# Numbering and cross referencing of equations in questions and answers

A basic LaTeX feature which I sometimes miss when asking and answering questions in MO (specially when the question and the particularly the answer are longer) is the possibility of numbering equations for cross referencing. I tried to do it naively a couple of times but it never worked. I also looked into the MO help pages to figure out a way to do it, to no avail. I do not know if there is an intrinsic limitation in MathJax for implementing such a feature, but I believe it would be quite helpful to be able to do so. I would be happy enough with just simple numbering and then cross referencing bare-handedly. Fully-fledged, \label-\eqref-style cross referencing would probably be overkill since questions and answers are not that long.

If it is indeed the case that numbering and cross referencing of formulas is currently not possible in MO, is it feasible to implement such a feature? If that is the case, would it be helpful for other people in the MO community as well? Thanks in advance.

MathJax supports manual numbering using $$\tag{…}$$, as in \eqref{grz} below:

$$\tag{1}\label{grz}\Box(\Box(p\to\Box p)\to p)\to p$$

Cross-references work, too, with \label and \eqref. The tags needn't be numbers:

$$\tag{LR}\Box p\to p\vdash p$$

• I usurped your label in my answer... Jun 15 '16 at 14:38
• Ah, it was the $\verb|\tag|$ command I was missing. Just using $\verb|\label|$ and $\verb|\eqref|$ as in a standard $\mathrm{\LaTeX}$ document wasn't working for me. Thanks a lot! Jun 15 '16 at 14:45

Let me try this label feature that Emil pointed out... $$\tag{1}\label{grz}\Box(\Box(p\to\Box p)\to p)\to p$$ Then I have more material.
Then I have more material.
Then I have more material.

Ready to refer to the equation: In equation ($\ref{grz}$) we see... Wow there is even a link that jumps to the equation if it is off the screen by now.

However: I note that if my answer is above Emil's, then Emil's equation with the same label no longer works. So, to be polite, I should choose labels unique to me. It also means I can put a link in my answer to an equation in a different answer.

• Your last paragraph raises an important point to have in mind. It makes sense, since it means MathJax works as if the whole page were a single $\mathrm{\LaTeX}$ document. However, we are only able to "see" the labels of other people if we enter the edit window of the corresponding post. This may be a source of confusion - perhaps a "mouseover" feature would help? Jun 15 '16 at 14:49
• Oops, your equation is not being displayed correctly. I tried to edit a MO answer of mine to include cross referencing and the same thing is happening to me. It seems that the \label command alone is doing this (i.e. removing \eqref does not solve it), even if it is the only cross reference in the page (so it's not due to a conflict between labels). Curiously, this bug doesn't show up in the preview of the edit window. Even more curiously, Emil's answer doesn't have this problem, even if I copied his commands verbatim in my post. Would it be the case to add a "bug" tag to the question...? Jun 15 '16 at 15:24
• Emil's answer is now above mine, so HIS is displayed correctly and mine is not. However my link now goes to his equation! Jun 15 '16 at 15:27
• But it's still strange - why is your first equation not being formatted? In my MO answer I tried to edit to incorporate this feature, the same thing happens even if it's the only equation in the page being referenced. Jun 15 '16 at 15:28
• It seems if a given label already exists, then formatting fails. In normal LaTeX, if you put in a duplicate label, you just get a warning in the log file. Mathjax has no log file, so when something is wrong, it does not format the equation. Jun 15 '16 at 15:32
• OK, but in my case I know for sure there is no other equation label in the page. Changing the name of the label doesn't work either. Jun 15 '16 at 15:32
• It actually works fine, but you (and you only) may see it corrupted due to the fact that the MathJax script running on the page first saw and learned the label in the preview window, and erroneously thinks that the same label on the final version of the page is a duplicate label. Just reload the page to force the script to restart from a clean state when this happens. Jun 15 '16 at 16:39
• @EmilJerabek Hmm, you're right, all formulas render just fine on my smartphone. Thanks! Jun 15 '16 at 17:43
• Perhaps there should be a convention to use the same symbols for the label as for the tag (since you have to give the tag explicitly anyway). So \tag{1}\label{1} or \tag{grz}\label{grz}. Then you don't have to look at the code to see what label to use. Jun 16 '16 at 0:50
• @DavideCervone : I think that's a great suggestion! I am also wondering if it wouldn't be helpful in MathJax to obsolete \label (since you won't want to label and refer to untagged questions) and redefine \tag to take an optional argument so \tag{#1} mapsto (what is currently) \tag{#1}\label{#1} while \tag[#1]{#2} maps to \tag{#2}\label{#1}? Jun 16 '16 at 15:02
• I think differences between MathJax and LaTeX syntax should be minimized. Jun 16 '16 at 16:05
• @WillieWong, I agree with Gerald, we don't want to make more changes to standard TeX than are already in MathJax. People want to be able to copy expressions from here directly into LaTeX papers, and such changes would make that harder to do. The reason LaTeX has two separate macros is that LaTeX is set up to number equations automatically (so you rarely use \tag), and also because \label can be used on things other than equations (like headers, figures, etc.). It looks redundant here, but isn't in LaTeX itself. Jun 17 '16 at 12:33
• @DavideCervone: I am fully aware of the reasons for distinct commands in LaTeX, which is why I specified "in MathJax" in my comment. Furthermore, precisely because \label and \ref are "general purpose" TeX commands that one has the reason to expect that they behave differently in MathJax then in LaTeX. (Similar to \newcommand or any of the non-existent text-mode only commands.) And no one will be able to directly copy-paste code with "references" anyway from a LaTeX document: \ref and \eqref are almost never used in Mathmode but in MathJax you need to surround them by $...$. Jun 17 '16 at 14:23
• On the other hand, looking through the MathJax docs again, I see one much more reasonable objection to doing this, which is the fact apparently automatic equation numbering is available. This would make it bad to obsolete \label. Still, what about a * form of \tag that does what I described? This will not break code that already use \label. Jun 17 '16 at 14:27
• @WillieWong, Note that \ref and \eqref do not need to be surrounded by math delimiters (just as \begin{x}...\end{x} don't). As for \tag*, that already has a meaning (a tag without the parentheses), so that is not available. Also, I didn't mention copying from LaTeX to here, I said copying from here to a LaTeX document. I'm not sure why you expect \label and \ref to act differently in MathJax than in LaTeX (is there a missing "not"?); for example \hbox` is general purpose, so do you expect it to work differently in MathJax. I'm afraid I'm missing something. Jun 17 '16 at 20:03