pl-matrix-latex element¶
Displays a scalar or 2D numpy array of numbers in LaTeX using mathjax.
Sample element¶

question.html
$$C = <pl-matrix-latex params-name="matrixC"></pl-matrix-latex>$$
server.py
import prairielearn as pl
import numpy as np
def generate(data):
# Construct a matrix
mat = np.matrix("1 2; 3 4")
# Export matrix to be displayed in question.html
data["params"]["matrixC"] = pl.to_json(mat)
Customizations¶
| Attribute | Type | Default | Description |
|---|---|---|---|
digits |
integer | 2 | Number of digits to display according to the choice of presentation-type |
params-name |
string | — | Name of variable in data["params"] to display. |
presentation-type |
string | "f" |
Number display format. If presentation-type is "sigfig", each number is formatted using the to_precision module to digits significant figures. Otherwise, each number is formatted as '{:.{digits}{presentation-type}}'. |
Details¶
Depending on whether data["params"] contains either a scalar or 2D numpy array of numbers,
one of the following will be returned.
- scalar
- a string containing the scalar not wrapped in brackets.
- numpy 2D array
- a string formatted using the
bmatrixLaTeX style.
- a string formatted using the
Sample LaTeX formatting:
\begin{bmatrix} ... & ... \\ ... & ... \end{bmatrix}
As an example, consider the need to display the following matrix operations:
x = [A][b] + [c]
In this case, we would write:
question.html
${\bf x} = <pl-matrix-latex params-name="A" digits="1"></pl-matrix-latex>
<pl-matrix-latex params-name="b" digits="1"></pl-matrix-latex>
+ <pl-matrix-latex params-name="c" digits="1"></pl-matrix-latex>$
Example implementations¶
See also¶
pl-variable-outputfor displaying the matrix in a supported programming language.pl-matrix-component-inputfor individual input boxes for each element in the matrixpl-matrix-inputfor input values formatted in a supported programming language.