I'm developing a small LaTeX library that requires hyperref to work, but I'm facing 2 problems:
I think that hyperref should usually be loaded at the very end. However, if I put a
\RequirePackage{hyperref}
in my library, will it be loaded at the beginning? If the user also adds\usepackage{hyperref}
at the end, will it solve the problem, or will it be ignored ashyperref
was already loaded before?When the user adds options to the
hyperref
package, it breaks with an error:ERROR: LaTeX Error: Option clash for package hyperref.
So what is the proper way to say "my package requires hyperref", but still allow the user to overwrite the hyperref options/make sure it's loaded last?
Thanks!
MWE:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}[overwrite]{mypackage.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}[2020/07/13 A dummy package]
\RequirePackage{hyperref}
\end{filecontents}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{mypackage}
\usepackage[colorlinks]{hyperref}
\begin{document}
Hello
\end{document}
hyperref
and say in the documentation of your package please load hyperref but use\PassOptionsToPackage{<option list>}{hyperref}
in your package file. See theclsguide
for more help on package and class creation\AtEndPreamble{\RequirePackage{hyperref}
(needs etoolbox), but it doesn't solve every problem.