2

The MWE below results in the error:

Undefined control sequence. \hypersetup

It's minimized from a CV that definitely compiled fine a month ago (with the warnings discussed in What does "You have requested package `foo', but the package provides `foo'." mean?). I've tried in up-to-date setups of both MiKTeX and TeX Live. I suspect some package that was updated in the meantime is causing an incompatibility, but having a hard time tracking down which one. I'm hoping someone can identify it, so that I can revert to an older version, or suggest a workaround.

\documentclass{moderncv}

\moderncvstyle{banking}
\moderncvcolor{black}
\name{John}{Doe}

\hypersetup{}

\begin{document}

\makecvtitle

Lorem ipsum

\end{document}

Changing the documentclass to article (and replacing the moderncv specific lines with \usepackage{hyperref}) makes it compile fine. If I include

\usepackage{hyperref}

I get an Option clash for package hyperref. error, presumably because moderncv is loading hyperref.

4
  • 1
    \hypersetup is from the hyperref package. So add \usepackage{hyperref} to your document. And no, it didn't compile previously, I checked with texlive 2018 and 2019 on overleaf. And it doesn't compile with article either, as article doesn't load hyperref. Nov 18 '20 at 18:35
  • @UlrikeFischer see edit. It's quite possible I minimized incorrectly, but I'm confused by the mwe as it is.
    – ronno
    Nov 18 '20 at 18:42
  • 5
    moderncv loads hyperref with AtEndPreamble. So you either need to use AtEndPreamble{\hypersetup{...}} or load hyperref with \usepackage[unicode]{hyperref} to avoid the options clash. Nov 18 '20 at 18:46
  • @UlrikeFischer, that seems to have fixed it, my original document had \AtBeginDocument{\hypersetup{...}}, which throws a more complicated error, maybe worth asking about in a separate question.
    – ronno
    Nov 18 '20 at 19:28
2

There is an easy workaround: simply move comand \hypersetup behind \begin{document} like this:

\documentclass{moderncv}

\moderncvstyle{banking}
\moderncvcolor{black}
\name{John}{Doe}

%\hypersetup{} % <========================================= move it down

\begin{document}
\hypersetup{} % <=======================================================

\makecvtitle

Lorem ipsum

\end{document}

The reason is that class moderncv, current version 2.0, loads hyperref with AtEndPreamble. That means that hyperref is called after your complete preamble. That means that your call is to early, at that moment hyperref is not loaded and therefore \hypersetup is an unknown command, resulting the error message you got.

With the moved command \hypersetup after \begin{document} package hyperref is already called and \hypersetup is a valid command ...

3
  • Although this fixes the compilation issue, this does not work as intended for me. Package hyperref Warning: Option 'colorlinks' has already been used, setting the option has no effect... Apr 12 at 16:15
  • @Rastapopoulos please ask a new question,adding an mwe resulting in your error ...
    – Mensch
    Apr 12 at 17:06
  • 1
    A working solution, which I found in another answer, is the following: just before begin{document}, write \AtBeginDocument{\hypersetup{colorlinks=true,linkcolor=blue}} , for example. Apr 13 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.