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}
.\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).