It's possible to use \def, and it usually works. However, there's a problem in that the definitions stick around and there seems to be no way to get rid of them short of reloading the page. This might not be so bad if it weren't for the fact that it messes up standard commands whose names appear temporarily while a custom command name is being typed.

For instance, say I have \int_{-\pi}^\pi and I realize I'll be writing lots of these integrals, so I enclose it in braces and type \def\intp in front of it. Before I type the final 'p', the result is \def\int{\int_{-\pi}^\pi}. This redefines \int (in this case to something self-referential that causes an error), and that definition doesn't get cleared when I type the final 'p'. (This happens no matter how fast I type.) From then on, trying to use \int causes an error, even after deleting the entire definition, and the only way to get it to work again seems to be to reload the page.

  • $\begingroup$ Hmmm. Is this an SE bug or a MathJax one? $\endgroup$ – cardinal Dec 26 '11 at 2:17
  • $\begingroup$ @cardinal: Sounds like either a MathJax bug, or a MathJax "feature" that we should turn off. $\endgroup$ – Ilmari Karonen Dec 26 '11 at 5:08
  • $\begingroup$ This is probably a silly suggestion, but if this is due to insta-parsing...Does it help, if you paste 'intp' to the correct place as opposed to type it? $\endgroup$ – Jyrki Lahtonen Dec 29 '11 at 19:44
  • 1
    $\begingroup$ @Jyrki: Yes, there are various workarounds -- you can also type the entire definition and then add the \def in front of it. $\endgroup$ – joriki Dec 29 '11 at 20:33
  • $\begingroup$ Can someone confirm whether this is still an issue? $\endgroup$ – Oded Jul 24 '14 at 12:18
  • $\begingroup$ @Oded It is; I tested it now. This answer by Davide Cervone describes how MathJax scoping begingroup... endgroup can be used to deal with leaking definitions, but implementing it would require some changes to SE code. $\endgroup$ – user147263 Jul 24 '14 at 15:18
  • 2
    $\begingroup$ Geoff Dalgas updated this to say status-completed, but didn't say why. $\endgroup$ – MJD Jan 27 '15 at 17:41

I took a quick look at how macro definitions are implemented in MathJax, and from what I can tell, this is a MathJax bug, or rather, a missing feature. In fact, there are two features that would make the way we use MathJax work better:

  • Some way to reset TeX macro definitions (and ideally any other mutable state) back to its previous state after a Typeset call. It might be possible to hack this locally by poking into MathJax internals (pull a copy of the definitions from the TeX InputJax before calling Typeset and stick it back afterwards), but it would be much better to have an officially supported way to do this.

  • Some way to tell MathJax to automatically reset macro definitions after processing the content of appropriately marked HTML elements on the page. That way, we could for example mark each post on a page so that macro definitions wouldn't leak between them. This should also take care of the preview issues, assuming that the preview container was thus marked.

Anyone else feel like reporting these to the MathJax folks, or shall I?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .