EDIT2: As @Henri commented, this would work: \def\[#1\]{\begin{equation*}#1\end{equation*}}. Thanks for all your kind helping!
EDIT: I think I have convinced myself that the current code is enough to produce my desired result. Now I just wonder:
Why does the following redefinition of equation* break the \[ ... \]? With this, the use of \[ ... \] will produce bunch of errors.
\makeatletter
\let\MYequation\equation
\let\endMYequation\endequation
\RenewEnviron{equation*}{%
\begin{minipage}{\linewidth}
\begin{MYequation}%
\st@rredtrue \global\@eqnswfalse%
\BODY%
\end{MYequation}%
\end{minipage}
}
\makeatother
Redefining the \[ ... \] as below still cannot fix this. I really want to make \[ ... \] the same as \begin{equation*} ... \end{equation}.
\makeatletter
\DeclareRobustCommand\[{%
\begin{equation*}
}%
\DeclareRobustCommand\]{%
\end{equation*}
}%
\makeatother
Here's a 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}
Original question:
I tried to redefine the math-mode double dollar
$$ ... $$. Let's call this CODE1: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(Here the\global\let\tikz@ensure@dollar@catcode=\relaxthing is to preventtikzfrom producing an error.)I also redefined the
\begin{equation*}...\end{equation*}, and thus to prevent (the AMS version of)\[ ... \]from making an error, I have to change the definition of\[ ... \]from theamsmath.styversion to the originalltmath.dtxversion, and let's call this CODE2: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 }% \makeatotherNow here's the question:If I write
CODE 2 CODE 1Then there's no error, but the effect (I mean vertical space) of\[ ... \]is not the same as$$ ... $$. And even if I change CODE2 to the simplified version:$$%%$$ 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} ```
$is going to solve? – Henri Menke Jul 22 '20 at 02:54$active? I still don't see how that would solve this problem. Wouldn't it me much easier to hook into\begin{equation}and\end{equation}to correctly box up these things? – Henri Menke Jul 22 '20 at 04:25equationandequation*environments. However many of my equations are being written onmarkdownusing the$$ ... $$format, thus I would like to hook my box into this too. – Jinwen Jul 22 '20 at 05:32$$, but you can just use theamsmathenvironments directly. Overriding$$will not make you happy. – Henri Menke Jul 22 '20 at 06:43\def\[#1\]{\begin{equation*}#1\end{equation*}}(or something along those lines) for this to work. The\begin{equation*}needs to be able to “see” the\end{equation*}by looking ahead without expanding. – Henri Menke Jul 22 '20 at 08:05\csname equation*\endcsname, not \equation. Note that this only applies to environments. – John Kormylo Jul 22 '20 at 14:32