TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!”?

share|improve this question
up vote 16 down vote accepted

According to the documentation of afterpackage this should work

share|improve this answer
Great, thank you! – canaaerus Jul 24 '12 at 9:53

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


It has a bunch of other useful commands.

share|improve this answer
Actually I do use scrartcl. So that clears up why I got “\AfterPackage already defined” on \usepackage{afterpackage}. – canaaerus 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.

share|improve this answer
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}. – canaaerus Jul 24 '12 at 9:39
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 posting your answer, you agree to the privacy policy and terms of service.

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