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.

How do the options of a \RequirePackage command interact with options specified for that same package elsewhere?

Here is an example: The pdfx package, if loaded with the a-1b-option, executes the command \RequirePackage[pdftex,pdfa]{hyperref}. However, later in my LaTeX source file, I might also execute the command \usepackage[pdfa=true,linkbordercolor={0 0 1}]{hyperref}. Where in my document should I place the \usepackage[a-1b]{pdfx}-command so that it doesn't cause any conflicts with my hyperref-command? Does the fact that pdfx's \RequirePackage-command loads different options from the ones I am specifying in my \usepackage[...]{hyperref}-command cause problems?

Relevant:

share|improve this question

2 Answers 2

up vote 17 down vote accepted

Basically the package is only loaded once, with the options specified at that point. Any later uses of \RequirePackage or \usepackage are silently ignored if the options specified were specified earlier, or generate an error otherwise. Normally it works to put options on \documentclass, so they are global options seen by all packages.


The help text for the option clash error suggests placing the clashing package in the global options on \documentclass but that in fact isn't very good advice. (One might consider that a latex bug). What does work is to use something like

\documentclass{article}


\PassOptionsToPackage{pdfa=true,linkbordercolor={0 0 1}}{hyperref}
\usepackage[a-1b]{pdfx}
\usepackage[pdfa=true]{hyperref}

\begin{document}
a
\end{document}

\PassOptionsToPackage doesn't actually load the package but does arrange that if it is loaded it will get those options plus any others explicitly listed when it is loaded. So if you suspect that one or more of your packages is internally loading a package and you want to make sure that it has certain options you can use this method. In the particular case of hyperref the alternative suggested in mhp's anwer is also good, avoid the package option and use the hypersetup mechanism instead. However not all packages provide a means to set options after the package is loaded in that way.

share|improve this answer
    
So you mean if a package pkg has been loaded with options [opt1,opt2,...] and there is a later occurrence of either \RequirePackage or \usepackage, that is okay iff the later options are a subset of the earlier ones but generates an error iff there is at least one new option not in the earlier options list? I'm just trying to understand the exact conditions (and they'd be great to see in an answer). –  Lover of Structure Jul 25 '12 at 17:57
    
@user14996: Good question! –  mhp Jul 25 '12 at 21:17
    
@user14996 basically yes except that options on documentclass are global options seen by the package as well but they are handled a bit dofferent;y (ie they are not just prepended to the package option list) I'll remind myself of the details and come back later (might not be today as it's late here) –  David Carlisle Jul 25 '12 at 22:21
    
@DavidCarlisle No rush, any updates to your answer? –  Lover of Structure Jul 30 '12 at 6:17
1  
@DavidCarlisle Awesome. If our comments #1 and #3 in this comment thread could be worked into your answer that would make it perfect ;-) I would make the edit but don't want to write anything that's wrong and am deferring to someone else only for that reason. –  Lover of Structure Jul 31 '12 at 19:56

Loading a package several times with different (i.e. potentially conflicting) options easily results in an option clash. Fortunately, many options of the hyperref package need not be set at load time. You can use \hypersetup to set them:

\hypersetup{linkbordercolor={0 0 1}}
share|improve this answer

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.