FormaTeX
FatalDocument Structure

Mismatched Environment

! LaTeX Error: \begin{XXX} on input line N ended by \end{YYY}.

What this error means

A \begin{envname} was closed with a different \end{envname}. LaTeX environments must be nested properly — the most recently opened environment must be closed first.

Common causes

  • Typo in the \end{} argument
  • Copy-pasting code with the wrong environment name
  • Environments closed in the wrong order (LIFO violation)

How to fix it

Check that every \begin{foo} has a matching \end{foo}. Environments must close in the reverse order they were opened — if you open itemize inside enumerate, close itemize before enumerate.

Code examples

Causes the error
\documentclass{article}
\begin{document}

\begin{itemize}
  \item First
  \begin{enumerate}
    \item Nested
  \end{itemize}    % Wrong! Should be \end{enumerate}
\end{enumerate}    % Wrong! Should be \end{itemize}

\end{document}
Fixed
\documentclass{article}
\begin{document}

\begin{itemize}
  \item First
  \begin{enumerate}
    \item Nested
  \end{enumerate}  % Close the inner environment first
\end{itemize}      % Then close the outer

\end{document}

Related errors

Test the fix live

Paste your LaTeX into the playground and compile instantly.

ملاحظة سريعة

نتتبع الاستخدام المجهول — مشاهدات الصفحات واستخدام الميزات وأحداث الترجمة — لفهم ما يعمل وما لا يعمل. بدون إعلانات، بدون بيانات شخصية، بدون مشاركة مع أطراف ثالثة.