[Tex/LaTex] Align environment error – missing } inserted

alignerrorsline-breakingmath-mode

When I try to compile my LaTeX file, where begin{align*} environment is to be used, I constantly get an error:

! Missing } inserted.
<inserted text>
                 }
 1.164 \end{align*}

My LaTeX snippet:

\begin{align*}
X^{(0)} = \lbrace \mathsf{PR \ R \ ST0 \ T+ \ TP \ PR \ , \ PR \ R \ ST- \ T- \ TP \ PR \ , \\ \ PR \ rs \ ST0 \ T- \ TP \ PR \ , \ PR \ rS \ ST+ \ T+ \ TP \ PR \ , \\ \ PR \ Rs \ ST+ \ T+ \ TP \ PR} \rbrace
\end{align*}

The reason I would like to use align*environment is to make the long math mode line to break. I tried to use different commands (linebreak, allowbreak, //, etc.), but they would not help.

Best Answer

In my comment above I have already pointed out what causes the error message. Beyond that, I'm not convinced that you are on the right track. Pure guessing, but I suppose that each of these letter combinations designates some entity that will occur more frequently. To achieve consistent typesetting I suggest to use macros. E.g., you can rewrite your example as follows.

\documentclass{article}
\usepackage{amsmath}
\newcommand\PR{\mathsf{PR}}
\newcommand\R{\mathsf{R}}
\newcommand\STz{\mathsf{ST_0}}
\newcommand\STm{\mathsf{ST_-}}
\newcommand\STp{\mathsf{ST_+}}
\newcommand\Tp{\mathsf{T_+}}
\newcommand\Tm{\mathsf{T_-}}
\newcommand\TP{\mathsf{TP}}
\newcommand\rs{\mathsf{rs}}
\newcommand\rS{\mathsf{rS}}
\newcommand\Rs{\mathsf{Rs}}
\begin{document}
\begin{align*}
  X^{(0)} = \lbrace\;
    & \PR\;\R\;\STz\;\Tp\;\TP\;\PR,\;
      \PR\;\R\;\STm\;\Tm\;\TP\;\PR, \\
    & \PR\;\rs\;\STz\;\Tm\;\TP\;\PR,\;
      \PR\;\rS\;\STp\;\Tp\;\TP\;\PR, \\
    & \PR\;\Rs\;\STp\;\Tp\;\TP\;\PR\;\rbrace
\end{align*}
\end{document}

This will give the following output.

enter image description here

To avoid to hard-code the formatting of the chains of identifiers (like putting some space inbetween), you can put the definitions

\newcommand\chainend{\chainend}
\newcommand\chain[1]{\chainx#1\chainend}
\newcommand\chainx[1]%
  {\ifx\chainend#1\let\chainy\unskip % at the end, remove the last \;
   \else#1\;\let\chainy\chainx % here \; is inserted between any two items of the chain
   \fi
   \chainy
  }
\newcommand\chainy{}

into the preamble and then just write

 \chain{\PR\R\STz\Tp\TP\PR}

instead of

 \PR\;\R\;\STz\;\Tp\;\TP\;\PR
Related Question