Did I misunderstand \RequirePackage? I don’t understand an option clash

Have a look at the following example, please.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{my.sty}
\RequirePackage{xcolor}
\end{filecontents}

\RequirePackage{my}
\usepackage[cmyk]{xcolor}

\begin{document}
Content
\end{document}


I expect this to compile, but it reports an option clash. I thought there could be only an option clash if I try to load a package with different options and that there's no clash if the package is loaded multiple times and one time with options. Is that wrong?

I know that I could fix this by changing the order of my and xcolor but I can think about cases where I can’t influence the order (e.g. my is loaded internally by the document class).

I found \RequirePackage without option clashes because of the package loading order? where Herbert gave the solution to split the package loading, which won’t work in my case. And I asked catoptions causes option clash with xcolor, which is possibly a duplicate, a few minutes ago …

The LaTeX2e kernel defines usepackage to be exactly the same as RequirePackage in the ltclass.dtx.

    \if@compatibility\else\let\usepackage\RequirePackage\fi


So the fact that you use RequirePackage makes no difference and you still get an error. If the same package is requested more than once, nothing happens, unless the package has been requested with options that were not given the first time it was loaded, in which case an error is produced.

• Thanks. I kown that \usepackage uses \RequirePackage but I thought that no options won’t cause problems. So did I get you right that there’s no better work around than changing the order of loading packages? – Tobi Feb 26 '12 at 10:38
• @Tobi Unfortunately yes, unless you write your own routine to check if the package is present and then ignore errors. In general though is best to see the clashes. – Yiannis Lazarides Feb 26 '12 at 10:44
• Thanks again. Here Ahmed quotes the error help for the clash which suggests to use global options instead. – Tobi Feb 26 '12 at 11:07

In the above linked question Ahmed Musa quotes the LaTeX error help on an option clash:

? h
[cmyk].
There has now been an attempt to load it with no options.
'cmyk'
to your \documentclass declaration may fix this.


It solves my problem if I set the options for xcolor via \documentclass

\documentclass[cmyk]{article}
\usepackage{my}
\begin{document}
Hello World!
\end{document}

• Another trick is to use \PassOptionsToPackage to pass the option to the package. – Seamus Feb 26 '12 at 11:31
• @Seamus: Yes, I know, thanks. But I don’t like it because it seems inconvenient for me. Are the any pros or cons in preferring the global option way? – Tobi Feb 26 '12 at 12:17
• Well, if you wanted to pass draft option to one package and final option to another, your way wouldn't work… – Seamus Feb 26 '12 at 18:31
• @Seamus. Ahh … I didn’t think on that case :-) – Tobi Feb 27 '12 at 1:48