编辑2:正如@Henri 评论的那样,这将起作用:\def\[#1\]{\begin{equation*}#1\end{equation*}}
。感谢您所有的帮助!
编辑:我想我已经说服自己,当前的代码足以产生我想要的结果。现在我只是想知道:
为什么以下的重新定义会equation*
破坏\[ ... \]
?这样,使用\[ ... \]
就会产生一堆错误。
\makeatletter
\let\MYequation\equation
\let\endMYequation\endequation
\RenewEnviron{equation*}{%
\begin{minipage}{\linewidth}
\begin{MYequation}%
\st@rredtrue \global\@eqnswfalse%
\BODY%
\end{MYequation}%
\end{minipage}
}
\makeatother
重新定义如下\[ ... \]
仍然无法解决这个问题。我真的想把它做成\[ ... \]
和一样\begin{equation*} ... \end{equation}
。
\makeatletter
\DeclareRobustCommand\[{%
\begin{equation*}
}%
\DeclareRobustCommand\]{%
\end{equation*}
}%
\makeatother
以下是 MWE:
\documentclass{article}
\usepackage{amsmath}
\usepackage{environ}
\makeatletter
\let\MYequation\equation
\let\endMYequation\endequation
\RenewEnviron{equation*}{%
\begin{minipage}{\linewidth}
\begin{MYequation}%
\st@rredtrue \global\@eqnswfalse%
\BODY%
\end{MYequation}%
\end{minipage}
}
\makeatother
\begin{document}
\begin{equation*} % this is fine
y^2
\end{equation*}
% \[y^2\] % this will produce an error
\end{document}
原始问题:
我尝试重新定义数学模式的 double dollar
$$ ... $$
。我们称之为代码1:(latex \makeatletter \global\let\tikz@ensure@dollar@catcode=\relax \catcode`\$=\active \protected\def${\@ifnextchar$\@doubledollar\@singledollar} \def\@doubledollar$#1$${\begin{equation*}#1\end{equation*}} \def\@singledollar#1${\(#1\)} \makeatother
这里的\global\let\tikz@ensure@dollar@catcode=\relax
事情就是为了防止tikz
产生错误。)我还重新定义了
\begin{equation*}...\end{equation*}
,从而防止(AMS 版本的)犯了一个错误,我必须将版本\[ ... \]
的定义更改为原始版本,我们称之为\[ ... \]
amsmath.sty
ltmath.dtx
代码2:latex \makeatletter \DeclareRobustCommand\[{% \relax\ifmmode \@badmath \else \ifvmode \nointerlineskip \makebox[.6\linewidth]{}% \fi $$%%$$ BRACE MATCH HACK \fi }% \DeclareRobustCommand\]{% \relax\ifmmode \ifinner \@badmath \else $$%%$$ BRACE MATCH HACK \fi \else \@badmath \fi \ignorespaces }% \makeatother
现在问题是:如果我写
CODE 2 CODE 1
则不会出错,但是 的效果(我的意思是垂直空间)\[ ... \]
与 不一样$$ ... $$
。即使我将 CODE2 更改为简化版本:$$%%$$ BRACE MATCH HACK }% \DeclareRobustCommand\]{% $$%%$$ BRACE MATCH HACK }% \makeatother ``` They still look different. However, if I write ``` CODE 1 CODE 2 ``` Then there's an error ``` Paragraph ended before \@doubledollar was complete. ``` Why is this happening? Is there any way to achieve this properly? ----- Below is a MWE: ```latex \documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usetikzlibrary{calc} % CODE2 \makeatletter \DeclareRobustCommand\[{% \relax\ifmmode \@badmath \else \ifvmode \nointerlineskip \makebox[.6\linewidth]{}% \fi $$%%$$ BRACE MATCH HACK \fi }% \DeclareRobustCommand\]{% \relax\ifmmode \ifinner \@badmath \else $$%%$$ BRACE MATCH HACK \fi \else \@badmath \fi \ignorespaces }% \makeatother % CODE1 \makeatletter \global\let\tikz@ensure@dollar@catcode=\relax \catcode`\$=\active \protected\def${\@ifnextchar$\@doubledollar\@singledollar} \def\@doubledollar$#1$${\begin{equation*}#1\end{equation*}} \def\@singledollar#1${\(#1\)} \makeatother \begin{document} \$\$ : $$y^2+\int\mathrm{d} x \frac{p}{q_p^p}$$ $\backslash[ ... \backslash]$ : \[y^2+\int\mathrm{d} x \frac{p}{q_p^p}\] \end{document} ```
答案1
为什么不使用电子工具箱?
\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\csdef{[}{\begin{equation*}}
\csdef{]}{\end{equation*}}
\begin{document}
\begin{equation*} % this is fine
y^2
\end{equation*}
\[y^2\] % this works too
\end{document}
您的 MWE 没有显示\[...\]
与equation*
环境之间的任何差异,但我相信这可以用最少的技术实现您想要的效果。