[Tex/LaTex] Defining `$$$ $$$` to align

alignmacrosmath-mode

I would like to define

$$$ \zeta(s) = \dfrac1{1^s} + \dfrac1{2^s} + \cdots $$$

as a short hand for

\begin{align}
\zeta(s) = \dfrac1{1^s} + \dfrac1{2^s} + \cdots
\end{align}`

How should I go about doing this?

PS: I am aware of using newcommand to define something like

\newcommand{\ba}[1]{\begin{align}#1 \end{align}}

Best Answer

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