# Numbering of displayed math without using the equation environment

I know about align and equation environments, and tend to use them most of the time, but sometimes I like to have more flexibility within an array of equations, like better control on justification and horizontal spacing. In that case, I use an array environment.
The only downside of this method (that I know of) is the fixed vertical spacing, but for equation arrays wherein every line has the same height, it is usually ok.

For reference, here is my code :

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}

\newcommand*{\defeq}{\vcentcolon=}
\newcommand*{\diff}{\mathrm{d}}

\newcommand*{\pd}[3][]{%
\ensuremath%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}

\newcommand*{\pdc}[4][]{%
\ensuremath%
\left(\pd[#1]{#2}{#3}\right)_{\!\!#4}
}

\newcommand{\td}[3][]{%
\ensuremath%
\frac{\diff^{#1}#2}{\diff #3^{#1}}
}

\newcommand{\earray}[3][2]{%
\ensuremath%
\everymath{\displaystyle}%
\renewcommand*{\arraystretch}{#1}%
\begin{array}{#2}
#3
\end{array}
}

\begin{document}
$\earray{r@{\;}l@{\;}ll}{ \diff J^\pm & \defeq \diff u\pm \frac{1}{C}\diff p & =\left(F\pm\frac{1}{C}G\pdc{p}{e}{V}\right)\diff t & \text{ along a path defined by } \td{\xi}{t}=\pm C,\\ \diff S & \defeq \diff p + C^2 \diff V & =G\pdc{p}{e}{V} \diff t & \text{ along a path defined by } \td{\xi}{t}=0 }$

\begin{align*}
\diff J^\pm
& \defeq \diff u\pm \frac{1}{C}\diff p
& =\left(F\pm\frac{1}{C}G\pdc{p}{e}{V}\right)\diff t
& \text{ along a path defined by } \td{\xi}{t}=\pm C,\\
\diff S
& \defeq \diff p + C^2 \diff V
& =G\pdc{p}{e}{V} \diff t
& \text{ along a path defined by } \td{\xi}{t}=0.
\end{align*}
\end{document}


Here is what the code produces.

So, my question is : is there a way to manually add tags inside displayed math ? Alternatively, is there a better way to proceed, or a better environment, for such cases ?

-
Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Also, please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for people willing to help you solve your problem. Remove that one tedious hurdle; help them help you. In particular, your \pd command is nowhere defined. –  Jubobs May 30 '13 at 9:19
This may be of interest. –  Jubobs May 30 '13 at 9:27
Welcome to TeX.SX! I would strongly advise against using array whenever possible. amsmath and mathtools usually offer enough building blocks for equations. –  mafp May 30 '13 at 9:39
@Jubobs: I included a working example. \numberthis does not work if it is not in an align environment. –  zuggg May 30 '13 at 9:42
@jubobs: interesting, but contains the ineffably clunky \addtocounter{foo}{1} rather than \stepcounter{foo} (or even \refstepcounter{foo} so that a label can be used). –  wasteofspace May 30 '13 at 9:43

An alignat* environment is more suitable here than align* or an array (within a display-math environment). See below.

For numbering lines, you can use the command \numberthis which I define below. That command takes one optional argument, which if not empty, is used to create a label for cross-referencing. (Thanks to wasteofspace for his/her comments.)

Also, see David Carlisle's recommendation regarding the (ab)use of \ensuremath.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[landscape]{geometry}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}

\newcommand\numberthis[1][]{%
\refstepcounter{equation}%
\ifx#1\empty\else\label{eq:#1}\fi%
\tag{\theequation}%
}

\newcommand*{\defeq}{\vcentcolon=}
\newcommand*{\diff}{\mathrm{d}}

\newcommand*{\pd}[3][]{%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}

\newcommand*{\pdc}[4][]{%
\left(\pd[#1]{#2}{#3}\right)_{\!\!#4}
}

\newcommand{\td}[3][]{%
\frac{\diff^{#1}#2}{\diff #3^{#1}}
}

\newcommand{\earray}[3][2]{%
\everymath{\displaystyle}%
\renewcommand*{\arraystretch}{#1}%
\begin{array}{#2}
#3
\end{array}
}

\begin{document}
\begin{alignat*}{4}
&\diff J^\pm
&& \defeq \diff u\pm \frac{1}{C}\diff p
&& =\left(F\pm\frac{1}{C}G\pdc{p}{e}{V}\right)\diff t
&& \text{ along a path defined by } \td{\xi}{t}=\pm C,\\[1em]
&\diff S
&& \defeq \diff p + C^2 \diff V
&& =G\pdc{p}{e}{V} \diff t
&& \text{ along a path defined by } \td{\xi}{t}=0 \numberthis[ju]
\end{alignat*}
Equation \ref{eq:ju} is of interest for\ldots
\end{document}

-
Thank you, alignat seems to be working pretty well. I was not aware of the right/left/right/left... alignment rule inside align environments. If I understand correctly, the big difference between align and alignat is that the latter does not expand the array to the whole page when there is more than one equation column. Is that correct ? Also, while your answer is satisfying, I am still wondering whether or not it is possible to insert tags outside of environments such as align. –  zuggg May 30 '13 at 11:08
@zuggg -- alignat differs from align in that it doesn't add any horizontal space at all; that's up to the user. it also requires that the number of column pairs be specified explicitly. –  barbara beeton May 30 '13 at 14:10

Do not do this!

\newcommand*{\pd}[3][]{%
\ensuremath%
\frac{\partial^{#1}#2}{\partial #3^{#1}}
}


If used in math mode the \ensuremath does nothing but if used out of math mode it will expand to

$\relax\frac${\partial^{#1}#2}{\partial #3^{#1}}


and you will get lots of strange errors as \frac will not see its arguments and \partial will not be in math mode.

Just remove the \ensuremath line.

(for your actual question, I'd recommend using the AMS alignments as Jubobs suggests in his answer)

-