3

Suppose you want to set, in a .sty or .cls file, some hyperref's options in case the end user loads this package. Because that's only at the begin of the document you know if hyperref has been loaded, you have to use something like:

\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{%
    \hypersetup{%
      ⟨my advised hyperref's options⟩%
    }%
  }{%
  }%
}%

This has already been discussed in use hypersetup in own package.

But a drawback of this method is that if the end user has different tastes and inserts \hypersetup{⟨another hyperref's options⟩} in its preamble, the \AtBeginDocument{\hypersetup{...}} from the .sty or .cls file will overwrite his setup.

In order to circumvent this problem, the end user may specify its own \hypersetup choices not in the preamble but in the document's body. But suppose you'd like to not distract the end users with such complication, would it be possible to collect hyperref's \hypersetup argument?

The idea is to get, at the begin of the document, the possible options that have been specified either at the \usepackage level (this is easy with \@ifpackagewith macro) or as \hypersetup argument, and not overwrite them.

4

I guess I've found, not a real answer to the main question, but a solution to the underlying problem (namely how not override end user hyperref's options with an \AtBeginDocument{\hypersetup{...}} declaration in a .sty or .cls file): instead of

\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{%
    \hypersetup{%
      ⟨my advised hyperref's options⟩%
    }%
  }{%
  }%
}%

it should be enough to use

\PassOptionsToPackage{%
  ⟨my advised hyperref's options⟩
}{hyperref}%

These options would be taken in account if (and only if) hyperref is loaded and only at its loading time. Hence ⟨another hyperref's options⟩ specified either with

\hypersetup{⟨another hyperref's options⟩}

or with

\usepackage[⟨another hyperref's options⟩]{hyperref}

will override ⟨my advised hyperref's options⟩ specified in the .sty or .cls file.

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.