# Equation number inside equation (not on extreme right), or ref to user-defined counter

Please note that the solution should be compatible with MathJax. I produce the .tex code, but someone else deals with the getting it up onto the web (meaning I don't understand MathJax, but if the "answer" messes up MathJax, I won't be able to use it).

I'm typesetting step-by-step solutions to basic math questions. Since these are for beginners the equations not been numbered. Instead, I've been using the align* environment and I often include comments on the right-hand side, but NOT in the margin, as in the following code snippet:

\begin{align*}
y & = \text{expression 1} && \text{Comment to student}\\
& = \text{expression 2}\\
& = \text{expression 3} && \text{Another comment}
\end{align*}


so it looks something like this

I just recently needed to number a line in one of the equations, and used the suggestion from Ian Thompson's answer to align* but show one equation number at the end.

However, when I did this, the output looked bad due to the different placements of the equation number vs the comments I use:

It would be easier to read if the equation number appeared in the same place as the comments:

Here is the MWE of how I did this third version:

\documentclass{article}
\usepackage{amsmath}

\newcounter{myCount}
\setcounter{myCount}{0}

\newcommand*{\thisNumber}{%
\refstepcounter{myCount}
(\themyCount)
}

\begin{document}
\begin{align*}
y & = \text{expression 1} && \text{Comment to student}\\
& = \text{expression 2}\\
& = \text{expression 3} && \text{Another comment}\\
& = \text{expression 4} && \thisNumber\label{eq1}
\end{align*}

Reference attempt: \ref{eq1}
\end{document}


which produces the placement I want, but the \ref and eqref commands don't recognize the label.

Interestingly (to me, in my ignorance) the reference commands work just fine if this approach is used in regualar text or enumerated lists. But not in the align environment.

I know it's likely something simple, but I haven't been able to figure out what.

• align* redefines/disables \label, that is the cause, as far as I can see. I don't know what MathJaX allows, but you can use \let\labelorig\label and use \labelorig{eq1} in LaTeX at least – user31729 Dec 31 '16 at 18:30
• Could you provide a comparable set of MathJax instructions to your LaTeX ones that shows how the \label-\ref systems works at the moment with some functional solution? – Werner Dec 31 '16 at 18:36
• @Werner I can't because I don't know the MathJax system. Usually, when I want to include a new package or similar, I have to contact the MathJax guy and ask if it is supported. – HTG Dec 31 '16 at 18:42
• @ChristianHupfer That worked, though, like you said, I'll need to check with the MathJax guru to see if it works there. If it does, and if you type up your comment as an answer, I'll be happy to select it. Thanks! – HTG Dec 31 '16 at 18:50
• @HTG: I've already provided as an answer, deleted it shortly after, but if it gets a downvoted, I will delete it again. – user31729 Dec 31 '16 at 18:52

## 1 Answer

I can't say whether this is possible for MathJaX at all, but using the original \label inside align* seems to work.

I am not sure whether MathJaX knows \let at all...

However, according to this post (http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference ), MathJaX knows \newcommand as well.

\documentclass{article}
\usepackage{amsmath}
\let\labelorig\label
\newcounter{myCount}
\setcounter{myCount}{0}

\newcommand*{\thisNumber}{%
\refstepcounter{myCount}%
(\themyCount)%
}

\begin{document}
\begin{align*}
y & = \text{expression 1} && \text{Comment to student}\\
& = \text{expression 2}\\
& = \text{expression 3} && \text{Another comment}\\
& = \text{expression 4} && \thisNumber\labelorig{eq1}
\end{align*}

Reference attempt: \ref{eq1}
\end{document}


'Improved version' with \tag

\documentclass{article}
\usepackage{amsmath}
\let\labelorig\label
\newcounter{myCount}
\setcounter{myCount}{0}

\newcommand*{\thisNumber}{%
\refstepcounter{myCount}%
\tag{\themyCount}% Or switch back to (\themycount)
}

\begin{document}
\begin{align*}
y & = \text{expression 1} && \text{Comment to student}\\
& = \text{expression 2}\\
& = \text{expression 3} && \text{Another comment}\\
& = \text{expression 4} && \thisNumber\labelorig{eq1}
\end{align*}

Reference attempt: \eqref{eq1}
\end{document}


• The problem with the \tag version is that the equation number appears on the far right, which seems out of place since all other comments to the reader appear more to the left. Consequently, I prefer the \myCount version. Thanks for the help! – HTG Jan 7 '17 at 18:38