[Tex/LaTex] Package amsmath Error: Erroneous nesting of equation structures

alignamsmathpandoc

When I run pandoc periodic.md -o example.pdf --pdf-engine=xelatex --template eisvogel --listings -VCJKmainfont="Microsoft YaHei", pandoc reported an error:

! Package amsmath Error: Erroneous nesting of equation structures;
(amsmath)                trying to recover with `aligned'.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.430 \end{align}

BTW, I use pandoc-latex-template so there is --template eisvogel in the command.

Here's my markdown source file.
Actually, this document is written in another language and this is the reason why there is -VCJKmainfont="Microsoft YaHei" in the command I executed. For easy understanding, I translate it into English.

---
title: "Cyclical phenomena in life"
author: [andylizf]
date: "2019.3.23"
keywords: [Markdown]
---


## Definition of periodicity

In general, for the function $f(x)$, if there is a non-zero constant $T$, such that for every $x$ in the domain,
$$
f(x + T) = f(x)
$$
For a periodic function $f(x)$, if there is a smallest positive number in all its cycles, then this smallest positive number is called the smallest positive period of $f(x)$.

## Periodic phenomena in mathematics

### Trigonometric function

According to the induction formula,
$$
\begin{align}
    \sin x&= \sin(x + 2\pi) \label{eq1}\\
    \cos x&= \cos(x + 2\pi) \label{eq2}\\
    \tan x&= \tan(x + \pi) \label{eq3}\\
\end{align}
$$

Best Answer

The {align} or {align*} environment is like the {equation} or {equation*} environments and are used for arranging equations of multiple lines. (Use the asterisk to avoid automatic numbering of equations.) When you place an {align} environment inside $$, it is equivalent to nesting an equation environment inside another equation environment, hence the error message "Erroneous nesting of equation structures."

As you appear to have already discovered, simply remove the $$ surrounding the \begin{align}...\end{align}, and your markdown will set properly.

Other environments you may wish to explore are {multline} or {multline*} to left-align the first equation, and right-align the last equation, {gather} or {gather*} to write consecutive equations without alignment, {flalign} or {flalign*} that works like {align} but right-aligns what occurs after the ampersand, and {alignat} or {alignat*} that allows for several columns of equation to be aligned rather than just 2.

Related Question