# Package options and \RequirePackage: order of commands and option conflicts?

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:

-

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}

\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.

-
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
@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}}

-