6

I'm trying to redefine \[ and \] so that they behave as \begin{gather*} and end{gather*}. I've been doing this using \DeclareRobustCommmand; however, when I try to compile the following minimal program:

\documentclass[10pt,oneside,a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\let\equation\gather
\let\endequation\endgather
\DeclareRobustCommand{\[}{\begin{gather*}}
\DeclareRobustCommand{\]}{\end{gather*}}
\begin{document}
\[ 2+2=4 \]
\end{document}

I get this error:

! LaTeX Error: \begin{gather*} on input line 9 ended by \end{document`.

This does not happen if I replace gather with equation. What is going on here?

2
  • 2
    bad idea. single-line displays need different "surroundings", whether or not they have associated equation numbers. Commented Dec 7, 2011 at 17:41
  • 1
    Do not call it a bad idea unconditionally. If you have many more multi-line displays than one-line displays, then you can use \[...\] as a shorthand for the former and use the lenghtier \begin{equation}...\end{eqaution} for the latter. Commented Dec 8, 2011 at 8:25

2 Answers 2

6

You can't do like that, because TeX needs to see \end{gather*} in order to know where gather* ends. A low level command definition is needed

\protected\def\[#1\]{\begin{gather*}#1\end{gather*}

But I don't recommend this, as one line displayed equations need different vertical spacing around them, which \[...\] (or equation*) ensures.

2
  • More precisely, \begin{foo} needs to see \end{bar}, and will complain if the string foo is different from the string bar. So the problem is inherent to defining \[ to begin an environment using the \begin{...} syntax. If you want equivalent functionality to the gather* environment, you can do it, but you'll have to re-implement (i.e. duplicate) some of the functionality of environments in general as well. Commented Dec 7, 2011 at 15:37
  • 1
    @NieldeBeaudrap: That's not quite true. You can, for example, redefine the {center} environment in exactly this way and it will work. The problem is actually that the way the amsmath environments are defined requires that the closing tag be visible at the top level. Presumably this is similar to the {verbatim} environment.
    – Ryan Reich
    Commented Dec 7, 2011 at 18:13
1

@Ryan Reich: Your view is the closest. Some changes can be made to the AMS codes to permit the type of abbreviation that the OP seeks. This comes up often. The logic of Michael Downes, the coder of much of the original AMS stuff, is obvious from this snippet:

\edef\begin@stack{%
   \push@begins#1\begin\end \expandafter\@gobble\begin@stack}

This stack will not stop building until the end of the current topmost environment is seen.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .