diff --git a/latex/acl_natbib.bst b/latex/acl_natbib.bst index 7fa70cc..cad5a5e 100644 --- a/latex/acl_natbib.bst +++ b/latex/acl_natbib.bst @@ -1,3 +1,16 @@ +%%% Modification of BibTeX style file acl_natbib_nourl.bst +%%% ... by urlbst, version 0.9.1 (marked with "% urlbst") +%%% See and repository +%%% Modifications Copyright 2002–23, Norman Gray, +%%% and distributed under the terms of the LPPL; see README for discussion. +%%% +%%% Added webpage entry type, and url and lastchecked fields. +%%% Added eprint support. +%%% Added DOI support. +%%% Added PUBMED support. +%%% Added hyperref support. +%%% Original headers follow... + %% %% This is file `acl_natbib_basic.bst', %% generated with the docstrip utility. @@ -78,18 +91,74 @@ ENTRY type volume year + doi % urlbst + pubmed % urlbst + url % urlbst + lastchecked % urlbst } {} { label extra.label sort.label short.list } INTEGERS { output.state before.all mid.sentence after.sentence after.block } +% urlbst... +% urlbst constants and state variables +STRINGS { urlintro + eprinturl eprintprefix doiprefix doiurl pubmedprefix pubmedurl + citedstring onlinestring linktextstring + openinlinelink closeinlinelink } +INTEGERS { hrefform doiform inlinelinks makeinlinelink + addeprints adddoi addpubmed } +FUNCTION {init.urlbst.variables} +{ + % The following constants may be adjusted by hand, if desired + + % The first set allow you to enable or disable certain functionality. + #1 'addeprints := % 0=no eprints; 1=include eprints + #2 'hrefform := % 0=no crossrefs; 1=hypertex hrefs; 2=hyperref hrefs + #1 'inlinelinks := % 0=URLs explicit; 1=URLs attached to titles + #1 'adddoi := % 0=no DOI resolver; 1=include it + #1 'addpubmed := % 0=no PUBMED resolver; 1=include it + #0 'doiform := % 0=with href; 1=with \doi{} + + % String constants, which you _might_ want to tweak. + "online" 'onlinestring := % label that a resource is online + "[link]" 'linktextstring := % anonymous link text + "http://www.ncbi.nlm.nih.gov/pubmed/" 'pubmedurl := % prefix to make URL from PUBMED + "https://doi.org/" 'doiurl := % prefix to make URL from DOI + "doi:" 'doiprefix := % printed text to introduce DOI + "https://arxiv.org/abs/" 'eprinturl := % prefix to make URL from eprint ref + "cited " 'citedstring := % label in "lastchecked" remark + "arXiv:" 'eprintprefix := % text prefix printed before eprint ref + "PMID:" 'pubmedprefix := % text prefix printed before PUBMED ref + "URL: " 'urlintro := % text prefix before URL + + % The following are internal state variables, not configuration constants, + % so they shouldn't be fiddled with. + #0 'makeinlinelink := % state variable managed by possibly.setup.inlinelink + "" 'openinlinelink := % ditto + "" 'closeinlinelink := % ditto +} +INTEGERS { + bracket.state + outside.brackets + open.brackets + within.brackets + close.brackets +} +% ...urlbst to here FUNCTION {init.state.consts} -{ #0 'before.all := +{ #0 'outside.brackets := % urlbst... + #1 'open.brackets := + #2 'within.brackets := + #3 'close.brackets := % ...urlbst to here + + #0 'before.all := #1 'mid.sentence := #2 'after.sentence := #3 'after.block := } STRINGS { s t} -FUNCTION {output.nonnull} +% urlbst +FUNCTION {output.nonnull.original} { 's := output.state mid.sentence = { ", " * write$ } @@ -109,6 +178,125 @@ FUNCTION {output.nonnull} if$ s } + +% urlbst... +% 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. +% They communicate between each other using the variables makeinlinelink +% (which is true if a link should be made), and closeinlinelink (which holds +% the string which should close any current link. They can be called +% at any time, but start.inlinelink will be a no-op unless something has +% previously set makeinlinelink true, and the two ...end.inlinelink functions +% will only do their stuff if start.inlinelink has previously set +% closeinlinelink to be non-empty. +% (thanks to 'ijvm' for suggested code here) +FUNCTION {uand} +{ 'skip$ { pop$ #0 } if$ } % 'and' (which isn't defined at this point in the file) +FUNCTION {possibly.setup.inlinelink} +{ makeinlinelink hrefform #0 > uand + { doi empty$ adddoi uand + { pubmed empty$ addpubmed uand + { eprint empty$ addeprints uand + { url empty$ + { "" } + { url } + if$ } + { eprinturl eprint * } + if$ } + { pubmedurl pubmed * } + if$ } +% { doiurl doi * } + { doi empty$ + { "XXX" } + { doi parse.doi pop$ } + if$ + } + if$ + % an appropriately-formatted URL is now on the stack + hrefform #1 = % hypertex + { "\special {html: }{" * 'openinlinelink := + "\special {html:}" 'closeinlinelink := } + { "\href {" swap$ * "} {" * 'openinlinelink := % hrefform=#2 -- hyperref + % the space between "} {" matters: a URL of just the right length can cause "\% newline em" + "}" 'closeinlinelink := } + if$ + #0 'makeinlinelink := + } + 'skip$ + if$ % makeinlinelink +} +FUNCTION {add.inlinelink} +{ openinlinelink empty$ + 'skip$ + { openinlinelink swap$ * closeinlinelink * + "" 'openinlinelink := + } + if$ +} +FUNCTION {output.nonnull} +{ % Save the thing we've been asked to output + 's := + % If the bracket-state is close.brackets, then add a close-bracket to + % what is currently at the top of the stack, and set bracket.state + % to outside.brackets + bracket.state close.brackets = + { "]" * + outside.brackets 'bracket.state := + } + 'skip$ + if$ + bracket.state outside.brackets = + { % We're outside all brackets -- this is the normal situation. + % Write out what's currently at the top of the stack, using the + % original output.nonnull function. + s + add.inlinelink + output.nonnull.original % invoke the original output.nonnull + } + { % Still in brackets. Add open-bracket or (continuation) comma, add the + % new text (in s) to the top of the stack, and move to the close-brackets + % state, ready for next time (unless inbrackets resets it). If we come + % into this branch, then output.state is carefully undisturbed. + bracket.state open.brackets = + { " [" * } + { ", " * } % bracket.state will be within.brackets + if$ + s * + close.brackets 'bracket.state := + } + if$ +} + +% Call this function just before adding something which should be presented in +% brackets. bracket.state is handled specially within output.nonnull. +FUNCTION {inbrackets} +{ bracket.state close.brackets = + { within.brackets 'bracket.state := } % reset the state: not open nor closed + { open.brackets 'bracket.state := } + if$ +} + +FUNCTION {format.lastchecked} +{ lastchecked empty$ + { "" } + { inbrackets citedstring lastchecked * } + if$ +} +% ...urlbst to here FUNCTION {output} { duplicate$ empty$ 'pop$ @@ -122,7 +310,7 @@ FUNCTION {output.check} 'output.nonnull if$ } -FUNCTION {fin.entry} +FUNCTION {fin.entry.original} % urlbst (renamed from fin.entry, so it can be wrapped below) { add.period$ write$ newline$ @@ -558,7 +746,7 @@ FUNCTION {make.full.names} if$ } -FUNCTION {output.bibitem} +FUNCTION {output.bibitem.original} % urlbst (renamed from output.bibitem, so it can be wrapped below) { newline$ "\bibitem[{" write$ label write$ @@ -935,12 +1123,203 @@ FUNCTION {output.eprint} % this is only used with the @misc record type (common if$ } +% urlbst... +% Functions for making hypertext links. +% In all cases, the stack has (link-text href-url) +% +% make 'null' specials +FUNCTION {make.href.null} +{ + pop$ +} +% make hypertex specials +FUNCTION {make.href.hypertex} +{ + "\special {html: }" * swap$ * + "\special {html:}" * +} +% make hyperref specials +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$ +} + +% If inlinelinks is true, then format.url should be a no-op, since it's +% (a) redundant, and (b) could end up as a link-within-a-link. +FUNCTION {format.url} +{ inlinelinks #1 = url empty$ or + { "" } + { hrefform #1 = + { % special case -- add HyperTeX specials + urlintro "\url{" url * "}" * url make.href.hypertex * } + { urlintro "\url{" * url * "}" * } + if$ + } + if$ +} +FUNCTION {format.eprint} +{ eprint empty$ + { "" } + { eprintprefix eprint * eprinturl eprint * make.href } + if$ +} + +FUNCTION {format.doi} +{ doi empty$ + { "" } + { 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$ +} + +FUNCTION {format.pubmed} +{ pubmed empty$ + { "" } + { pubmedprefix pubmed * pubmedurl pubmed * make.href } + if$ +} + +% Output a URL. We can't use the more normal idiom (something like +% `format.url output'), because the `inbrackets' within +% format.lastchecked applies to everything between calls to `output', +% so that `format.url format.lastchecked * output' ends up with both +% the URL and the lastchecked in brackets. +FUNCTION {output.url} +{ url empty$ + 'skip$ + { new.block + format.url output + format.lastchecked output + } + if$ +} + +FUNCTION {output.web.refs} +{ + new.block + 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 (the original version of) this code, + % at http://tex.stackexchange.com/questions/5660) + adddoi + 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 + 'skip$ + { output.url } + if$ + addeprints eprint empty$ not and + { format.eprint output.nonnull } + 'skip$ + if$ + adddoi doi empty$ not and + { format.doi output.nonnull } + 'skip$ + if$ + addpubmed pubmed empty$ not and + { format.pubmed output.nonnull } + 'skip$ + if$ + } + if$ +} + +% Wrapper for output.bibitem.original. +% If the URL field is not empty, set makeinlinelink to be true, +% so that an inline link will be started at the next opportunity +FUNCTION {output.bibitem} +{ outside.brackets 'bracket.state := + output.bibitem.original + inlinelinks url empty$ not doi empty$ not or pubmed empty$ not or eprint empty$ not or and + { #1 'makeinlinelink := } + { #0 'makeinlinelink := } + if$ +} + +% Wrapper for fin.entry.original +FUNCTION {fin.entry} +{ output.web.refs % urlbst + makeinlinelink % ooops, it appears we didn't have a title for inlinelink + { possibly.setup.inlinelink % add some artificial link text here, as a fallback + linktextstring output.nonnull } + 'skip$ + if$ + bracket.state close.brackets = % urlbst + { "]" * } + 'skip$ + if$ + fin.entry.original +} + +% Webpage entry type. +% Title and url fields required; +% author, note, year, month, and lastchecked fields optional +% See references +% ISO 690-2 http://www.nlc-bnc.ca/iso/tc46sc9/standard/690-2e.htm +% http://www.classroom.net/classroom/CitingNetResources.html +% http://neal.ctstateu.edu/history/cite.html +% http://www.cas.usf.edu/english/walker/mla.html +% for citation formats for web pages. +FUNCTION {webpage} +{ output.bibitem + author empty$ + { editor empty$ + 'skip$ % author and editor both optional + { format.editors output.nonnull } + if$ + } + { editor empty$ + { format.authors output.nonnull } + { "can't use both author and editor fields in " cite$ * warning$ } + if$ + } + if$ + new.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ + format.title "title" output.check + inbrackets onlinestring output + new.block + year empty$ + 'skip$ + { format.date "year" output.check } + if$ + % We don't need to output the URL details ('lastchecked' and 'url'), + % because fin.entry does that for us, using output.web.refs. The only + % reason we would want to put them here is if we were to decide that + % they should go in front of the rather miscellaneous information in 'note'. + new.block + note output + fin.entry +} +% ...urlbst to here + + FUNCTION {article} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block crossref missing$ @@ -949,7 +1328,7 @@ FUNCTION {article} "journal" bibinfo.check emphasize "journal" output.check - format.vol.num.pages output + possibly.setup.inlinelink format.vol.num.pages output% urlbst } { format.article.crossref output.nonnull format.pages output @@ -974,6 +1353,7 @@ FUNCTION {book} if$ format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.btitle "title" output.check format.edition output crossref missing$ @@ -998,6 +1378,7 @@ FUNCTION {booklet} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block howpublished "howpublished" bibinfo.check output @@ -1022,6 +1403,7 @@ FUNCTION {inbook} if$ format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.btitle "title" output.check crossref missing$ { @@ -1050,6 +1432,7 @@ FUNCTION {incollection} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block crossref missing$ @@ -1075,6 +1458,7 @@ FUNCTION {inproceedings} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block crossref missing$ @@ -1102,6 +1486,7 @@ FUNCTION {manual} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.btitle "title" output.check format.edition output organization address new.block.checkb @@ -1118,6 +1503,7 @@ FUNCTION {mastersthesis} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block @@ -1136,6 +1522,7 @@ FUNCTION {misc} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title output new.block howpublished "howpublished" bibinfo.check output @@ -1151,6 +1538,7 @@ FUNCTION {phdthesis} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.btitle "title" output.check new.block @@ -1167,6 +1555,7 @@ FUNCTION {presentation} format.authors output author format.key output new.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title output new.block format.organization.address "organization and address" output.check @@ -1187,6 +1576,7 @@ FUNCTION {proceedings} editor format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.btitle "title" output.check format.bvolume output format.number.series output @@ -1209,6 +1599,7 @@ FUNCTION {techreport} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block @@ -1226,6 +1617,7 @@ FUNCTION {unpublished} author format.key output format.date "year" output.check date.block + title empty$ 'skip$ 'possibly.setup.inlinelink if$ % urlbst format.title "title" output.check new.block format.note "note" output.check @@ -1523,6 +1915,7 @@ FUNCTION {begin.bib} write$ newline$ } EXECUTE {begin.bib} +EXECUTE {init.urlbst.variables} % urlbst EXECUTE {init.state.consts} ITERATE {call.type$} FUNCTION {end.bib}