6

Is it possible to redefine \[ ... \] to be equivalent to \begin{align} ... \end{align}?

(I seldom use anything but the align environment, and \[ ... \] is faster and looks cleaner.)

4
  • What would be a motivation?
    – egreg
    Commented Aug 1, 2016 at 21:59
  • (@egreg: See edit.)
    – user66081
    Commented Aug 1, 2016 at 22:03
  • 1
    You shouldn't substitute equation with align, which should only be used with multiline displays.
    – egreg
    Commented Aug 1, 2016 at 22:04
  • @egreg: In this case, this new \[ ... \] could choose automatically...
    – user66081
    Commented Aug 1, 2016 at 22:06

1 Answer 1

8

The align environment is special in the sense, that it needs the end tag \end{align} to be present and not hidden inside macros. The environment internally catches the contents of the environment. Then it can measure the widths, before setting the equations. Therefore the following redefinition only redefines \[ and uses \] to limit the parameter with the contents and passes it to \begin{align} and \end{align}:

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

(\long\def would be needed, when it can happen that there are empty lines in the parameter #1. However, environment align does not like long arguments, thus the definition without \long is better here, see user66081's comment.)

Example file:

\documentclass{article}
\usepackage{amsmath}
\def\[#1\]{\begin{align}#1\end{align}}
\begin{document}
\[
  a &= b\\
  c &= d
\]
\end{document}

Result

6
  • 3
    It won't digest empty lines because align doesn't. It is better w/o \long because the error message (in case of empty lines) makes reference to \[ instead of align
    – user66081
    Commented Aug 1, 2016 at 22:13
  • 1
    (This is great.)
    – user66081
    Commented Aug 1, 2016 at 23:32
  • @user66081 You are right, the original \[ ... \] (without amsmath) allows empty lines, but align of amsmath does not. Commented Aug 1, 2016 at 23:43
  • 1
    Better (IMO) to define \protected\def\[#1\]{\begin{equation*}\begin{split}#1\end{split}\end{equation*}} (or with aligned rather than split may be.
    – Manuel
    Commented Aug 2, 2016 at 0:15
  • @Manuel My interpretation of the question is that \[...\] should be just a shortcut for \begin{align}...\end{align}, because align is the main equation type for the document. Unnumbered equation types still remain available (displaymath, equation*). Commented Aug 2, 2016 at 5:03

You must log in to answer this question.

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