TransWikia.com

Redefinition of equation* break the [ ... ], why?

TeX - LaTeX Asked on November 18, 2021

EDIT2: As @Henri commented, this would work: def[#1]{begin{equation*}#1end{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
letMYequationequation
letendMYequationendequation
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
letMYequationequation
letendMYequationendequation
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 globallettikz@ensure@dollar@catcode=relax catcode`$=active protecteddef${@ifnextchar$@doubledollar@singledollar} def@doubledollar$#1$${begin{equation*}#1end{equation*}} def@singledollar#1${(#1)} makeatother (Here the
globallettikz@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[{% relaxifmmode @badmath else ifvmode nointerlineskip makebox[.6linewidth]{}% fi $$%%$$ BRACE MATCH HACK fi }% DeclareRobustCommand]{% relaxifmmode 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[{%    relaxifmmode
      @badmath    else
      ifvmode
         nointerlineskip
         makebox[.6linewidth]{}%
      fi
      $$%%$$ BRACE MATCH HACK    fi }% DeclareRobustCommand]{%    relaxifmmode
      ifinner
         @badmath
      else
         $$%%$$ BRACE MATCH HACK
      fi    else
      @badmath    fi    ignorespaces }% makeatother

% CODE1 makeatletter globallettikz@ensure@dollar@catcode=relax
catcode`$=active
protecteddef${@ifnextchar$@doubledollar@singledollar}
def@doubledollar$#1$${begin{equation*}#1end{equation*}}
def@singledollar#1${(#1)} makeatother

begin{document}

$$ : $$y^2+intmathrm{d} x frac{p}{q_p^p}$$

$backslash[ ... backslash]$ : [y^2+intmathrm{d} x
frac{p}{q_p^p}]

end{document} ```

One Answer

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.

Answered by user30471 on November 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP