
是否可以在 amsmathequation*
環境中強制自動方程式編號?就像是
\begin{equation*} \dotag
x^2
\end{equation*}
的效果\dotag
是轉變equation*
成equation
?
我在看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
}
並看到未加星標和加星標版本之間的差異是一個附加命令\incr@eqnum
,但是將此程式碼新增到equation*
我的文件中的環境中不起作用。
背景:在 Pandoc 的 markdown 中包含顯示數學的首選方法是將它們包含在一對$$
.對於 LaTeX 輸出,它們被轉換為\[
和\]
,由於amsmath
包含在預設範本中,因此它們就像一個equation*
環境。有一些解決方法,但這種方法有幾個優點。
答案1
這個怎麼樣?正如您所建議的,我使用\incr@eqnum
,但也通過 添加方程式編號\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}
或只是更新環境的定義equation*
。
\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}