Automatically number inequalities
This might be what you're after, using a counter that increments at every use and resets at the start of every \section
in your document. This can be modified, of course:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{chngcntr}% http://ctan.org/pkg/chngcntr
\newcounter{numrel}% Counter for numering relations
\counterwithin*{numrel}{section}% Counter resets at every section
\newcommand{\numrel}[1]{% Relation numbering
\stepcounter{numrel}% Increment numrel counter
\overset{(\roman{numrel})}{#1}% Print counter + relation
}
\begin{document}
\section{First section}
\begin{align*}
P(x) &= ax^2+bx+c \\
&\overset{(i)}{\leq} cx^3+dx^2+ex+f \\
&\overset{(ii)}{<} gx^4+hx^3+ix^2+jx+k
\end{align*}
\section{Second section}
\begin{align*}
P(x) &= ax^2+bx+c \\
&\numrel{\leq} cx^3+dx^2+ex+f \\
&\numrel{<} gx^4+hx^3+ix^2+jx+k
\end{align*}
\end{document}
In the example above, the first section uses \overset
while the second uses the newly defined \numrel
command, to show the similarities. It would also be possible to modify the code to accommodate for using references so that your document text will change according to the change of adding/removing a line in your equation. The chngcntr
package was used for more flexibility in formatting the counter resetting.
In order to accommodate the possibility to reference the counter within your text, here's a modified minimal example that uses the etoolbox
package to reset the counter at the end of the align*
environment, as well as some amsmath
counter manipulation using Multiply defined labels using hyperref. It uses two counters, the global counter to produce unique reference hooks (important for hyperref
), and a local counter which is actually displayed and reset for each equation. The \numrel{<rel>}{<lab>}
now takes two mandatory arguments. The first is the relation <rel>
while the second is the label <lab>
that may be referenced elsewhere:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{hyperref}% https://ctan.org/pkg/hyperref
\newcounter{numrellocal}% Local counter for numering relations
\renewcommand{\thenumrellocal}{\roman{numrellocal}}% Counter numrellocal uses lowercase roman numerals
\newcounter{numrelglobal}% Global counter for numering relations
\renewcommand{\thenumrelglobal}{\roman{numrellocal}}% Counter numrelglobal uses lowercase roman numerals, but results in value from numrellocal
\makeatletter
\newcommand{\numrel}[2]{% Relation numbering
\stepcounter{numrellocal}% Increment local counter
\refstepcounter{numrelglobal}% Increment global counter and create correct reference hook, with label-text from local counter
\ltx@label{#2}% Label numrel counter
\overset{(\thenumrellocal)}{#1}% Print counter + relation
}
\makeatother
\AfterEndEnvironment{align*}{\setcounter{numrellocal}{0}}% Resets numrellocal at the end of align*
\begin{document}
\section{First section}
\begin{align*}
P(x) &= ax^2+bx+c \\
&\stackrel{(i)}{\leq} cx^3+dx^2+ex+f \\
&\stackrel{(ii)}{<} gx^4+hx^3+ix^2+jx+k
\end{align*}
\section{Second section}
\begin{align*}
P(x) &= ax^2+bx+c \\
&\numrel{\leq}{rel1} cx^3+dx^2+ex+f \\
&\numrel{<}{rel2} gx^4+hx^3+ix^2+jx+k
\end{align*}
If you look at (\ref{rel1}), you will notice it is different from (\ref{rel2}).
\begin{align*}
P(x) &= ax^2+bx+c \\
&\numrel{\leq}{rel3} cx^3+dx^2+ex+f \\
&\numrel{<}{rel4} gx^4+hx^3+ix^2+jx+k
\end{align*}
If you look at (\ref{rel3}), you will notice it is different from (\ref{rel4}).
\end{document}
Here's a try:
\documentclass{article}
\usepackage{amsmath}
\newcounter{hints}
\renewcommand{\thehints}{\roman{hints}}
\newcommand{\hintedrel}[2][]{%
\refstepcounter{hints}%
\if\relax\detokenize{#1}\relax\else\label{#1}\fi
\mathrel{\overset{\mathrm{(\thehints)}}{\vphantom{\le}{#2}}}%
}
\newcommand{\restarthintedrel}{\setcounter{hints}{0}}
\begin{document}
$a\hintedrel[lab1]{\le}b\hintedrel[lab2]{<}c$
(\ref{lab1}): because it's so.
(\ref{lab2}): I tell you it is.
$\restarthintedrel a\hintedrel[lab3]{\le}b\hintedrel[lab4]{<}c$
(\ref{lab3}): because it's so.
(\ref{lab4}): I tell you it is.
\end{document}
The \hintedrel
command has an optional argument, a label for referring later to the inequality.
Before a new chain of hinted inequalities you can write \restarthintedrel
to restart from 1.
Different implementation
\documentclass{article}
\usepackage{amsmath,etoolbox}
\AfterEndEnvironment{equation}{\restarthintedrel}
\AfterEndEnvironment{align}{\restarthintedrel}
\newcounter{hints}
\renewcommand{\thehints}{\roman{hints}}
\newcommand{\hintedrel}[2][]{%
\stepcounter{hints}%
\if\relax\detokenize{#1}\relax\else\csxdef{hint@#1}{\thehints}\fi
\mathrel{\overset{\textrm{(\thehints)}}{\vphantom{\le}{#2}}}%
}
\newcommand{\restarthintedrel}{\setcounter{hints}{0}}
\newcommand{\hintref}[1]{\csuse{hint@#1}}
\begin{document}
\begin{equation}
a\hintedrel[lab1]{\le}b\hintedrel[lab2]{<}c\overset{*}{\le}d
\end{equation}
(\hintref{lab1}): because it's so.
(\hintref{lab2}): I tell you it is.
\begin{align}
a&\hintedrel[lab3]{\le}b\\
&\hintedrel[lab4]{<}c
\end{align}
(\hintref{lab3}): because it's so.
(\hintref{lab4}): I tell you it is.
\end{document}
This assumes that the hints will be referred to only after they are defined (with the standard \label
-\ref
mechanism amsmath would raise an error). You have to add similar \AfterEndEnvironment
for each math environment you use.