有没有一种方法可以将降价(或 LaTex)文本分配给命名变量或别名,以便重复插入 Jupyter 笔记本?

Is there a method of assigning markdown (or LaTex) text to a named variable or alias for repeated insertion into a Jupyter notebook?

我正在使用 Jupyter 笔记本中的 markdown 和 LaTeX 做个人笔记。理想情况下,我想使用 shorthand 别名或标记在编辑器中处理重复出现的 Latex 表达式。然后,这些标记将在呈现文档时替换为相关的 LaTeX 表达式。

比如下面的markdown ...

The Pauli X matrix is given by the following expression:
$ S_x =\frac{\hbar}{2} \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix} $

...可以用下面的替代但等效的表达式表示,其中 spinX 别名是 {{dereferenced}} 已在其他地方定义为等于繁琐的 \frac{\hbar}{2} \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix} 表达式。

The Pauli X matrix is given by the following expression:
$ S_x = {{spinX}} $

New LaTeX macros may be defined using standard methods, such as \newcommand, by placing them anywhere between math delimiters in a Markdown cell. These definitions are then available throughout the rest of the IPython session.

https://jupyter-notebook.readthedocs.io/en/stable/notebook.html

在文档的开头,放

$\newcommand{\spinX}{\frac{\hbar}{2} \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix}}$

在降价单元格中。之后,您可以使用 \spinX 在后续单元格中使用别名。

The Pauli X matrix is given by the following expression:
$S_x = \spinX$