# [Tex/LaTex] Errors when using \end{align*}

align

I get 6 errors when I use the code below – all 6 of them occur on the line that contains only \end{align*}. The code between the \begin{align*} and \end{align*} works as a displayed equation.

\begin{align*}
p_{\text{undetect}}
&=\sum_{i=0}^{n} {{A_i}{p^i}{(1-p)^{n-i}}} \\
&={{(1-p)^n}{\sum_{i=0}^{n} {{A_i}{\left({\frac{p}{1-p}}\right)}^i}} \\
&={(1-p)^n}\left[\left({\sum_{i=0}^{n} {{A_i}{{\left({\frac{p}{1-p}}\right)}^i}}}\right)-{A_{0}}\right] \\
&={(1-p)^n}}\left[A\left(\frac{p}{1-p}\right)-1\right]
\end{align*}


Four of the error messages are either Missing { inserted or Missing } inserted. The other two error messages are Missing \endgroup and Misplaced \omit.

Your use of the grouping chars { and } is misleading. First, here is the correct way of writing your formula:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
p_{\mathrm{undetect}}
&=\sum_{i=0}^{n} A_i p^i (1-p)^{n-i} \\
&=(1-p)^n\sum_{i=0}^n A_i \left(\frac{p}{1-p}\right)^i \\
&=(1-p)^n\left[\left(\sum_{i=0}^{n} A_i\left(\frac{p}{1-p}\right)^i\right)-A_0\right] \\
&=(1-p)^n\left[A\left(\frac{p}{1-p}\right)-1\right]
\end{align*}
\end{document}


The rule for using the grouping chars here is quite straight forward (as in most other cases): You need to group arguments of macros as in \frac{...}{...}, which apparently takes two arguments, and you need to group the content that is parsed by the special characters ^ and _ (e.g. A_ijk differs dramatically from A_{ijk} and in contrast to what one possibly could think {A_ijk} is not analogous to latter one but to the first example). Any other group is simply superflous. However, A_i and A_{i} are analogous. Even though in the second case the group isn't mandatory, most would recommand to use it to have a uniform input. 