# What is the general shape of the preamble of a latex main file?

The task is to identify latex main files to write a maven plugin processing latex files (conversion into various formats).

Currently, I identify the main file with the pattern

.*\\begin\s*\{document\}.*


but this is wrong. What about

\s*\\documentclass.*


? This would mean that apart from blanks, \documentclass must be the very beginning of the file.

I remember that there was a second possibility: \documentstyle?

• \documentclass doesn't need to be the first command. There could be \RequirePackage or definitions before. Also while nowadays normally every LaTeX file has a \documentclass, a main file could also consist simply of an \input{real-main-file}. – Ulrike Fischer Oct 25 '16 at 9:26
• In the meantime I found tex.stackexchange.com/questions/35855/…. – user2609605 Dec 5 '16 at 9:52
• Well, you should check for a \documentclass or \begin{document}, but following any \input provided, so that you can't miss it. How detailed do you want your check? A latex main file means you would also have to check that this is not pdflatex, xelatex or lualatex (check for eventually enhanced features). – TeXnician Jul 4 '17 at 6:39