Hi
> The \AtBeginDocument seems indeed to be what I am looking for! But what
> is its expected behavior? I still see in both the Lyx-latex sources and
> exported .tex the command \AtBeginDocument before the babel/subfig
> lines...
\AtBeginDocument is a LaTeX command and should ensure that the command is
executed
just before \begin{document} even if it is placed before the LyX internal
command.
The caveat is that some packages also use the command (natbib is one example)
and
then the last \AtBeginDocument is placed closes to \begin{document}...
However, if this happens you have to try my other suggestion (the ERT box) or
export
to LaTeX and change the code and run LaTeX manually.
hth,
Ingar Pareliussen