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

Jinwen
  • 8,518
  • 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? – Henri Menke Jul 22 '20 at 02:54
  • @Henri, actually I'm trying to make every equation's height an integer multiple of 1cm. And in the way doing so I meet this question. – Jinwen Jul 22 '20 at 03:13
  • 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? – Henri Menke Jul 22 '20 at 04:25
  • @Henri, I have actually done the work on equation and equation* environments. However many of my equations are being written on markdown using the $$ ... $$ format, thus I would like to hook my box into this too. – Jinwen Jul 22 '20 at 05:32
  • @XuJinwen Perhaps you can a) define a new equation environment that accomplish the concrete-height task and b) modify the parser used to output latex from markdown to use that customized equation environment. – muzimuzhi Z Jul 22 '20 at 05:51
  • 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. – Henri Menke Jul 22 '20 at 06:43
  • @Henri, I restated my problem. Do you have any idea about this? – Jinwen Jul 22 '20 at 08:00
  • 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. – Henri Menke Jul 22 '20 at 08: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. – Henri Menke Jul 22 '20 at 08:08
  • @Henri, Thank you for your previous reply! Perhaps you can describe it in more detail (I don't quite understand your words on box) and make it an answer, so that I can accept it? – Jinwen Jul 22 '20 at 09:00
  • @XuJinwen My ideas are far too vague to write a proper answer. Maybe something along those lines? http://dpaste.com/24NFGLC7E (expires in 10 days) – Henri Menke Jul 22 '20 at 10:15
  • The equation* environment starts with\csname equation*\endcsname, not \equation. Note that this only applies to environments. – John Kormylo Jul 22 '20 at 14:32
  • I believe this question is related to an earlier one: https://tex.stackexchange.com/q/554459 concerning grid typesetting. – barbara beeton Jul 22 '20 at 18:24
  • @Barbara Thanks! I will try to make some edit as you said there when I have time ;) – Jinwen Jul 23 '20 at 01:49

1 Answers1

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.