summaryrefslogtreecommitdiff
path: root/biblio/bibtex/contrib/urlbst/urlbst.in
diff options
context:
space:
mode:
Diffstat (limited to 'biblio/bibtex/contrib/urlbst/urlbst.in')
-rwxr-xr-xbiblio/bibtex/contrib/urlbst/urlbst.in33
1 files changed, 27 insertions, 6 deletions
diff --git a/biblio/bibtex/contrib/urlbst/urlbst.in b/biblio/bibtex/contrib/urlbst/urlbst.in
index 569bb7c4fb..3cd06089f5 100755
--- a/biblio/bibtex/contrib/urlbst/urlbst.in
+++ b/biblio/bibtex/contrib/urlbst/urlbst.in
@@ -501,6 +501,19 @@ sub print_output_functions {
print OUT "$mymarker...\n";
print OUT <<'EOD';
+% Minimal DOI parsing.
+% Given a DOI on the stack, check whether it starts with 'doiurl' or not.
+% In either case, leave on the stack first a DOI with, and then a DOI without, the URL prefix.
+FUNCTION {parse.doi}
+{
+ #1 doiurl text.length$ substring$
+ doiurl =
+ { doi
+ doi doiurl text.length$ #1 + #999 substring$ }
+ { doiurl doi *
+ doi }
+ if$
+}
% The following three functions are for handling inlinelink. They wrap
% a block of text which is potentially output with write$ by multiple
% other functions, so we don't know the content a priori.
@@ -527,7 +540,12 @@ FUNCTION {possibly.setup.inlinelink}
if$ }
{ pubmedurl pubmed * }
if$ }
- { doiurl doi * }
+% { doiurl doi * }
+ { doi empty$
+ { "XXX" }
+ { doi parse.doi pop$ }
+ if$
+ }
if$
% an appropriately-formatted URL is now on the stack
hrefform #1 = % hypertex
@@ -683,9 +701,11 @@ EOD
FUNCTION {format.doi}
{ doi empty$
{ "" }
- { doiform #1 =
- { "\doi{" doi * "}" * }
- { doiprefix doi * doiurl doi * make.href }
+ { doi parse.doi % leaves "https://doi.org/DOI" DOI on the stack
+ 's := 't :=
+ doiform #1 =
+ { "\doi{" s * "}" * }
+ { doiprefix s * t make.href }
if$
}
if$
@@ -731,10 +751,11 @@ FUNCTION {output.web.refs}
inlinelinks
'skip$ % links were inline -- don't repeat them
{ % If the generated DOI will be the same as the URL,
- % then don't print the URL (thanks to Joseph Wright for this code,
+ % then don't print the URL (thanks to Joseph Wright
+ % for (the original version of) this code,
% at http://tex.stackexchange.com/questions/5660)
adddoi
- doiurl doi empty$ { "X" } { doi } if$ * % DOI URL to be generated
+ doi empty$ { "X" } { doi parse.doi pop$ } if$ % DOI URL to be generated
url empty$ { "Y" } { url } if$ % the URL, or "Y" if empty
= % are the strings equal?
and