Force numbering of amsmath equation*?

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.

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*}
$$y^2$$
\begin{equation*} \dotag
z^2
\end{equation*}
\end{document}


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*}
$$y^2$$
\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