Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

There might be probably many reasons not to do it, but what would be the proper way to redeclare the $$ sequence or the \[,\] pair to open by default some special display math environment, such as \begin{align*},\end{align*}?

(And, of course, what are the reasons not to do it?)

share|improve this question
    
Related: Why is \[\] preferable to $$? –  Werner Oct 26 '13 at 5:17
1  
And also notice why single line display math should not always be written using, say, align. Good old equation(*) has a trick up its sleave –  daleif Oct 26 '13 at 7:59
    
There is no reason whatsoever for using $$ (even if redefined) in LaTeX. There is no reason whatsoever for redefining \[: different environments have different purposes and you gain nothing from changing equation* into align* (actually you lose something). –  egreg Oct 26 '13 at 8:10

2 Answers 2

up vote 4 down vote accepted

While you can redefine [\ to be \begin{align*} and \] to be \end{align*}, it won’t work that because many amsmath environments use the explicit \end{<env>} occurrence to find the body of the environment and to collect it. Even something seemingly trivial like

\newenvironment{<env>}{\begin{align}}{\end{align}}

won’t work. However

\let\<env>\align
\let\end<env>\endalign

would because the environment name <env> is stored by LaTeX when you use \begin{<env>}. With the case of \newenvironment{<env>} amsmath wouldn’t find \end{align} because it is hidden by \end{<env>}.

We can however mimic the behavior of the body-collecting process by defining \[ as a delimited macro that is delimited by \], the actual definition of \] would still be the old (or anything really) it just would never be executed:

\def\[#1\]{\begin{align*}#1\end{align*}}

would allow

\[
 a & = b \\
 b & = c
\]

(This will only work properly until \[ and \] are used in another macro and/or package and expects the original definition.)


The same holds true for $$. However, $$ is not a macro sequence but the double occurrence of the math shift character $ (: 3).

We can make $ active (catcode: 13) so that it can test for a following $ and use (similar to our \[#1\]) a definition that wraps everything until the next $$ in our custom environment.

\catcode`\$=\active
\begingroup
  \catcode`\|=3 % | will act as math-shift
  \makeatletter
  \gdef${\kernel@ifnextchar$\@doubledollar|}
  \gdef\@doubledollar$#1$${\begin{align*}#1\end{align*}}
\endgroup

Note that this will make $ $ (an empty inline math) look like $$ and will also execute \@doubledollar that will expect another $$ (which probably will not be found). We can correct this and/or change that on various ways but all of them will make this even harder to control or make break other things.


Yes, we can do many things but don’t.

share|improve this answer

You should certainly not redefine $$, which is a TeX math primitive command that is used internally by all kinds of LaTeX commands. For more on this topic, see the posting What are the differences between $$, \[, align, equation and displaymath? and the associated answers. If you were to mess with the definition of $$, there's no telling how many things might go seriously wrong. The definition of the align environment would get messed up, for sure.

Modifying the definitions of \] and \] -- which, incidentally, are defined by default as well-crafted "wrappers" around $$ directives -- in the way you're contemplating is also not going to work. This is because the amsmath equation structures "look ahead" to the end of their respective environments in order to gather up all the material into suitable blocks. You'd thus get an error message to the effect that

! LaTeX Error: \begin{align*} on input line xx ended by \end{document}

as LaTeX is searching, unsuccessfully, for an \end{align*} statement.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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