1

I am trying to learn how to use the \eqref commands instead of just doing tag{1.1}, so I don't have to go back and renumber. I'm having trouble: in problem 3b, I say

Now \eq{y(t, \epsilon)= y_0(t) + \epsilon y_1(t) + O(\epsilon^2), \label{eq:aa}}

(\eq is an abbreviation I've defined, it is \newcommand{\eq}[1]{\begin{align*}#1\end{align*}}). Later I go back and write So we can fill in \eqref{eq:aa}, and the problems are

  1. It doesn't label the equation
  2. When it refers back to it, it calls it (1.2), although it is the first tagged equation.

Here is a link to my code, if it helps you diagnose. https://www.writelatex.com/read/zjhhjpndjpkz

I appreciate your help!

  • 1
    Please make a small self contained document that shows the problem and add it to the question (not as a link) – David Carlisle Mar 27 '14 at 15:24
  • @DavidCarlisle My problem is that I'm not sure where the problem is...if I try to recreate the problem from scratch it shows up the right way. What would you recommend? – Eric Auld Mar 27 '14 at 15:25
  • 1
    Start from a copy of your document and delete anything you can delete while still showing the problem: if you delete something and the problem goes away then that's the cause of the problem. Once you can make the document no smaller, post it here. – David Carlisle Mar 27 '14 at 15:29
  • @DavidCarlisle OK, will do. – Eric Auld Mar 27 '14 at 15:32
  • 1
    it's absolutely necessary that we see the definition of \eq. the application of the label (and the printing of the equation number) is defined in equation, so if that is "broken", it would explain why there's nothing to reference. – barbara beeton Mar 27 '14 at 15:43
5

okay. here are some problems with your definition.

any starred math display environment is intended to suppress numbering. you can put a \tag{...} on a starred environment, but the number won't be incremented automatically. however, a \label on such a tag will be honored by \ref or \eqref. (all \eqref really does is format the argument of a \ref to be upright and wrapped in parentheses.)

next. align is intended to be used for multi-line expressions with each line having a left and a right part. although a lot of people use \align for one-line displays, it's a bad idea, since the vertical spacing around a multi-line display is intentionally different from that around a one-line display. and if there aren't two parts to a line (separated by &), the structure won't be centered horizontally.

finally, turning environments into commands makes your input much more difficult for someone else to read and decipher, and leads to bad input habits -- like running display material into long lines. believe me, this leads to serious loss of hair on the part of journal editors.

if you really want a one-line, numbered display using a shorthand like this, it can be done, perhaps like this:

\newcommand{\eq}[1]{\begin{equation} #1\end{equation}}

but it's better to think twice before doing so. someone suggested persuading your input environment/editor to use "completion". this makes for much more scrutable files, and more efficient debugging and maintenance in the long run.

| improve this answer | |
  • I'd like to upvote this answer many times ... – Ethan Bolker Mar 27 '14 at 18:03
2

I've taken a look at the code you provide in the link. The main problem, it would seem, is that you use the align* environment in the definition of the \eq macro. The align* environment, by design, does not increment or print equation numbers. Hence, any \label instruction associated with this equation (or group of equations) will not point to what's generated by \eq.

As a result, a subsequent \ref or \eqref instruction won't point to that structure. Instead, either (??) will be printed out, or the cross-reference will point to the object that had its associated counter incremented most recently before the lost \label instruction. This object could be a section, a theorem, some other equation that was generated the "normal" way (i.e., not via \eq), etc.

You should be able to achieve a better outcome by defining the \eq macro as follows:

\newcommand{\eq}[1]{\begin{equation}\begin{split} #1 \end{split}\end{equation}}

and affix a \label instruction to it, as in

\eq{y(t, \epsilon)= y_0(t) + \epsilon y_1(t) + O(\epsilon^2),} \label{eq:aa}

Note that with this setup, you should rename all \tag instructions inside an \eq statement with \label.

| improve this answer | |
  • Thanks for the input! What is split doing here? – Eric Auld Mar 28 '14 at 14:44
  • @EricAuld - The nested equation and split environments act a bit like an align environment, while assigning a single equation number to the entire group. The inner, split environment lets you provide alignment points à la align. – Mico Mar 28 '14 at 14:55

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.