Hyperref is loaded by the class, and I need to load packages that are supposed to be loaded before

Short version: yes, you'll have to redefine the class, or at least patch their hyperref inclusion.

I ran into a similar problem with my hyperref-using thesis class (which was originally a package). When it was a package, I could have students load packages before or after my thesis package, and hyperref would then be in the right order. Once I made a class, though, all my packages would be loaded first in the \documentclass line, which made it impossible for anyone to work around hyperref. Rather than abandon hyperref entirely, I added the following to the class:

\IfFileExists{\jobname-packages-loaded-before-hyperref.sty}{%
  \RequirePackage{\jobname-packages-loaded-before-hyperref}
}{}

% For all sorts of hyperlinks in the PDF output.
\RequirePackage[pdfcreator={pdfLaTeX with hyperref},
  plainpages=false,
  pdfpagelabels,
  hypertexnames=true,
  colorlinks=false]{hyperref}

\IfFileExists{\jobname-packages-loaded-after-hyperref.sty}{%
  \RequirePackage{\jobname-packages-loaded-after-hyperref}%
}{}

and now my students just have to put all their extra \usepackage or \RequirePackage entries in one of two .sty files. Examples: before package, after package, and class.


It is well-known (and should be to class authors) that hyperref needs to be loaded as late as possible. Hence, the class should really be changed not to load hyperref.


In the KOMA-Script-bundle, Markus Kohm’s replacement for the standard LaTeX-classes and much more, he includes a package called scrlfile, that is designed to execute actions both before and after the loading of files. May be that package can solve your problems. It can be used on a stand alone basis.

If you do not read German, the author has started the work on improving the English manual. He describes scrlfile on pages 248ff. You will find KOMA-Script at CTAN and BerliOS.

Links to the new, improved, English manual you will find here.