2

This seems again trivial, but I cannot find any solution to my problem in the questions that have been asked on referencing.

The issue can be explained easily: I am making a document with many equations which are numbered consecutively. All of them are labelled (manually) via \label and referenced via \ref. Now let's say I decide to move one of the equations at the beginning of the document to the Appendix. This makes all of the following labels and references too large by exactly 1. I cannot believe I have to edit all of them manually? I mean it's possible if you make all the references at the end of your work, but still I wonder if there is a more effective way.

  • 4
    run the document at least two times to get the labels right! – user2478 Oct 19 '13 at 13:41
  • 1
    @TomM as Herbert pointed out, references should be updated automatically, but you'd have to run tex twice to make the updates appear in your final document... (first run to gather new ref. numbers, second to show them). If you tried this and it doesn't work, i'd suggest to put a MWE online... – long tom Oct 19 '13 at 13:55
  • 2
    Note that the string you put in the \label is unrelated to the printed number, it is just a symbolic name for internal referencing. – David Carlisle Oct 19 '13 at 14:53
  • 2
    to follow up on david's comment, the ability to rearrange your labeled items is a good reason to assign descriptive labels, not numerical ones. – barbara beeton Oct 19 '13 at 15:01
  • 1
    \ref{zzz} generates the same number used in the equation labeled with \label{zzz} the internal label zzz is just to make that link, it is unrelated to the number used. – David Carlisle Oct 19 '13 at 21:37
2

I like to label my equations eq1, eq2 etc. in order to remember them (especially if I come back after a delay). A partial solution is to use the following:

\documentclass{article}
\usepackage{mathtools}

\newcounter{myeqn}
\newcommand{\eqlabel}{
\stepcounter{myeqn}
\label{eq\arabic{myeqn}}
}

\begin{document}

\begin{equation}
\eqlabel
A=A
\end{equation}

\begin{equation}
\eqlabel
A\neq B
\end{equation}

If one substitues for $A$ using (\ref{eq1}) into (\ref{eq2})
\end{document}

Of course, the references occur randomly and still have to be edited manually. Then again, I avoid autonumbering in general (it's easier to add than remove).

  • Since you're already loading the mathtools package (which, in turns, loads the amsmath package), you may want to look into using the command \eqref{...} instead of (\ref{...}). A real advantage to using \eqref is that its contents are always written in the upright font shape, regardless of whether the surrounding text is in typeset upright or in italics (as will often be the case in theorem-like environments). – Mico Oct 19 '13 at 17:02
  • 1
    in doing \label{eq\arabic{myeqn}} you lose a large part of the benefit of the automatic numbering and cross reference mechanism. – David Carlisle Oct 19 '13 at 21:38
  • @mico, actually I use \hypertarget and \href. I just wanted to demonstrate how to counters and set up numbered labels. – John Kormylo Oct 20 '13 at 15:05

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.