那么如何定义加载选项fleqn
后的打开和关闭开关呢?amsmath
我研究了开关的来源amsmath.sty
并将其定义为
\makeatletter
\newcommand*{\fleqnon}{\setboolean{@fleqn}{true}}
\newcommand*{\fleqnoff}{\setboolean{@fleqn}{false}}
\makeatother
这两个开关只有在amsmath
加载选项时才有效fleqn
。
梅威瑟:
\documentclass[b6paper]{scrartcl}
%\usepackage[fleqn]{amsmath} % works with the option `fleqn`
\usepackage{amsmath} % fails without the option `fleqn`
\usepackage{ifthen}
\makeatletter
% https://tex.stackexchange.com/a/212099
\newcommand*{\leqnomode}{\tagsleft@true\let\veqno=\@@leqno}
\newcommand*{\reqnomode}{\tagsleft@false\let\veqno=\@@eqno}
% based on my guess on `amsmath.sty`
\newcommand*{\fleqnon}{\setboolean{@fleqn}{true}}
\newcommand*{\fleqnoff}{\setboolean{@fleqn}{false}}
\makeatother
\begin{document}
\fleqnon
\begin{align}
f(x) &= ax^2 + bx + c \\
g(x) &= dx^2 + ex + f
\end{align}
\fleqnoff
\begin{align}
f(x) &= ax^2 + bx + c \\
g(x) &= dx^2 + ex + f \tag{e}
\end{align}
\fleqnon
\leqnomode
\begin{align}
f(x) &= ax^2 + bx + c \\
g(x) &= dx^2 + ex + f \tag{a}
\end{align}
\fleqnoff
\begin{align}
f(x) &= ax^2 + bx + c \\
g(x) &= dx^2 + ex + f
\end{align}
\begin{equation}
a^2+b^2=c^2.
\end{equation}
\reqnomode
\begin{equation}
-\Delta\phi=4\pi k\rho.\tag{2}
\end{equation}
\end{document}
答案1
评论amsmath.dtx
说:
% The code for calculating the appropriate placement of equation
% tags in the \env{align} environments is quite complicated and
% varies wildly depending on the settings of the |tagsleft@| and
% |@fleqn| switches. To minimize memory and hash space usage, we
% only define the variant appropriate for the current setting of
% those switches.
%
这意味着在使用或不使用的四种可能组合fleqn
和leqno
选项中,仅对一组合,在包加载时选择。其他三种可能性将被跳过,并且不会为该组合创建 TeX 定义。
因此,如果您在文档中间更改这些开关中的任何一个,而不从包源复制代码并实现适当的定义,那么布局基本上将是任意的并且通常是错误的,正如您所展示的。