First of all, a bit of introduction in order to avoid the XY problem: when I write a test/exams I like to keep text and solution together. Now, both the main text and the solution can have equations; I'd like that the equation numbering of the main text could be kept constant, both in the formulation-only document and the full one (formulation with the solution).
I am able to do it for figures (I use newfloat
to define a solfigure
environment which has labels like Figure S1 and so on), but I am at a loss thinking something similar with equation.
I prepared this MWE:
\documentclass{article}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage{xcolor}\usepackage{environ}\newif\ifsolution\solutiontrue\NewEnviron{solution}{\ifsolution\color{red}\expandafter\BODY\fi}\begin{document}\begin{equation} 2x=4 \label{eq:one}\end{equation}\begin{solution} \begin{equation} x=2 \label{eq:solone} \end{equation}\end{solution}\begin{equation} 3x=6 \label{eq:two}\end{equation}\end{document}
With \solutiontfalse
I have equation (1), (2); with \solutiontrue
I have (1), (2), (3); I'd like to have (1), (S1), (2)... and so on, so that the equation for (2) is the same one both in the formulation and the formulation+solution document.
Extra point for having the tag in red, too.
With \solutionfalse
:
With \solutiontrue
: