pl-matrix-latex元件¶
使用 mathjax 在 LaTeX 中显示数字的标量或 2D numpy 数组。
样品元素¶

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)
定制¶
| 属性 | 类型 | 默认 | 描述 |
|---|---|---|---|
digits |
整数 | 2 | 根据presentation-type的选择显示位数 |
params-name |
字符串 | — | 要显示的 data["params"] 中的变量名称。 |
presentation-type |
字符串 | "f" |
数字显示格式。如果 presentation-type 为 "sigfig",则使用 to_precision 模块将每个数字格式化为 digits 有效数字。否则,每个数字的格式为 '{:.{digits}{presentation-type}}'。 |
细节¶
根据 data["params"] 是否包含标量或 2D numpy 数组,
以下其中一项将被退回。
- 标量
- 包含未括在方括号中的标量的字符串。
- numpy 二维数组
- 使用
bmatrixLaTeX 样式格式化的字符串。
- 使用
LaTeX 格式示例:
\begin{bmatrix} ... & ... \\ ... & ... \end{bmatrix}
例如,考虑需要显示以下矩阵运算:
x = [A][b] + [c]
在这种情况下,我们会写:
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>$
示例实现¶
- [元素/矩阵乳胶]
- [演示/随机复选框]
参见¶
pl-variable-output用于以支持的编程语言显示矩阵。pl-matrix-component-input用于矩阵中每个元素的单独输入框pl-matrix-input表示以支持的编程语言格式化的输入值。