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 use a package foo that requires a package bar with some options. Now, assume that I need bar to be loaded with a different set of options. Unfortunately, when I try to load bar myself I usually end up with an Option clash for package bar LaTeX error. Minimal example:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{foo.sty}
\ProvidesPackage{foo}
\RequirePackage[noisy]{bar}
\end{filecontents}

\begin{filecontents}{bar.sty}
\ProvidesPackage{bar}
\DeclareOption{noisy}{\PackageWarning{bar}{I'm noisy}}
\DeclareOption{silent}{\PackageWarning{bar}{I'm silent}}
\ProcessOptions*
\end{filecontents}

%% \usepackage[silent]{bar}

\usepackage{foo}

\usepackage[silent]{bar}

\begin{document}

\end{document}

What can I do?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

In an ideal world, the LaTeX message Option clash for package … simply indicates an error and, as such, should not be ignored, but entail appropriate measures. Nonetheless, I’ve made the experience that, in reality, there are situations where it is either harmless or even advantageous to circumvent this error. Versatile tools for this purpose are \PreventPackageFromLoading and \ResetPreventPackageFromLoading from the scrlfile package. Minimal example:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{foo.sty}
\ProvidesPackage{foo}
\RequirePackage[noisy]{bar}
\end{filecontents}

\begin{filecontents}{bar.sty}
\ProvidesPackage{bar}
\DeclareOption{noisy}{\PackageWarning{bar}{I'm noisy}}
\DeclareOption{silent}{\PackageWarning{bar}{I'm silent}}
\ProcessOptions*
\end{filecontents}

\usepackage{scrlfile}

\PreventPackageFromLoading{bar}

\usepackage{foo}

\ResetPreventPackageFromLoading

\usepackage[silent]{bar}

\begin{document}

\end{document}
share|improve this answer
    
Why don't you simply put \PassOptionsToPackage{silent}{bar} before \documentclass{article}? –  Harish Kumar Jun 15 '12 at 0:08
    
@HarishKumar: See my comments on the answer given by Daniel E. Shub. –  mhp Jun 15 '12 at 6:24

What about declaring silent as a global option with \documentclass[silent]{article} and then just using \usepackage{bar} in your document. The silent option will still be loaded because of the global option.

share|improve this answer
    
This only works if the silent and noisy options complement each other, but doesn’t work if they are conflicting in some way. –  mhp Jun 14 '12 at 14:48
    
@mhp In that case you really have a clash. Hopefully the bar package is well enough designed to handle requests for conflicting options. The foo package should not be loading the bar package with options that it doesn't require. –  StrongBad Jun 14 '12 at 14:55
    
If you are lucky … ;-) In my experience, there are nowadays quite some opportunities where it is advantageous to outsmart the LaTeX2e option system. –  mhp Jun 14 '12 at 17:31

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.