Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing an exercise book, and in some exercises I'll have several numbered equations in an align environment, e.g.,

(1) x^2+x+1=0, (2) ax^3+2x=0, (3) x^5=2i,

(4) x^4=-i, (5) x-1/x=2, (6) cosh(x)=3.

(I'll want them to be aligned with respect to the number).

I'm using a macro \newcommand*\ExoEq{\refstepcounter{ExoEq}(\theExoEq)~}

so that the previous example is typed as:

\begin{align*}
\ExoEq&x^2+x+1=0,&
\ExoEq&ax^3+2x=0,&
\ExoEq&x^5=2i,\\
\ExoEq&x^4=-i,&
\ExoEq&x-\frac1x=2,&
\ExoEq&\cosh(x)=3.
\end{align*}

All is good so far, except that I sometimes need to refer to an equation, e.g.,

In Equation~(2), we assume that $a\neq0$.

The thing is when I want to use \label and \eqref, I get weird results in the align environment: here is a minimal example that shows what goes wrong:

\documentclass{amsart}

\usepackage{amsthm}
\usepackage[pdftex]{hyperref}

\parindent0pt

\newtheoremstyle{myexercise}{\baselineskip}{\baselineskip}{}{}{\bfseries}{.}{ }{\thmname{#1}\ \thmnumber{#2}}%
\theoremstyle{myexercise}
\newtheorem{Exo}{Exercise}[section]

\newcounter{MyCounter}
\newcommand*\Number{\refstepcounter{MyCounter}(\theMyCounter)~}

\let\oldlabel\label

\begin{document}
\section{Exercises}
\begin{Exo}
\begin{align*}
\Number\oldlabel{L1}&x^2+x=2,&
\Number\oldlabel{L2}&x^3+x^2=0.
\end{align*}
Equation~\eqref{L1} is very nice, and Equation~\eqref{L2}
is lovely too.
\end{Exo}
\end{document}

Without the hyperref package, I get the exercise reference, instead of the equation reference. With the hyperref package, I get an error on the second latex pass.

I'm using a \let\oldlabel\label trick, as the align* environment redefines \label, and it just doesn't work with \label instead.

How can I work around this annoying thing to have it work?

share|improve this question
    
Since you don't align at relation symbols, I recommend to use a tabular(x) environment with equations in cells instead of align. –  Stefan Kottwitz Mar 6 '11 at 12:55

1 Answer 1

amsmath align fix

It works if you redefine \eqref to use the starred version \ref* which doesn't create a hyperlink:

\makeatletter
\renewcommand{\eqref}[1]{\textup{\tagform@{\ref*{#1}}}}
\makeatother

tabular solution

Though I recommend to use the numbered environment align instead of align*. I can see that you use align* to achieve an unusual numbering style. However, I would rethink if it's worth to differ from the common style.

As I said in my comment: since you don't align at relation symbols, I recommend to use a tabular(x) environment with equations in cells instead of align. Here's a quick example which uses you numbering macros:

\usepackage{tabularx}
...
\begin{Exo}

\begin{tabularx}{.5\textwidth}{XX}
  \Number\label{L1} \(x^2+x=2\), &
  \Number\label{L2} \(x^3+x^2=0\). 
\end{tabularx}

Equation~\eqref{L1} is very nice, and Equation~\eqref{L2}
is lovely too.
\end{Exo}

enter image description here

You could take further care of spacing, centering and hyperlink design.

Morover, you could use numbered equation environments in tables if you use \parbox or minipage for those within cells. It requires to specify a width, but you could rely on LaTeX's resp. amsmath's numbering instead of on your self-made solution.

enumerated list solution

A third way is to use an enumerated list. The look of the label can be changed to be like an equation tag with parentheses. For multicolum equations, which are horizontally numbered, you could use the multenum package.

A small example with your theorem environment, yet without referencing worked out:

\documentclass{amsart}
\usepackage{amsthm}
\usepackage{multienum}
\renewcommand{\regularlisti}{\setcounter{multienumi}{0}%
  \renewcommand{\labelenumi}%
  {\addtocounter{multienumi}{1}(\arabic{multienumi})}}
\usepackage[pdftex]{hyperref}
\parindent0pt
\newtheoremstyle{myexercise}{\baselineskip}{\baselineskip}{}{}%
  {\bfseries}{.}{ }{\thmname{#1}\ \thmnumber{#2}}%
\theoremstyle{myexercise}
\newtheorem{Exo}{Exercise}[section]
\begin{document}
\section{Exercises}
\begin{Exo}
\qquad
\begin{minipage}[t]{.5\textwidth}
\begin{multienumerate}
  \mitemxx{\(x^2+x=2\),}{\(x^3+x^2=0\).} 
\end{multienumerate}
\end{minipage}
\end{Exo}
\end{document}

enter image description here

share|improve this answer
    
Thanks for your answer. It works with \ref*. However I have two issues with it: First, I'd like to keep a hyperlink, but this is a detail. When I compile, I get the error (\end occurred when \ifmmode on line 28 was incomplete). Now, I'm using align* and put several equations on one line, just to save space. It's an exercise book, and not a research article, so it doesn't matter if several equations are on one single line. My colleagues use a multi-column environment for this, but I don't like it, since equations are numbered downward. Anyways, I'm keeping your solution as a fallback. –  gniourf_gniourf Mar 6 '11 at 12:13
    
@gniourf_gniourf: you could extend your macros by hyperref commands, such as \hypertarget and \hyperref. –  Stefan Kottwitz Mar 6 '11 at 12:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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