LaTeX error "Two \documentclass or \documentstyle commands": cause and fix
The preamble contains a second \documentclass line. A document has exactly one class. \documentstyle is the name of the command in LaTeX 2.09 and counts as well.
Why it happens
- A template or an example was pasted into a document that has its own
\documentclassline. - A file loaded in the preamble with
\inputstarts with its own\documentclass. - A second
\documentclassline was added to pass more options, such as12pt.
How to fix it
- Keep one
\documentclassline, as the first command of the main file, and delete the other. - Put all class options into that line:
\documentclass[12pt,a4paper]{article}. - Files loaded with
\inputcontain no\documentclass, no\begin{document}and no\end{document}. See Split a document into multiple files in LaTeX.
A document that produces the message
\documentclass{article}
\documentclass[12pt]{article}
\begin{document}
Text.
\end{document}The corrected document
\documentclass[12pt]{article}
\begin{document}
Text.
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.