如何在MathJax中定义自定义宏 [英] How to define custom macros in MathJax
问题描述
我正在尝试定义MathJax的LaTeX文件中使用的自定义宏.
I'm trying to define custom macros used in LaTeX files in MathJax.
可以定义简单的宏(单个参数),而不会出现任何问题;
Can define simple macros (single parameter) without any issue such as;
\newcommand{\braket}[1]{\langle #1 \rangle}
为
Macros: {
braket: ['{\\langle #1 \\rangle}', 1]
}
但是要与复杂的人斗争;
But struggle with complicated ones;
\newcommand{\Abs}[2][]{\left\lvert#2\right\rvert_{\text{#1}}}
试图像这样定义它;
trying to define it like;
Macros: {
Abs: ['{\\left\\lvert#2\\rvert_{\\text{#1}}}', 2]
}
但没有运气.
这是LaTeX文件中的用法
This is how it is used in LaTeX file
\begin{align}\nonumber
p_e = \Abs{\braket{e|\psi(t)}}^2 = \sin^2\Omega t\, .
\end{align}
不确定我在哪里做错了.
Not sure where I did wrong.
我不是LaTeX专家,而是一个试图在Web应用程序上显示LaTeX文件的开发人员(适用于Quantum Physics社区),因此,非常感谢您的帮助.谢谢.
I'm not a LaTeX expert, but just a developer trying to display LaTeX files on a web app (for Quantum Physics community), so I would greatly appreciate your help. thanks.
PS请问这个问题并在SE上关闭,他们将我重定向到SO.
推荐答案
我已经更新了我的codepen评论.
Primarliy,您忘记了\\right
;我还修改了宏定义,使其具有可选参数.换句话说,类似于以下内容:
Primarliy, you forgot a \\right
; I also modified your macro definition so that it has an optional parameter. In other words, something along the lines of:
Macros: {
braket: ['{\\langle #1 \\rangle}', 1],
Abs: ['\\left\\lvert #2 \\right\\rvert_{\\text{#1}}', 2, ""]
}},
这篇关于如何在MathJax中定义自定义宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!