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.

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?

share|improve this question
2  
bad idea. single-line displays need different "surroundings", whether or not they have associated equation numbers. –  barbara beeton Dec 7 '11 at 17:41
    
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. –  Federico Poloni Dec 8 '11 at 8:25
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
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. –  Niel de Beaudrap Dec 7 '11 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 Dec 7 '11 at 18:13
add comment

@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.

share|improve this answer
add comment

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.