Is there a way to apply some options to a package which is loaded in the cls file I am using? For instance, suppose that the cls file loads graphicx
, and I want to apply the option demo
to it from my tex file.
[Tex/LaTex] Applying options to already loaded package
package-optionspackages
Related Solutions
André Miede's idea is that one should copy classicthesis-preamble.sty
in the working directory and changes is to suit the needs for a particular job.
Not a very good idea, in my opinion, as the code in this package is quite intimidating for the novice and does not limit itself to some
\usepackage[<options>]{<package>}
lines, maybe with some auxiliary definitions. It's not very clear why saying
\PassOptionsToPackage{fleqn}{amsmath} % math environments and more by the AMS
\RequirePackage{amsmath}
is to be preferred to the simpler
\usepackage[fleqn]{amsmath}
or what the novice user is supposed to do with
\ifthenelse{\boolean{cld@backref}}%
{%
\PassOptionsToPackage{hyperpageref}{backref}
\RequirePackage{backref} % to be loaded after hyperref package
\renewcommand{\backreftwosep}{ and~} % seperate 2 pages
\renewcommand{\backreflastsep}{, and~} % seperate last of longer list
\renewcommand*{\backref}[1]{} % Disable standard
\renewcommand*{\backrefalt}[4]{% Detailed backref
\ifcase #1 %
\backrefnotcitedstring%
\or%
\backrefcitedsinglestring{#2}%
\else%
\backrefcitedmultistring{#2}%
\fi}%
}{\relax}
which is code that should go in classicthesis.sty
.
If you feel intimidated by classicthesis-preamble.sty
, then don't load it and add the packages you need, passing the desired options directly to classicthesis.
For example
\documentclass[...]{scrbook}
\usepackage[fleqn]{amsmath}
\usepackage[eulerchapternumbers,subfig,beramono,eulermath,parts]{classicthesis}
\usepackage{hyperref}
\hypersetup{%draft, % = no hyperlinking at all (useful in b/w printouts)
colorlinks=true, linktocpage=true, pdfstartpage=3, pdfstartview=FitV,%
% uncomment the following line if you want to have black links (e.g., for printing)
%colorlinks=false, linktocpage=false, pdfborder={0 0 0}, pdfstartpage=3, pdfstartview=FitV,%
breaklinks=true, pdfpagemode=UseNone, pageanchor=true, pdfpagemode=UseOutlines,%
plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1,%
hypertexnames=true, pdfhighlight=/O,%hyperfootnotes=true,%nesting=true,%frenchlinks,%
urlcolor=webbrown, linkcolor=RoyalBlue, citecolor=webgreen, %pagecolor=RoyalBlue,%
%urlcolor=Black, linkcolor=Black, citecolor=Black, %pagecolor=Black,%
pdftitle={},%
pdfauthor={},%
pdfsubject={},%
pdfkeywords={},%
pdfcreator={pdfLaTeX},%
pdfproducer={LaTeX with hyperref and classicthesis}%
}
which might be sufficient for many purposes.
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.
Best Answer
If a package is loaded, the option setting code in the package is already processed and gone. Thus in general you cannot change package options later.
\PassOptionsToPackage
But you can specify options earlier, before loading the package. Apart from a global option (with side effects for other packages)
\PassOptionsToPackage
can be even used before\documentclass
, e.g.:Package interface for loading options
Sometimes a package or class allows the setting of a subset of options later. For example, package
hyperref
provides\hypersetup
. Also some options of packagegraphicx
(or rather for\includegraphics
) can be set via:However, the option
demo
is not supported this way.