11

When having multiple equations inside one displaymath environment, it is sometimes desirable to refer to just one of them without having to break the environment up into smaller pieces. Take for example the following set of boundary conditions (where the last three labels won't work, but are written here to illustrate the goal of this question):

\[\left\{\begin{array}{l l l l}
    (i)\label{eq:i}\quad        & \epsilon_1E_1^\perp=\epsilon_2E_2^\perp,\quad     &
    (ii)\label{eq:ii}\quad      & B_1^\perp=B_2^\perp,\\\\
    (iii)\label{eq:iii}\quad    & \mathbf{E}_1^\parallel=\mathbf{E}_2^\parallel,\quad   &
    (iv)\label{eq:iv}\quad      & \dfrac{1}{\mu_1}\mathbf{B}_1^\parallel=\dfrac{1}{\mu_2}\mathbf{B}_2^\parallel.
\end{array}\right.\]

enter image description here

How can one refer to any of the above four equations separately? Is a list inside a math environment perhaps possible?

15

Here is one way: create your own \mylabel, that mimics the regular \label. The following is a hyperref-compatible version:

enter image description here

\documentclass{article}
\usepackage{amsmath,hyperref}% http://ctan.org/pkg/{amsmath,hyperref}

\providecommand{\phantomsection}{}% In case hyperref is not loaded
\AtBeginDocument{\let\textlabel\label}% http://tex.stackexchange.com/q/9939/5764
\makeatletter
\newcommand{\mylabel}[2]{\raisebox{.7\normalbaselineskip}{\phantomsection}#1%
  \def\@currentlabel{#1}\textlabel{#2}}
\makeatother

\begin{document}

\[
  \left\{\begin{array}{l l l l}
    \mylabel{\text{(\textit{i})}}{eq:i}\quad        & \epsilon_1E_1^\perp=\epsilon_2E_2^\perp,\quad     &
    \mylabel{\text{(\textit{ii})}}{eq:ii}\quad      & B_1^\perp=B_2^\perp,\\\\
    \mylabel{\text{(\textit{iii})}}{eq:iii}\quad    & \mathbf{E}_1^\parallel=\mathbf{E}_2^\parallel,\quad   &
    \mylabel{\text{(\textit{iv})}}{eq:iv}\quad      & \dfrac{1}{\mu_1}\mathbf{B}_1^\parallel=\dfrac{1}{\mu_2}\mathbf{B}_2^\parallel.
  \end{array}\right.
\]
See~\ref{eq:i}, or~\ref{eq:iv}, or~\ref{eq:iii}, or~\ref{eq:ii}.
\end{document}

\mylabel{<to-print>}{<label>} prints and stores <to-print> in the <label> that you can reference later.

  • \textit should add the italic correction by itself. – egreg Feb 14 '14 at 16:11
  • @egreg: I see. There's some checking in the background going on. – Werner Feb 14 '14 at 16:14
  • As I use hyperref in pretty much all my documents, I'll give this question a shot: do you know a way around the error "File ended while scanning use of \Hy@setref@link"? – Betohaku Feb 14 '14 at 16:41
  • 1
    @Betohaku: I've updated the answer to provide a hyperref-compatible version. – Werner Feb 14 '14 at 18:07
  • I was trying to find a solution that worked with hyperref but yours works with and without. +1 – karlkoeller Feb 14 '14 at 18:28
4

This one is based on Werner's idea but works only when hyperref is loaded.

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\makeatletter
\newcommand{\mylabel}[2]{%
  \phantomsection#1%
  \@bsphack
  \begingroup
    \def\label@name{#2}%
    \label@hook
    \protected@write\@auxout{}{%
      \string\newlabel{#2}{%
        {#1}%
        {\thepage}%
        {\@currentlabelname}%
        {\@currentHref}{}%
      }%
    }%
  \endgroup
  \@esphack
}%

\makeatother
\begin{document}

\[
  \left\{\begin{array}{l l l l}
    \mylabel{(\textit{i})}{eq:i}\quad        & \epsilon_1E_1^\perp=\epsilon_2E_2^\perp,\quad     &
    \mylabel{(\textit{ii})}{eq:ii}\quad      & B_1^\perp=B_2^\perp,\\\\
    \mylabel{(\textit{iii})}{eq:iii}\quad    & \mathbf{E}_1^\parallel=\mathbf{E}_2^\parallel,\quad   &
    \mylabel{(\textit{iv})}{eq:iv}\quad      & \dfrac{1}{\mu_1}\mathbf{B}_1^\parallel=\dfrac{1}{\mu_2}\mathbf{B}_2^\parallel.
  \end{array}\right.
\]
See~\ref{eq:i}, or~\ref{eq:iv}, or~\ref{eq:iii}, or~\ref{eq:ii}.
\end{document} 

Output:

enter image description here

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.