如何在 Jupyter Notebook 的 Markdown 单元格中定义 LaTeX 宏?

问题描述

我想在 Jupyter 笔记本的 Markdown 单元格中定义一个宏。但似乎我们无法定义它。

例如,我想定义一个格式化向量的宏。 单元格中的代码是:

\newcommand{\vect}[1]{{\mathbf{\boldsymbol{{#1}}}}}

This is the vector $\vect{x}$.

渲染是:

The macro is unused.

附注 该问题是在 https://tex.stackexchange.com/questions/281535/latex-macros-in-markdown 提出的,但与 LaTeX 没有直接关系,并且该问题被标记为题外话。

解决方法

在 Jupyter 单元格中定义宏的方法是在宏的前后放置一个美元。

$\newcommand{\vect}[1]{{\mathbf{\boldsymbol{{#1}}}}}$
This is the vector $\vect{x}$.

并且渲染是:

Correct rendering

附注 这是 Latex macros in Jupyter (iPython) notebook not rendered by github 中使用的技巧,但主题略有不同。