The following defines \inlineequation:
\inlineequation[<label name>]{<equation>}
- Optionally
<label name> can be given for referencing the equation.
\label afterwards keeps the previous referencing behavior like
an environment equation would have done.
\refstepcounter is called at the beginning of the inline equation, because
package hyperref sets the anchor here.
- A numbered equation should probably not be broken across lines. This is
prevented by the penalty settings at the beginning without loosing stretchability of glues. With
\hbox or \mbox the strechability would be lost.
- The equation number is set by
\@eqnnum that takes care of the formatting of the equation number as in environment equation. It is responsible for adding parentheses
and font settings.
The example file:
\documentclass{article}
\makeatletter
\newcommand*{\inlineequation}[2][]{%
\begingroup
% Put \refstepcounter at the beginning, because
% package `hyperref' sets the anchor here.
\refstepcounter{equation}%
\ifx\\#1\\%
\else
\label{#1}%
\fi
% prevent line breaks inside equation
\relpenalty=10000 %
\binoppenalty=10000 %
\ensuremath{%
% \displaystyle % larger fractions, ...
#2%
}%
~\@eqnnum
\endgroup
}
\makeatother
\usepackage{hyperref}
\begin{document}
The equation
\inlineequation[eq:inline]{a+1=b}
does \dots
\end{document}
