6

I would like to re-use equations with the same content and number. I know that the thmtools package has a restatable environment to do this for environments (like in this answer), but I would also like to do this with a single equation that is only part of some environment.

I had a look at the following questions which only aim at repeating the equation number but typing the whole equation twice (the first three) or repeat the content of the equation without a number (the last one):

Based on the answers provided there and on the last part of this answer I tried to create a macro \restatableeq for restable equations like this:

\documentclass{article}

\usepackage{amsmath}

\newcommand{\restatableeq}[3]{\label{#3}#2\xdef#1{\unexpanded#2\unexpanded\tag{\unexpanded\ref{#3}}}}

\begin{document}

\begin{eqnarray}
\restatableeq{\eqone}{This & is & eqation 1}{eq1}\\
Another & simple & equation
\end{eqnarray}

\begin{eqnarray}
One & more & equation\\
\restatableeq{\eqtwo}{This & is & eqation 2}{eq2}
\end{eqnarray}

Here, we use (\ref{eq1}) and (\ref{eq2}) again:
\begin{eqnarray*}
\eqone\\
\eqtwo
\end{eqnarray*}

\end{document}

Unfortunately, it does not work and yields:

! Missing { inserted.
<to be read again>
                   T
l.10 ...ableeq{\eqone}{This & is & eqation 1}{eq1}
                                                  \\
?

My guess is that the & symbols are not treated as intended but I may well be wrong there.

How can I define a command like \restatableeq that allows me to re-use equations with the same content and number in a setting like in this example (and give it a label such that I can still use \ref as usual in addition to that)?

1 Answer 1

4

There are a couple of flaws in your document.

  1. You use \xdef{\unexpanded...}. This is essentially \gdef, which totally suffices here.
  2. Your use of \unexpanded is wrong. \unexpanded expects a balanced token list delimited by explicit {, }. If you want to protect a single token from expansion in \edef, use \noexpand. Enrico wrote a nice answer about that.
  3. You use eqnarray. Never use eqnarray.
  4. \tag does not work in eqnarray.

Here is a fixed version.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\restatableeq}[3]{\label{#3}#2\gdef#1{#2\tag{\ref{#3}}}}
\begin{document}
\begin{align}
\restatableeq{\eqone}{This & is & eqation 1}{eq1}\\
Another & simple & equation
\end{align}

\begin{align}
One & more & equation\\
\restatableeq{\eqtwo}{This & is & eqation 2}{eq2}
\end{align}

Here, we use (\ref{eq1}) and (\ref{eq2}) again:
\begin{align*}
\eqone\\
\eqtwo
\end{align*}
\end{document}

enter image description here

You must log in to answer this question.

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