Defining `$$$ $$$` to align

You can. But I strongly discourage you to use the following code that implements your idea. The resulting document code is obscure and error prone. If you forget a $ somewhere, you'll probably get weird error messages when TeX is very far from the point where the missing $ should be.

Disclaimer. Using this code can cause kittens die; it can also cause the computer to rebel against you and create a computer domination over the world. You've been advised.

\documentclass{article}
\usepackage{amsmath,array}

\let\normaldollar=$
\catcode`$=\active
\makeatletter
\protected\def${\new@ifnextchar${\check@two}{\(\close@single}}
\def\close@single#1${#1\)}
\def\check@two#1{\@ifstar{\do@equation@star}{\check@three}}
\def\check@three{\new@ifnextchar${\check@three@star}{\do@equation}}
\def\check@three@star#1{\@ifstar{\do@align@star}{\do@align}}
\def\do@equation@star#1$${\[#1\]}
\def\do@equation#1$${\begin{equation}#1\end{equation}}
\def\do@align#1$$${\begin{align}#1\end{align}}
\def\do@align@star#1$$${\begin{align*}#1\end{align*}}
\makeatother

\begin{document}
In line math $abc$, followed by a numbered equation
$$
1+1=\left\lbrace\begin{array}{@{}l>{\normaldollar}l<{\normaldollar}@{}}
2 & if it rains\\
3 & otherwise
\end{array}\right.
$$
followed by an unnumbered equation
$$*
2+2=4
$$
followed by a numbered align
$$$
a&=b\\
c&=d
$$$
followed by an unnumbered align
$$$*
f&=g\\
&=h
$$$
\end{document}

For example, forgetting the $ after abc, you get an error at line 34, which reads

! Misplaced alignment tab character &.

Try it. Then forget about this idea. Using \newcommand{\ba}[1]{\begin{align}#1\end{align}} is even worse.

enter image description here


You shouldn't. You actually shouldn't use $$...$$ either in LaTeX: Why is \[ … \] preferable to $$?

It is probably doable, but would be very difficult to do so that it doesn't break things like these two (\usepackage{array} needed for the 2nd one):

$$$ x_n = 0 \quad\text{for $n=1,2,3,\dotsm$} $$$
\begin{tabular}{>$l<$} 3x^2 \\ $Hello, World!$ \end{tabular}

Please, please, write a legible code and don't use cryptic shorthands like proposed $$$...$$$ or (maybe even worse) \ba{...}.


As giordano points out, if you want to type the code faster, ask a question on how to type the code faster, and not how to shorten the code. For typing the code faster, you can find some good editors that support various kinds of auto-completion: LaTeX Editors/IDEs


If we are using plain TeX then our life is simpler. We are typing:

$$\eqalign{
   a &= b + c \cr
   c &= d + e
}$$

when we need to typeset aligned equations. And your idea about $$$ ... $$$ can be implemented simply by \everydisplay:

\everydisplay={\futurelet\next\eqalignQ}
\def\eqalignQ{\ifx\next$\expandafter\eqalignX\fi}
\def\eqalignX$#1$$${\eqalign{#1}$$}

$$$
   a &= b + c \cr
   c &= d + e
$$$

\end

And we have no LaTeX-syntactical purists in our own ranks.