如何在 MathJax 中定义自定义宏 [英] How to define custom macros in MathJax

查看:19
本文介绍了如何在 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;


ewcommand{raket}[1]{langle #1 
angle}

作为

Macros: {
    braket: ['{\langle #1 \rangle}', 1]
}

但与复杂的斗争;


ewcommand{Abs}[2][]{leftlvert#2
ight
vert_{	ext{#1}}}

试图将其定义为;

Macros: {
    Abs: ['{\left\lvert#2\rvert_{\text{#1}}}', 2]
}

但没有运气.

这是它在 LaTeX 文件中的使用方式

This is how it is used in LaTeX file

egin{align}
onumber
    p_e = Abs{raket{e|psi(t)}}^2 = sin^2Omega t, .
end{align}

不知道我哪里做错了.

我不是 LaTeX 专家,只是一名尝试在 Web 应用程序(适用于 Quantum Physics 社区)上显示 LaTeX 文件的开发人员,因此非常感谢您的帮助.谢谢.

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.

P.S 这个问题是在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆