# How can I use cross-references and hyperlinks to parts of an align environment?

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?

-
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

## 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}


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}%
\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}
\mitemxx{$$x^2+x=2$$,}{$$x^3+x^2=0$$.}

@gniourf_gniourf: you could extend your macros by hyperref commands, such as \hypertarget and \hyperref. –  Stefan Kottwitz Mar 6 '11 at 12:43