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?
\documentclassdoesn't need to be the first command. There could be\RequirePackageor 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 09:26\documentclassor\begin{document}, but following any\inputprovided, 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 04 '17 at 06:39