2

I'd like to use \label{eq:1} and eqref{eq:1}. But it doesn't seem to want to work with the document class I'm using. (The amspset document class can be found here.)

\documentclass[reqno, 11pt, letterpaper, cm, unboxed]{amspset}
\usepackage{amsthm, amssymb, amsfonts, amsmath}
\usepackage[in]{fullpage}
\let\ifpdf\relax
\usepackage{mathtools}

\newcommand{\eq}[1]{\begin{align*}#1\end{align*}}
\newcommand{\ml}[1]{\!\begin{multlined}[t]#1\end{multlined}}

\newcommand{\pr}[2]{\begin{solution}{\textbf{#1.}}#2\end{solution}}

\name{Eric Auld}
\class{MATH 2200}
\assignment{Homework 1}
\duedate{April, 10}

\begin{document}

\pr{1}{
 \eq{
  e=mc^2 \label{eq:1}
 }
Suppose we consider \eqref{eq:1}
}

\end{document}

When I do this, it does not recognize the reference, and says Latex warning: reference "eq:1" on page 1 undefined on line __.

Anyone have some advice?

  • 3
    You're using align* that doesn't produce numbers, so \label{eq:1} will refer to nothing. I can't recommend using commands to enclose environments; use explicitly solution and also equation or align when one is needed. Your document will be more legible and structured. – egreg Oct 18 '13 at 17:58
  • Thanks! If I'm using align, and only want to label one line, should I put \notag after each line I don't want labelled? – Eric Auld Oct 18 '13 at 18:37
  • @egreg Can you inform a newbie on the value of having your documents be structured and legible? This is just a homework assignment, and I presume no one will ever look at the code, except for me, and only for about a week. But I am definitely interested in how it could be helpful to have the code be very clear. – Eric Auld Oct 18 '13 at 18:43
  • You will be looking at the code and in a few months you'll be asking “what the heck is \pr doing?” – egreg Oct 18 '13 at 19:18
1

The align* environment you're using with \eq doesn't generate a number, so your \label command ends up referring to nothing, at least in this particular case. It would refer to a “random” number in the general case, precisely to the last one that has been generated, maybe by a \section command.

You get much more flexibility, structure and readability if you don't hide environments inside commands.

There's no gain in using your input rather than

\documentclass[reqno, 11pt, letterpaper, cm, unboxed]{amspset}
\usepackage{amsthm, amssymb, amsfonts, amsmath}
\usepackage[in]{fullpage}
\let\ifpdf\relax
\usepackage{mathtools}

%%% patch solution to typeset its argument boldface
\usepackage{xpatch}
\xpatchcmd{\solution}{#1]}{\textbf{#1.}]}{}{}    


\name{Eric Auld}
\class{MATH 2200}
\assignment{Homework 1}
\duedate{April, 10}

\begin{document}

\begin{solution}[1]
\begin{equation}
  e=mc^2 \label{eq:1}
\end{equation}
Suppose we consider \eqref{eq:1}
\end{solution}

\end{document}

By the way, it's not recommended using align or align* as “catch-all” display environments: use them only for multiline environments.

In a few month you'll probably be staring at your documents asking yourself “what the *@$$ is \pr doing?” Moreover, code using standard commands is portable from one document to another.

In the same vein, I've patched solution so that it typesets its (optional) argument boldface, so that you don't have to use the clumsy

\begin{solution}[\textbf{1.}]

and your document will comply with the standard. If the Powers That Be (your TA or supervisor, for instance) tell you “what's that boldface doing there?”, you'll just remove the patch and print again the paper, asking in return “What boldface?" ;-)

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.