From 463ca065c26b1c014d6ce2ecac901cb1ab49eff6 Mon Sep 17 00:00:00 2001 From: Jan N Rose Date: Thu, 12 Aug 2021 10:02:56 +0200 Subject: [PATCH 1/2] Implement optional loading of hyperref Add package options hyperref (default) and nohyperref --- doi.sty | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doi.sty b/doi.sty index 29054e9..4c53a5c 100644 --- a/doi.sty +++ b/doi.sty @@ -39,10 +39,21 @@ %% https://doi.org/ URL but may be set to old http://dx.doi.org/ %% +%% Declare two complementary boolean options [no]hyperref that determine +%% if hyperref should be loaded in this package. +\newif\if@doihyperref\@doihyperreftrue +\DeclareOption{hyperref}{\@doihyperreftrue} +\DeclareOption{nohyperref}{\@doihyperreffalse} + +%% Execute default options and process the options passed to the package. +\ExecuteOptions{hyperref} % default is the old behaviour, to load hyperref +\ProcessOptions\relax %% We need hyperref, but you probably want to load hyperref %% beforehand, or set some options later on. -\RequirePackage{hyperref} +\if@doihyperref + \RequirePackage{hyperref} +\fi %% To change the default prefix, redefine this command within your own code. %% It takes no argument, which is different from the doipubmed package. From b9116b0608e6c20653314429711b13aab699253d Mon Sep 17 00:00:00 2001 From: Jan N Rose Date: Thu, 12 Aug 2021 13:56:46 +0200 Subject: [PATCH 2/2] Implement runtime check for href Makes hyperlink creation optional and dependent on the user having loaded hyperref --- doi.sty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doi.sty b/doi.sty index 4c53a5c..14274ed 100644 --- a/doi.sty +++ b/doi.sty @@ -99,7 +99,7 @@ \edef\_{_}% \edef\textless{\@percentchar3C}% instead of {\string<} for Apple \edef\textgreater{\@percentchar3E}% instead of {\sting>} for Apple - \edef\x{\toks2={\noexpand\href{\doiurl#1}}}% + \edef\x{\toks2={\ifdefined\href\noexpand\href{\doiurl#1}\fi}}% \x \edef\x{\endgroup\doitext\the\toks2 \the\toks0}% \x