Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the lipics document class, which includes hyperref. I want to load the float package, which should be loaded before hyperref, without changing the document class. As suggested in this comment, I am trying to use the KOMA-Script called scrlfile (cf. page 199 of the documentation), in the following way

\documentclass{lipics}
\usepackage{scrlfile}
\BeforePackage{hyperref}{
  \usepackage{float}
}
...

however it never loads the package.

What I am doing wrong?

share|improve this question
2  
Try \RequirePackage{scrfile}\BeforePackage{hyperref}{\usepackage{float}}\documentcl‌​ass{lipics} ` –  Marco Daniel Apr 7 '12 at 16:49
    
There is something really odd. It rise an warning You have requested package `hyperref', but the package provides `float'. and the error Command \c@float@type already defined. However, if I do not put anything and try to use some commands from the package float (for example \floatstyle{boxed} \restylefloat{figure}) I get the undefined commands error. I am a bit lost. –  Alejandro Díaz-Caro Apr 7 '12 at 20:47

1 Answer 1

up vote 6 down vote accepted

The problem here is that you need to call \BeforePackage{} and related commands before the package is actually loaded so that the hooks can work. This is what Marco's suggestion tries to do.

Unfortunately, you cannot load an additional package using \BeforePackage{} because, when lipics finally requests hyperref, loading float will call the \ProvidesPackage{float} declaration and LaTeX thinks that the wrong package is being provided.

I have found that it is best to use \AfterPackage or \AfterClass. Why not just load the float package right after the article documentclass that lipics uses?

\RequirePackage{scrlfile}
\AfterClass{article}{
  \RequirePackage{float}
}

\documentclass[english]{lipics}
\begin{document}
Hi
\end{document}

If you really want to make \BeforePackage{} work, you can use the following hack

\BeforePackage{hyperref}{
  \let\oldProvidesPackage\ProvidesPackage   % Save original definition
  \def\ProvidesPackage#1[#2]{               % Redefine (simply)        
    \oldProvidesPackage#1[#2]               % Call original \ProvidesPackage
    \let\ProvidesPackage\oldProvidesPackage % restore original definitions
    \let\oldProvidesPackage\relax

    \RequirePackage{float}                  % Now load float
  }
}

This temporarily redefines \ProvidesPackage to first call the original version (which will tell LaTeX that hyperref is being provided as expected), then to load float after restoring the old definitions.

share|improve this answer
    
The first solution, load float after article, worked! Thanks! –  Alejandro Díaz-Caro Apr 8 '12 at 15:04

Your Answer

 
discard

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.