MathJax state: \newcommand and friends, numbered eqs
Turns out MathJax has stateful support for \newcommand, and it works. However it depends on the order they're typeset, which might not correspond to document order To make it usable:
- [x] Leave
$\newcommand{...}$in source form instead of becoming invisible (special case of #10). - [ ] on change to a
$\newcommand...$formula, re-typeset all (or all following) math.
- [x] Also pass
\[re]newcommand...without any$etc delimiters to mathjax. Pandoc does this.
Undocumented: \newcommand alters MathJax.InputJax.TeX.Definitions.macros and MathJax.InputJax.TeX.Definitions.environment. Could try to save/restore them instead of re-typesetting all following math.
However, it's rare enough that re-typesetting should be acceptable.
Simular (but worse?) issues of rendering order sensitivity happen with \begin{equation} numbering. See https://github.com/mathjax/MathJax/issues/422.
This is going to be more acute if I optimize initial pass (#14) to be partial/out-of-order.
- [ ] Learn which phase of MJ updates state (macros, numbers, labels). Preprocess? Process? Render?
http://jsfiddle.net/89r6p/3/ demonstates mathjax running again (click) on labels, numbers & refs.
Numbering state is in MathJax.Extension["TeX/AMSmath"].number and MathJax.Extension["TeX/AMSmath"].startNumber; there is a host of other variables to handle labels&refs: https://github.com/mathjax/MathJax/blob/master/unpacked/extensions/TeX/AMSmath.js#L562
- [ ] syntax highlight \begin...\end
- [ ] syntax highlight \newcommand...}
- [ ] avoid "label foo multiply defined" which makes labels completely unusable
- [ ] handle
\DeclareMathOperatornot wrapped in $...$- [ ] handle any tex macros not wrapped in math? Probably WONTFIX.
Should check how pandoc handles those.