• monkeycode
Platform
  • Problems
  • Contests
  • News
  • Help
Back to Help Center
Back to Help Center

General

  • Getting Started
  • Supported Languages

Validators

  • Figure Environment Validator
  • Begin/End Macro Validator
  • Begin Document Validator

Plugin

  • Introduction to Plugins
  • Add Plugin to Problem Package
  • Reading Samples and Test-Cases

Support

  • Contact Us

Begin/End Macro Validator

Learn about the begin/end macro pairing validator and how to resolve unmatched environment errors.

What It Does

The Begin/End Macro Validator checks that every \begin{...} in your LaTeX file has a corresponding \end{...}. It walks the entire document tree and uses a stack to track open environments. If any \begin remains unmatched after processing, the validator reports an error.

When This Error Occurs

You will see this error when one or more \begin macros do not have a matching \end:

Unmatched \begin on line 5, 12

The error message includes the line numbers of all unmatched \begin macros to help you locate them quickly.

Common Causes

There are a few typical reasons this error appears:

  • Missing \end tag — You opened an environment but forgot to close it.
  • Typo in environment name — The names in \begin{...} and \end{...} don't match, e.g. \begin{itemze} vs \end{itemize}.
  • Accidentally deleted a line — A \end line was removed during editing.
  • Incorrect nesting — Environments overlap instead of being properly nested.

How to Fix It

Make sure every \begin{environment} has a matching \end{environment} with the exact same name. Environments must be properly nested — they cannot overlap.

Before (incorrect):

\begin{enumerate}
  \item First item
  \begin{itemize}
    \item Sub-item
  \end{enumerate}
\end{itemize}

After (correct):

\begin{enumerate}
  \item First item
  \begin{itemize}
    \item Sub-item
  \end{itemize}
\end{enumerate}

Tip

If you have a large document and the error is hard to track down, try collapsing or folding environments in your editor to visually verify that each \begin pairs with the correct \end.

Further Reading

For a deeper understanding of how LaTeX macros and environments work, see How TeX macros actually work on Overleaf.

Figure Environment Validator
Begin Document Validator