0

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=\relax thing is to prevent tikz from 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 the amsmath.sty version to the original ltmath.dtx version, 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 }% \makeatother Now here's the question:

If I write CODE 2 CODE 1 Then 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} ```
14
  • 3
    Classic XY problem. What is it that you are actually trying to do? What problem do you think an active $ is going to solve? Jul 22 '20 at 2:54
  • 2
    I see, and what does this have to do with making $ 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? Jul 22 '20 at 4:25
  • 1
    If you are generating LaTeX with pandoc you don't have to use $$, but you can just use the amsmath environments directly. Overriding $$ will not make you happy. Jul 22 '20 at 6:43
  • 1
    You need to do \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. Jul 22 '20 at 8:05
  • 1
    However, I think it is easier to collect the equation in a box and then manipulate the box. This has other subtleties, but at least doesn't require looking ahead which is always fragile. Jul 22 '20 at 8:08
3

Why not use the etoolbox?

\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}

Your MWE does not show any difference between \[...\] and the equation* environment but I believe that this does what you want with a minimum of technology.

1
  • Nice suggestion +1
    – MadyYuvi
    Oct 27 '20 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.