As you already have found out the problem occurs every time the hyperref package will be loaded prior to the minted package. This is happening here:
The hyperref package will be loaded. It does not detect the float package (because the float package is not loaded yet), and therefore it does not patch the float package code.
The minted package will be loaded which loads the float package, and does a \newfloat
.
The caption package will be loaded. It does detect the float and hyperref packages, and assumes that the float package code was patched by hyperref. But this assumtion is false in this case.
So as solution you could load the float package prior to the hyperref package and the minted package after the hyperref package - which BTW is the correct load order anyway, see hyperref's README for details.
\documentclass{report}
% it's all in the order of the imports
% this one is the correct one:
% 1. Load the float package
\usepackage{float}
% 2. Load the hyperref package; hyperref will patch the float package
\usepackage{hyperref}
% 3. Load the minted package which will use the patched \newfloat now
\usepackage{minted}
% The load order of the caption package is (or should be) irrelevant now
\usepackage{caption}
\begin{document}
\chapter{test}
\clearpage
\begin{listing}[H] \mint{cl}/(car (cons 1 2))/
\caption{Example of a listing.}
\label{lst:example}
\end{listing}
\clearpage
Listing \ref{lst:example} contains an example of a listing.
\end{document}
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.
Best Answer
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\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 ofhyperref
the alternative suggested in mhp's anwer is also good, avoid the package option and use thehypersetup
mechanism instead. However not all packages provide a means to set options after the package is loaded in that way.