In my previous question I ended up with


But now I'm using the fontspec package which redefines : with \AtBeginDocument itself. So as my own definition comes before fontspec is loaded, even putting it in \AtBeginDocument won't help.

Is there a way to say “Execute this after fontspec has loaded!” or “Execute this at the very end of \AtBeginDocument!”?


According to the documentation of afterpackage this should work


There's also the scrlfile package from KOMA-script:


It has a bunch of other useful commands.

  • 1
    Actually I do use scrartcl. So that clears up why I got “\AfterPackage already defined” on \usepackage{afterpackage}. – bodo Jul 24 '12 at 11:58

Put it in \AtBeginDocument after you load fontspec any commands saved by that command are executed in order, so if you do it that way your saved commands will be executed after the packages.

  • 1
    Well, that is exactly what I didn't want to do. Actually I'm issuing \DeclareMathSymbol in my document class, which I then \dump with the rest of the preamble to speed up compilation. fontspec can not be dumped, so I put it right before \begin{document}. – bodo Jul 24 '12 at 9:39
  • 2
    ah well an alternative is to patch \document to add your hook stuff just after it runs \@begindocumenthook – David Carlisle Jul 24 '12 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.