3

Is it possible to force an automatic equation number in an amsmath equation* environment? Something like

\begin{equation*} \dotag
x^2
\end{equation*}

where the effect of \dotag is to transform equation* into equation?

I looked at amsmath.sty

\renewenvironment{equation}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswtrue
  \mathdisplay{equation}%
}{%
  \endmathdisplay{equation}%
  \mathdisplay@pop
  \ignorespacesafterend
}
\newenvironment{equation*}{%
  \mathdisplay@push
  \st@rredtrue \global\@eqnswfalse
  \mathdisplay{equation*}%
}{%
  \endmathdisplay{equation*}%
  \mathdisplay@pop
  \ignorespacesafterend
}

and saw that the difference between the unstarred and the starred version is an additional command \incr@eqnum, but adding this code to the equation* environment in my document doesn't work.

Background: The preferred way to include display math in Pandoc's markdown is to enclose them in a pair of $$. For LaTeX output, they are translated into \[ and \], and since amsmath is included in the default template, these act like an equation* environment. There are workarounds, but this way has several advantages.

5

How about this? I use \incr@eqnum, as you suggest, but also add the equation number via \tag.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand\dotag{\incr@eqnum\tag{\number\value{equation}}}
\makeatother
\begin{document}
\begin{equation*} \dotag
x^2
\end{equation*}
\begin{equation}
y^2
\end{equation}
\begin{equation*} \dotag
z^2
\end{equation*}
\end{document}

enter image description here

Or just renew the definition of the equation* environment.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\renewenvironment{equation*}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswtrue
  \mathdisplay{equation}%
}{%
  \endmathdisplay{equation}%
  \mathdisplay@pop
  \ignorespacesafterend
}
\makeatother
\begin{document}
\begin{equation*}
x^2
\end{equation*}
\begin{equation}
y^2
\end{equation}
\begin{equation*} 
z^2
\end{equation*}
\end{document}
  • Thanks, I didn't think of \makeatletter, or more precisely, never quite understood what it does. – A. Donda Dec 7 '19 at 2:48

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.