[Tex/LaTex] How to determine in which order packages have been loaded

packages

The \listfiles command will give the list of all loaded files (and therefore also packages) at the end of the .log file, but how do I determine from inside LaTeX, whether package A was loaded before package B or vice versa?

Best Answer

You can access the list as a comma separated list of filenames in \@filelist

If you need this check after \begin{document} use \listfiles so LaTeX saves that information.

\listfiles does

  \@for\@currname:=\@filelist\do{%
      .....

to iterate over this list.

So for example you could define

\makeatletter

\def\test#1#2{%
\def\hmma{#1.sty}%
\let\hmmb\@empty
\@for\@currname:=\@filelist\do{%
   \ifx\@currname\hmma
     \def\hmmb{#2.sty}%
   \fi
   \ifx\@currname\hmmb
       \typeout{#1 loaded before #2}%
   \fi}}

then using this as:

\test{marginnote}{geometry}

will type out

marginnote loaded before geometry

if that is in fact the case.

As noted in the comments you might want to use different comand names in production code, also if the two .sty are removed from the test you can test other files such as class and def files that are listed by LaTeX, but would need to explicitly use the extension, so \test{marginnote.sty}{geometry.sty}