From ed0e84c965a0667df4491e53e17d97a3bd1cf41e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 12 Jan 2017 13:49:04 -0500 Subject: [PATCH] Fix the bibliography DOI output when the hyperref package is not loaded. The last attempt at adding hyperref support for DOIs worked, but it broke things when the hyperref package isn't loaded. This commit fixes it by conditionally defining a no-op \href in the absense of the hyperref package. Now that I understand what's going on a little bit better, I was also able to eliminate some of the urlbst boilerplate. --- mjo.bst | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/mjo.bst b/mjo.bst index 105ec77..5a09e3d 100644 --- a/mjo.bst +++ b/mjo.bst @@ -68,12 +68,10 @@ ENTRY { label } STRINGS { doiprefix doiurl } -INTEGERS { hrefform } FUNCTION {init.doi.variables} { "http://dx.doi.org/" 'doiurl := % prefix to make URL from DOI "doi:" 'doiprefix := % text prefix printed before DOI ref - #2 'hrefform := % 0=no crossrefs; 1=hypertex xrefs; 2=hyperref refs } INTEGERS { output.state before.all mid.sentence after.sentence after.block } FUNCTION {init.state.consts} @@ -491,33 +489,8 @@ FUNCTION {format.issn} if$ } -FUNCTION {make.href.null} -{ - pop$ -} - -FUNCTION {make.href.hypertex} -{ - "\special {html: }" * swap$ * - "\special {html:}" * -} - -FUNCTION {make.href.hyperref} -{ - "\href {" swap$ * "} {\path{" * swap$ * "}}" * -} - FUNCTION {make.href} -{ hrefform #2 = - 'make.href.hyperref % hrefform = 2 - { hrefform #1 = - 'make.href.hypertex % hrefform = 1 - 'make.href.null % hrefform = 0 (or anything else) - if$ - } - if$ -} +{ "\href {" swap$ * "} {\path{" * swap$ * "}}" * } FUNCTION {format.doi} { doi empty$ @@ -1483,6 +1456,10 @@ FUNCTION {begin.bib} write$ newline$ " \providecommand{\doi}{doi:\discretionary{}{}{}\begingroup \urlstyle{rm}\Url}\fi" write$ newline$ + "\expandafter\ifx\csname href\endcsname\relax" + write$ newline$ + " \def\href#1#2{#2} \def\path#1{#1}\fi" + write$ newline$ } EXECUTE {begin.bib} EXECUTE {init.doi.variables} -- 2.44.2