Placing items before \documentclass
There aren't really problems and in fact some techniques use input before \documentclass
, for example to set a conditional. One has to be careful not to define commands that can be later defined by the class or a package via \newcommand
(for instance \large
).
Of course it would have little sense to set the text width or the text height before \documentclass
, but it's not disallowed: simply it won't work.
You can even say \input{file}
, as long as the code in file.tex
doesn't break the "rule" stated above.
The only command that is formally disallowed before \documentclass
is \usepackage
, as pointed out by doncherry. Other commands just can't because they would be nonsensical (\begin{document}
is an example).
Of course, no text producing command should go before \documentclass
, nor any definition or measurement that relies on document properties such as the default font and size, which are set later. But one can say \AtBeginDocument
.
You can't use \usepackage
before \documentclass
, you'll get an error. There are a few packages recommended to be loaded before it, though, e.g. nag
and hyphsubst
; you have to use \RequirePackage
for them.