5

In general, I use mathtools in a mode that puts equation numbers only if an equation is referenced. How can I reference an equation without actually showing the number in the document, so that a label is put next to the equation?

Here is a MWE:

\documentclass{article}

\usepackage{mathtools}

\mathtoolsset{showonlyrefs,showmanualtags}

\begin{document}

\begin{equation}
Ax = b \label{eq1}
\end{equation}

The equation above will be numbered since I am referencing it using \refeq{eq1}.
The equation below will not be numbered since I am never referencing it. I want something like nocite: referencing
the equation, so that a number appears next to the equation, but no mention of that in the text.

\begin{equation}
Ax = b \label{eq2}
\end{equation}

\end{document}
  • 1
    What do you mean by "so that a label is put next to the equation"? Do you mean a specific symbol, or are you using the term "label" in the TeX/LaTeX sense of \label? – Mico Nov 9 '14 at 20:48
  • 3
    Please provide a minimal working example (MWE) that illustrates your question. This will both make it easier to help and help to clarify your question (again making it easier to help). – cfr Nov 9 '14 at 20:53
  • Are you perhaps thinking to \tag? – egreg Nov 9 '14 at 20:54
4

The command \refeq, besides typesetting the reference, writes an \MT@newlabel entry in the .aux file, so defining a \silentrefeq that does this will suffice.

\documentclass{article}

\usepackage{mathtools}

\mathtoolsset{showonlyrefs,showmanualtags}

\makeatletter
\MHInternalSyntaxOn
\newcommand{\silentrefeq}[1]{
  \@bsphack
  \MH_if_boolean:nT {show_only_refs} {
    \protected@write\@auxout{}{\string\MT@newlabel{#1}}
  }
  \@esphack
}
\MHInternalSyntaxOff
\makeatother


\begin{document}
\silentrefeq{eq2}

An equation:
\begin{equation}
Ax = b \label{eq1}
\end{equation}
The equation above will be numbered since I am referencing it using \refeq{eq1}.

The equation below will not be numbered since I am never referencing it. I want something 
like nocite: referencing the equation, so that a number appears next to the equation, but 
no mention of that in the text.
\begin{equation}
Ax = b \label{eq2}
\end{equation}

\end{document}

In case showonlyrefs is not active, the command will do nothing. The \silenteqref command can go almost anywhere, but the start of the document is a good place.

enter image description here

Note that I didn't change your text, so as to make sure that no \refeq{eq2} was added that would trigger numbering the second equation; the number appears just because of the \silentrefeq command after \begin{document}.

| improve this answer | |
  • The second equation appears to be numbered just fine in the screenshot... – Mico Nov 9 '14 at 22:28
  • @Mico That's what the OP seems to want. I didn't change the text. – egreg Nov 9 '14 at 22:29
  • I guess I'm completely confused. Your text says "The equation below will not be numbered since ..." (I realize now you copied the text from the OP.) Should you maybe write, "The equation below will be numbered even though it's not referenced explicitly"? – Mico Nov 9 '14 at 22:30
  • @Mico I didn't change in any way the original text, so as to make the OP sure that the result was as intended. – egreg Nov 9 '14 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.