/

本页目录

TeX 宏

在编写 TeX 公式 时,你可能会想要使用自定义宏。

.texmacro {name} {content} 文档 ↗ 函数定义了一个可用于方程中的新宏。

示例 1

.texmacro {\gradient} {\nabla}

$ \gradient f $
\gradient f

与每一个 Quarkdown 函数一样,你可以使用最后一个参数作为主体参数

示例 2

.texmacro {\gradient}
    \nabla

参数

宏可以拥有数量可变的参数,这些参数在宏内容内部以 #1#2 等形式被引用。

示例 3

.texmacro {\sumlim}
    \sum_{#1}^{#2}

$ \sumlim{i=1}{n} a_i $
\sumlim{i=1}{n} a_i

组合

你可以定义多个宏并将它们组合,就像在 LaTeX 中那样:

示例 4

.texmacro {\hello}
    \text {Hello, \textit {world}}

.texmacro {\highlight}
    \colorbox{blue}{#1}

$ \highlight{\hello} $
\highlight{\hello}

你也可以在其他宏的基础上进行组合:

示例 5

.texmacro {\hello}
    \text {Hello, \textit {world}}

.texmacro {\highlighthello}
    \colorbox{blue}{\hello}

$ \highlighthello $
\highlighthello