How to define custom macros in MathJax
latex, macros, mathjax
Solution
I've updated the codepen from my comment.
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, ""]
}},
Problem
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} ``` as ``` 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] } ``` but no luck. 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. 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 this question was asked and closed on SE they redirected me to SO.