45

When I run this code, I'm getting the error:

"! LaTeX Error: Option clash for package hyperref."

Code

\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}         
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths} 

\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}                   
\phone{phone +64 6 212 0549}                      
\email{contact@robward.co.nz}                      
\homepage{www.robward.co.nz}                

\usepackage[pdftex,
            pdfauthor={Rob Ward},
            pdftitle={CV for Rob Ward},
            pdfsubject={Detailed CV for Rob},                   
            urlcolor={blue}]{hyperref}

\begin{document}

% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston North}{New Zealand}{}  % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New Zealand}{}

\end{document}

2 Answers2

52

Update: moderncv loads the package hyperref by itself with its own hypersetup. From moderncv.cls,

enter image description here

Hence, you need not load hyperref again. But load the hypersetup using \AfterPreamble (or \AtBeginDocument) hook as in this code:

\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}

\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{contact@robward.co.nz}
\homepage{www.robward.co.nz}

\AfterPreamble{\hypersetup{
  pdfauthor={Rob Ward},
  pdftitle={CV for Rob Ward},
  pdfsubject={Detailed CV for Rob},
  urlcolor=blue,
}}

\begin{document}


% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston
North}{New Zealand}{}  % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria
University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New
Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New
Zealand}{}

\end{document}

The pdf properties will then look like:

enter image description here

Earlier attempt:

   \PassOptionsToPackage{pdftex,
            pdfauthor={Rob Ward},
            pdftitle={CV for Rob Ward},
            pdfsubject={Detailed CV for Rob},
            urlcolor={blue}}{hyperref}

\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}

\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{contact@robward.co.nz}
\homepage{www.robward.co.nz}

%\usepackage[pdftex,
%            pdfauthor={Rob Ward},
%            pdftitle={CV for Rob Ward},
%            pdfsubject={Detailed CV for Rob},
%            urlcolor={blue}]{hyperref}

\begin{document}

% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston North}{New Zealand}{}  % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New Zealand}{}

\end{document}

enter image description here

Note: Noting the comments of Heiko Oberdiek,

Package hyperref does a lot of redefinitions in order to support non-ASCII stuff in strings for bookmarks and entries in the information dictionary of PDF files. Much of this support gets lost, if LaTeX expands the options the hard way before hyperref has a chance to see them. Therefore it is better to set the information entries after hyperref is loaded.

this is not always advisable. In this case, it won't give desired results as the hypersetup is over-written later by the moderncv itself.

  • 2
    Package hyperref does a lot of redefinitions in order to support non-ASCII stuff in strings for bookmarks and entries in the information dictionary of PDF files. Much of this support gets lost, if LaTeX expands the options the hard way before hyperref has a chance to see them. Therefore it is better to set the information entries after hyperref is loaded. – Heiko Oberdiek Oct 28 '12 at 12:09
  • Same problem with style attachfile. It loads hyperref as well which raises the clash error when trying to use \hypersetup. Easy solution for that style: first load hyperref, then load attachfile. – Twonky Jul 05 '16 at 09:51
8

In this case this can be solved by:

\usepackage{hyperref}
\hypersetup{
  pdfauthor={...},
  pdftitle={...},
  pdfsubject={...},
  urlcolor=blue,
}

The entries for the PDF information dictionary should be better set after the package is loaded. Also the other entries (urlcolor) can be set afterwards. pdftex is not needed, hyperref detects pdfTeX in PDF mode automatically.

Generic methods to solve option clashes are - \PassOptionsToPackage before the first loading of the package. - Adding all options needed in the first loading of the package (not always possible, if the package is loaded indirectly).

The full example

\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}

\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{contact@robward.co.nz}
\homepage{www.robward.co.nz}

\usepackage{hyperref}
\hypersetup{
  pdfauthor={Rob Ward},
  pdftitle={CV for Rob Ward},
  pdfsubject={Detailed CV for Rob},
  urlcolor=blue,
}

\begin{document}

% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston
North}{New Zealand}{}  % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria
University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New
Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New
Zealand}{}

\end{document}

I do not get any option clash.

Heiko Oberdiek
  • 271,626
  • Hi Thanks , but i am still getting same error – Ekaveera Gouribhatla Oct 28 '12 at 11:40
  • Hi @Oberdiek,i am unable to rectify the same error even after implementing your correction. – Ekaveera Gouribhatla Oct 28 '12 at 12:19
  • 2
    @Ekaveera Which correction? Which error? Make a complete example that shows the problem. Maybe also add \listfiles to get a list of packages/classes with versions at the end of the LaTeX run. – Heiko Oberdiek Oct 28 '12 at 12:23
  • Hi @Oberdiek i am talking about the same error "Option clash for Package hyperref" even after running the code given by you.i am using Texworks as an editor,not command line. so where can i put \listfiles in the editor? should i include before \begin{document}. – Ekaveera Gouribhatla Oct 28 '12 at 13:01
  • @Ekaveera That's not possible, unless you explicitly load hyperref with options or the class moderncv loads hyperref several times with different options (unlikely) or you are loading other packages that implicitly load hyperref with options. Anyway you have to update your example in the question. – Heiko Oberdiek Oct 28 '12 at 13:09
  • Ok Thank you, i will try to solve and will get back to you.. – Ekaveera Gouribhatla Oct 28 '12 at 13:23
  • 1
    @heiko oberdiek: moderncv does indeed load hyperref, and also does its own \hypersetup. Ekaveera's simple \usepackage{hyperref} is enough to provoke the error message, i would think. – wasteofspace Oct 28 '12 at 15:33
  • 1
    @wasteofspace No, only if a package is loaded with options that are not given before, the option clash error is raised. – Heiko Oberdiek Oct 28 '12 at 16:09