2

Consider the following (well-behaving) latex code, where the hidelinks option works as expected:

\documentclass[american, hidelinks, 12pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{bookmark}

\begin{document}

  \tableofcontents

  \chapter{Foo}
    \section{SFoo}

  Some reference to \autoref{chap:bar}.

  \chapter{Bar}
    \label{chap:bar}
    \section{SBar}

\end{document}

Now if I separate the preamble into its own class, i.e.,

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{some}[2018/01/09 Some Class]

\LoadClass[american, hidelinks, 12pt]{report}

\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{bookmark}

And re-write the MWE from above to use this class:

\documentclass{the-class-from-above}

\begin{document}

  \tableofcontents

  \chapter{Foo}
    \section{SFoo}

  Later, in \autoref{chap:bar}.

  \chapter{Bar}
  \label{chap:bar}
    \section{SBar}

\end{document}

I get the "unused global options" warning for both hidelinks and american (but not 12pt). Indeed, all links appear with a red box, as if hidelinks is not there.

Is there a generic guideline on how to correctly load class options that I am missing?

EDIT:

This question is highly related, but is itself unanswered.

dow
  • 648
  • 4
  • 9
  • It does not seem to be though. \usepackage[hidelinks]{bookmark} fails to compile. – dow Jan 10 '18 at 15:13

1 Answers1

3

The options to \documentclass are "global options" and passed to all packages, but in your revised version the global option list is empty. you need to use hidelinks option and explicitly load hyperref, as passing that option to report does nothing. Similarly the american option does nothing unless you load babel and pass american to that.

David Carlisle
  • 757,742
  • bookmark does not take a hidelinks option.

    That's why I chose it over hyperref, to exclude this possibility.

    – dow Jan 10 '18 at 15:11
  • @dow ah i was thinking it passed it on, so you'd need to load hyperref then (i'll update the answer) . Alternatively of course it's possible to fake things and forcibly add the options on to the macro that latex uses to store the global options but that's not a documented interface and probably not recommended. – David Carlisle Jan 10 '18 at 15:22
  • I am not sure I follow your answer though. If \documentclass passes the options to all packages, then why does the first example work, since it loads bookmark and not hyperref? – dow Jan 10 '18 at 15:30
  • I found this very closely related question, if you would like to take a look:

    https://tex.stackexchange.com/questions/240198/set-global-option-and-pass-it-to-all-packages-in-a-custom-class-file

    As it seems, the whole issue boils down to my not understanding how to pass options via \LoadClass (or similar) and ensure that they are indeed made global---as with \documentclass.

    – dow Jan 10 '18 at 15:43
  • @dow as i said there is no supported way to set the global options other than \documentclass You would have to add them to \@classoptionslist "by hand" – David Carlisle Jan 10 '18 at 15:53
  • @dow in your first version, bookmark loads hyperref and then hyperref sees the global option hidelinks – David Carlisle Jan 10 '18 at 15:54