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 have several tall, thin expressions - graphical diagrams - which I need to label as if they were equations. Given their shape, it would be mad to have them displayed one underneath the other. I really want to have them next to each other, and give them equation numbers displayed immediately underneath. How can I generate new equation numbers, and then typeset them wherever I please?

This is pseudocode for the sort of effect I want, where \newlabel{blah} is a fictional command which increments the equation count by 1, typesets (n) where n is the new equation number, and sets the label "blah" to refer to this new number.

\[
\begin{array}{cc}
\firstlongthinexpression & \secondlongthinexpression
\\
\newlabel{firstexpr} & \newlabel{secondexpr}
\end{array}
\]
.
.
.
In expressions~\eqref{firstexpr} and~\eqref{secondexpr}, we did blah blah blah.
share|improve this question
    
Does it have to be in math mode? Since these or graphical diagrams, could you put them in a figure or even just a tabular, say? –  Werner Aug 16 '11 at 17:02
    
Perhaps, but I don't think that changes the essence of the problem - I want a macro that generates new equation numbers associated to a particular label, and displays the number in-place. That's how I've set things up above. But if you see some better way to approach things given the context I've given, I'd be happy with that. –  Jamie Vicary Aug 16 '11 at 17:08
add comment

1 Answer

up vote 2 down vote accepted

You define your own commands \mylabel (which works with the existing equation counter) and \myref command to typeset both the label and the reference. In the code below I used \rule{<width>}{<height>} to produce a face "thin equation", just for reference.

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array

\newcommand*{\mylabel}[1]{% Label
  \refstepcounter{equation}% Correct increment for referencing and label
  \label{#1}% Label
  \textrm{(\theequation)}% Typeset label
}%
\newcommand*{\myref}[1]{\textrm{(\ref{#1})}}% Reference

\begin{document}

\begin{equation}
  E=mc^2 \label{einstein}
\end{equation}

\[
  \begin{array}{*{5}{c}}
    \rule{5pt}{4em} & \rule{5pt}{3em} & \rule{5pt}{4em} & \rule{5pt}{3em} & \rule{5pt}{4em} \\
    \mylabel{firstexpr} & \mylabel{secondexpr} & \mylabel{thirdexpr} & \mylabel{fourthexpr} & \mylabel{fifthexpr}
  \end{array}
\]

In expressions~\myref{firstexpr} and~\myref{secondexpr}, we did blah blah blah. However, in expressions~\myref{fifthexpr}, 
\myref{fourthexpr} and \myref{thirdexpr} we have blah blah blah blah. I really like~\myref{einstein}.

\end{document}​

Thin equations with counter/label/reference

Without any other specification, this works fine. However, if you use amsmath, a slight modification is required in the definitions of \mylabel and \myref:

\usepackage{amsmath}% http://ctan.org/pkg/amsmath
...
\makeatletter
\newcommand*{\mylabel}[1]{% Label
  \refstepcounter{equation}% Correct increment for referencing and label
  \ltx@label{#1}% Label
  \textrm{(\@currentlabel{})}% Typeset label
}%
\makeatother
\newcommand*{\myref}[1]{\textrm{\eqref{#1}}}% Reference
share|improve this answer
    
Thanks Werner, that's delightful! But I will have other conventional equations in the document, so I really want to use the standard equation counter rather than a newly-declared one. Is this possible? –  Jamie Vicary Aug 16 '11 at 20:41
    
@Jamie: I've updated my answer to use the conventional equation counter of the document. It will even work if you change the formatting of the equation number to say \renewcommand{\theequation}{\alph{equation}} for alphabetic equation numbers. –  Werner Aug 16 '11 at 21:01
1  
@Werner: your code won't work if the amsmath package is loaded; in this case, you'll need something like \makeatletter \newcommand*{\mylabel}[1]{ \refstepcounter{equation} (\@currentlabel{}) \ltx@label{#1} } \makeatother \newcommand*{\myref}[1]{\eqref{#1}} –  Gonzalo Medina Aug 16 '11 at 21:26
    
@Gonzalo: Thanks. I didn't know how to fix that, but I've added it to my answer. –  Werner Aug 16 '11 at 21:57
add comment

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.