Debian Codegraph @

texmf-dist/doc/bibtex/urlbst/urlbst.tex

raw
1 \documentclass[a4paper]{article}
2
3 \title{The \texttt{urlbst} package}
4 \author{Norman Gray\\\texttt{<https://nxg.me.uk>}}
5 \date{Version 0.9.1, 2023 January 30}
6
7 %\usepackage{times}
8 \usepackage{url}
9 \usepackage{hyperref}
10
11 % Not long enough to make it useful to number sections
12 \setcounter{secnumdepth}{0}
13
14 % Squeeze a bit more on to the page
15 %\addtolength\textwidth{1cm}
16 %\addtolength\oddsidemargin{-0.5cm}
17
18 \makeatletter
19 % Easy verbatim mode
20 \catcode`\|=\active
21 \def|{\begingroup \let\do\@makeother \dospecials \verbatim@font \doverb}
22 \def\doverb#1|{#1\endgroup}
23
24 \renewcommand{\verbatim@font}{\normalfont\small\ttfamily}
25 \makeatother
26
27 \newcommand{\ub}{\package{urlbst}}
28 \newcommand{\BibTeX}{Bib\TeX}
29 \newcommand{\package}[1]{\texttt{#1}}
30 \newcommand{\btfield}[1]{\textsf{#1}}
31
32 \begin{document}
33 \maketitle
34
35 The \ub\ package consists of a Perl script which edits \BibTeX\ style
36 files (|.bst|) to add a \btfield{webpage} entry type, and which adds a
37 few new fields -- notably including \btfield{url} --
38 to all other entry types. The distribution includes preconverted
39 versions of the four standard \BibTeX\ |.bst| style files.
40
41 It has a different goal from Patrick Daly's \package{custom-bib}
42 package~\cite{url:daly} -- that is intended to create a \BibTeX\ style
43 |.bst| file from scratch, and supports \btfield{url} and
44 \btfield{eprint} fields. This package, on the other hand, is intended
45 for the case where you already have a style file that works (or at
46 least, which you cannot or will not change), and edits it to add the
47 new \btfield{webpage} entry type, plus the new fields.
48
49 The added fields are:
50 \begin{itemize}
51 \item \btfield{url} and \btfield{lastchecked}, to associate a URL with
52 a reference, along with the date at which the URL was last checked
53 to exist;
54 \item \btfield{doi}, for a reference's DOI
55 (see \url{https://doi.org});
56 \item \btfield{eprint}, for an arXiv eprint reference
57 (see \url{https://arxiv.org}); and
58 \item \btfield{pubmed} for a reference's PubMed identifier
59 (\textsc{PMID}, see \url{http://pubmed.gov}).
60 \end{itemize}
61
62 The script's home page is \url{https://purl.org/nxg/dist/urlbst}
63 (\textbf{please quote this rather than the URL it redirects to}).
64 It is on CTAN at \url{https://ctan.org/pkg/urlbst}.
65 The code repository is at \url{https://heptapod.host/nxg/urlbst}.
66
67
68 \section{Usage}
69 Command line:
70 \begin{verbatim}
71 % urlbst [--setting key=value] [--literal key=value]
72 [input-file [output-file]]
73 \end{verbatim}
74 where the |input-file| is an existing |.bst| file, and
75 the |output-file| is the name of the new style file to be
76 created. If either file name is missing, the default is the
77 standard input or standard output respectively.
78
79 There are a number of settings which can be applied on the
80 command-line, to adjust the support in the generated style file. See
81 the following tables for the (current) list, and \texttt{urlbst --setting help}
82 and \texttt{urlbst --literal help}. Some of these can be alternately
83 set with particular options as shown in Table~\ref{t:options}. Each
84 of these options sets a flag in the generated \texttt{.bst} file, but
85 you should feel free to adjust/hack these flags by editing the generated
86 file (for example |#0 'adddoi :=| will disable generation of DOI
87 links; don't blame me for the eccentric \texttt{.bst} syntax).
88
89 \begin{table}
90 \begin{tabular}{lll}
91 setting&description&default\\
92 \hline
93 inlinelinks & 0=URLs explicit; 1=URLs attached to titles & 0\\
94 addpubmed & 0=no PUBMED resolver; 1=include it & 1\\
95 addeprints & 0=no eprints; 1=include eprints & 1\\
96 hrefform & 0=no crossrefs; 1=hypertex hrefs; 2=hyperref hrefs & 0\\
97 adddoi & 0=no DOI resolver; 1=include it & 1\\
98 doiform & 0=with href; 1=with |\doi{}| & 0\\
99 \end{tabular}
100 \caption{Defined settings}
101 \end{table}
102 \begin{table}
103 \begin{tabular}{lll}
104 literal&description&default\\
105 \hline
106 urlintro & prefix before URL & URL: \\
107 pubmedprefix & prefix before PUBMED ref & PMID:\\
108 pubmedurl & prefix to make URL from PMID \\
109 && \multicolumn1r{\llap{http://www.ncbi.nlm.nih.gov/pubmed/}}\\
110 eprintprefix & prefix printed before eprint ref & arXiv:\\
111 linktextstring & anonymous link text & [link]\\
112 citedstring & label in `lastchecked' remark & cited \\
113 eprinturl & prefix to make URL from eprint ref & https://arxiv.org/abs/\\
114 doiurl & prefix to make URL from DOI & https://doi.org/\\
115 doiprefix & printed text to introduce DOI & doi:\\
116 onlinestring & label that a resource is online & online\\
117 \end{tabular}
118 \caption{Literal strings for inclusion in the generated file}
119 \end{table}
120
121 \begin{table}
122 \begin{tabular}{ll}
123 option & setting\\
124 \hline
125 \texttt{--[no]eprint} & addeprints\\
126 \texttt{--[no]doi} & adddoi\\
127 \texttt{--nohyperlinks} & hrefform=0\\
128 \texttt{--hyper[tex/ref]} & hrefform=1/2\\
129 \texttt{--inlinelinks} & inlinelinks\\
130 \end{tabular}
131 \caption{Backward-compatibility options\label{t:options}}
132 \end{table}
133
134 For example:
135 \begin{verbatim}
136 % urlbst --eprint bibstyle.bst
137 \end{verbatim}
138 would convert the style file \texttt{bibstyle.bst}, including support
139 for e-prints, and sending the result to the standard output (ie, the
140 screen, so it would more useful if you were to either redirect this to
141 a file or supply the output-file argument).
142
143 If the setting \texttt{addeprint} is true (ie, 1), then we switch on support for
144 \btfield{eprint} fields in the modified .bst file, with a citation
145 format matching that recommended in
146 \url{https://arxiv.org/help/faq/references}. If the option
147 \texttt{adddoi} is true, we include support for a \btfield{doi} field, referring
148 to a Digital Object Identifier (DOI) as standardised by
149 \url{https://doi.org/}. And if \texttt{addpubmed} is true, we include
150 support for a \btfield{pubmed} field, referring to a PubMed identifier as
151 supported at \url{http://www.pubmed.gov}.
152
153 The genereated .bst file may include support for hyperlinks where
154 appropriate, in the generated entries in the bibliography. If the
155 \texttt{hrefform} setting is zero, this is suppressed, and it if is~1
156 or~2, the support is include using Hyper\TeX\ (see
157 \url{https://arxiv.org/hypertex/#implementation}), supported by xdvi,
158 dvips and others, or the \package{hyperref} package, respectively. When
159 URLs are included in the bibliography, they are written out using the
160 |\url{...}| command. The \package{hyperref} support is more generic,
161 and more generally supported, and so you should choose this unless you
162 have a particular need for the Hyper\TeX\ support. The
163 \texttt{--nohyperlinks} option, which is present by default,
164 suppresses all hyperlinking.
165
166 By default, any URL field is displayed as part of the bibliography
167 entry, linked to the corresponding URL. If the \texttt{inlinelinks}
168 setting is true, however, then the URL is not displayed in the
169 printed entry, but instead a hyperlink is created, linked to suitable
170 text within the bibliography entry, such as the citation title. This
171 option does not affect the display of eprints, DOI or PubMed fields. It makes
172 no sense to specify \texttt{inlinelinks} with \texttt{hrefform=0}, and the
173 script warns you if you do that, for example by failing to specify one
174 of the link-style options. This option is (primarily) useful if
175 you're preparing a version of a document which will be read on-screen;
176 the point of it is that the resulting bibliography is substantially
177 more compact than it would otherwise be.
178
179 The support for all the above behaviours is always included in the
180 output file. The options instead control only whether the various
181 behaviours are enabled or disabled, and if you need to alter these,
182 you may do so by editing the generated |.bst| file and adjusting
183 values in the |{init.urlbst.variables}| function, where indicated.
184
185 The generated references have URLs inside |\url{...}|. The best
186 way to format this this is with the \package{url} package
187 (see~\cite{texfaq} for pointers), but as a poor alternative, you can
188 try |\newcommand{\url}[1]{\texttt{#1}}|. The \package{hyperref}
189 package automatically processes |\url{...}| in the correct way to
190 include a hyperlink, and if you have selected \package{hyperref}
191 output, then nothing more need be done. If you selected Hyper\TeX\
192 output, however, then the script encloses the |\url| command in an
193 appropriate Hyper\TeX\ special.
194
195 When the style file generates a link for DOIs, it does so by
196 prepending the string \texttt{https://doi.org/} to the DOI. This is
197 generally reasonable, but some DOIs have characters in them which are
198 illegal in URLs, with the result that the resulting
199 \texttt{doi.org} URL doesn't work. The only real way of resolving
200 this is to write a URL-encoding function in the style-file
201 implementation language, but while that would doubtless be feasible in
202 principle, it would be hard and very, very, ugly. The only advice I
203 can offer in this case is to rely on the fact that the DOI will still
204 appear in the typeset bibliography, and that users who would want to
205 take advantage of the DOI will frequently (or usually?) know how to
206 resolve the DOI when then need to. As a workaround, you could include
207 a URL-encoded DOI URL in the \btfield{url} field of the entry (thanks
208 to Eric Chamberland for this suggestion). A slightly more generic
209 approach is to apply the setting \texttt{doiform=1}, which will
210 generate DOIs wrapped in the macro |\doi{...}|. This allows you to
211 supply a generic |\doi| macro to format them as you desire.
212
213 The \btfield{doi} field may include the \texttt{https://doi.org/}, or
214 it may omit it; the stylefile adds or removes the prefix as
215 appropriate. Note that this parsing is rudimentary: it won't detect
216 any of the variants of this prefix, meaning \texttt{http:} or
217 \texttt{dx.doi.org}, both of which are now deprecated.
218 % Note that this string is configured in configure.ac, but changing it
219 % there wouldn't change it here (I could, but... Makefile)
220
221 The \ub\ script works by spotting patterns and characteristic function
222 names in the input |.bst| file. It works as-is in the case of the
223 four standard \BibTeX\ style files |plain.bst|, |unsrt.bst|,
224 |alpha.bst| and |abbrv.bst|. It also works straightforwardly for
225 many other style files -- since many of these are derived from, or at
226 least closely inspired by, the standard ones -- but it does not
227 pretend that it can do so for all of them. In some cases, such as the
228 style files for the \package{refer} or \package{koma-script} packages,
229 the style files are not intended to be used for formatting; others are
230 sufficiently different from the standard files that a meaningful edit
231 becomes impossible. For the large remainder, however, the result of
232 this script should need only relatively minor edits before being
233 perfectly usable.
234
235 \section{New \texttt{.bib} entry and field types}
236
237 The new entry type \btfield{webpage} has required fields
238 \btfield{title} and \btfield{url}, and optional fields
239 \btfield{author}, \btfield{editor}, \btfield{note}, \btfield{year},
240 \btfield{month} and \btfield{lastchecked}. The \btfield{url} and
241 \btfield{lastchecked} fields are new, and are
242 valid in other entry types as well: the first, obviously, is the URL
243 which is being cited, or which is being quoted as an auxiliary source
244 for an article perhaps; the second is the date when you last checked
245 that the URL was there, in the state you quoted it; this is necessary
246 since some people, heedless of the archival importance of preserving
247 the validity of URLs, indulge in the vicious practice of reorganising
248 web pages and destroying links. For the case of the \btfield{webpage} entry
249 type, the \btfield{editor} field should be used for the `maintainer'
250 of a web page.
251
252 For example, in Figure~\ref{f:ex} we illustrate two potential |.bib|
253 file entries. The \texttt{@webpage} entry type is the new type
254 provided by this package, and provides reference information for a
255 webpage; it includes the new \texttt{url} and \texttt{lastchecked}
256 fields. There is also an example of the standard \texttt{@book} entry
257 type, which now includes the \texttt{url} and \texttt{lastchecked}
258 fields as well. The difference between the two references is that in
259 the \texttt{@book} case it is the book being cited, so that the
260 \texttt{url} provides extra information; in the \texttt{@webpage} case
261 it is the page itself which is of interest. You use the new |eprint|,
262 |doi| and |pubmed| fields similarly, if the bibliographic item in
263 question has an e-print, DOI or PubMed reference.
264 \begin{figure}
265 \begin{verbatim}
266 @Manual{w3chome,
267 url = {http://www.w3.org},
268 title = {The World Wide Web Consortium},
269 year = 2009,
270 lastchecked = {26 August 2009}}
271
272 @Book{schutz,
273 author = {Bernard Schutz},
274 title = {Gravity from the GroundUp},
275 publisher = {Cambridge University Press},
276 year = {2003},
277 url = {http://www.gravityfromthegroundup.org/},
278 lastchecked = {2008 June 16}}
279 \end{verbatim}
280 \caption{\label{f:ex}The new \texttt{@webpage} entry type, and the \texttt{url}
281 field in action}
282 \end{figure}
283
284 How do you use this in a document? To use the the
285 \texttt{alphaurl.bst} style -- which is a pre-converted version of the
286 standard \texttt{alpha.bst} style, included in the \texttt{urlbst}
287 distribution -- you simply make sure that \texttt{alphaurl.bst} is in
288 your BibTeX search path (use the command \texttt{kpsepath bst} to find
289 this path and \texttt{kpsewhich alphaurl.bst} to confirm that BibTeX
290 can find it) and add |\bibliographystyle{alphaurl}| to your \LaTeX\ document.
291
292 \section{Sources}
293
294 There are various sources which suggest how to format references to
295 web pages. I have followed none specifically, but fortunately they do
296 not appear to materially disagree.
297
298 ISO-690~\cite{url:iso690} is a formal standard for this stuff. Walker
299 and Taylor's \emph{Columbia Guide to Online Style}~\cite{walker06}
300 provides extensive coverage (but is only available on dead trees).
301 There are two style guides associated with the APA, namely
302 the published APA style
303 guide~\cite{apastyle} (a paper-only publication, so should be
304 ignored by all, if there's any justice in the world), and what appears
305 to be the 1998 web-citation proposal for that~\cite{url:weapas}, which
306 also includes some useful links.
307 The TeX FAQ~\cite{texfaq} has both practical advice and pointers to other sources.%
308 \footnote{Emory University's Goizueta Business Library once had a collection of
309 useful links on this topic, but they've whimsically changed the URL at least twice
310 since I first distributed \ub, and I've got fed up fixing their broken link.}
311
312 \section{Hints}
313
314 If you use Emacs' \BibTeX\ mode, you can insert the following in your
315 |.emacs| file to add knowledge of the new \btfield{webpage} entry:
316 \begin{verbatim}
317 (defun my-bibtex-hook ()
318 (setq bibtex-mode-user-optional-fields '("location" "issn")) ; e.g.
319 (setq bibtex-entry-field-alist
320 (cons
321 '("Webpage"
322 ((("url" "The URL of the page")
323 ("title" "The title of the resource"))
324 (("author" "The author of the webpage")
325 ("editor" "The editor/maintainer of the webpage")
326 ("year" "Year of publication of the page")
327 ("month" "Month of publication of the page")
328 ("lastchecked" "Date when you last verified the page was there")
329 ("note" "Remarks to be put at the end of the entry"))))
330 bibtex-entry-field-alist)))
331 (add-hook 'bibtex-mode-hook 'my-bibtex-hook)
332 \end{verbatim}
333 After that, you can add a \btfield{webpage} entry by typing |C-c C-b webpage|
334 (or |M-x bibtex-entry|).
335
336 It is a \emph{very} good idea to use the \package{url} package: it deals with
337 the problem of line-breaking long URLs, and with the problem that
338 \BibTeX{} creates, of occasionally inserting \%-signs into URLs in
339 generated bibliographies.
340
341 See also the URL entry in the UK \TeX\ FAQ~\cite{texfaq}, and
342 references therein.
343
344 \section{Acknowledgements, and release notes}
345
346 %%% include:release-notes.tex
347
348
349 Thanks are due to many people for suggestions and requests:
350 to Jason Eisner for suggesting the |--inlinelinks| option;
351 to ‘ijvm’ for code contributions in the |urlbst| script;
352 to Paweł Widera for the suggestion to use |\path| when formatting DOIs;
353 to Michael Giffin for the suggestion to include PubMed URLs;
354 to Katrin Leinweber for the pull request which fixed the format of DOI
355 references.
356
357 \begin{description}
358 \item[\textbf{0.9.1, 2023 January 30}]\relax
359
360 Added code to spot and wrangle the |https://doi.org/| URL
361 prefix – the code now behaves correctly whether this is present or not.
362
363
364 \item[\textbf{0.9, 2022 December 1}]\relax
365 \begin{itemize}
366 \item Changed repository location to heptapod\footnote{\url{https://heptapod.host/nxg/urlbst}}
367 (when Bitbucket dropped support for Mercurial).
368 The issue links below, pointing to Bitbucket, will therefore no
369 longer work.
370 \item Refactoring of the mechanism for configuring the generated
371 |.bst| file, specifically adding the
372 |--setting| option.
373 \item Added the |doiform| setting to generate DOIs wrapped
374 in |\doi{...}|.
375 \end{itemize}
376
377
378 \item[0.8, 2019 July 1]\relax
379 \begin{itemize}
380 \item The presence of a preexisting |format.doi|,
381 |format.eprint| or |format.pubmed| function is
382 now detected, and warned about. The resulting |.bst| file
383 might still require some manual editing.
384 Resolves issue 8\footnote{\url{https://bitbucket.org/nxg/urlbst/issue/8}}.
385 \item Clarified licences (I hope).
386 \item Adjust format of DOI resolver.
387 Resolves issue 11\footnote{\url{https://bitbucket.org/nxg/urlbst/issue/11}},
388 thanks to
389 code contributed by Katrin Leinweber\footnote{\url{https://bitbucket.org/nxg/urlbst/pull-requests/1/}}.
390 \end{itemize}
391
392
393 \item[0.7, 2011 July 20]\relax
394 Add |--nodoi|, |--noeprints| and
395 |--nopubmed| options (which defaulted on, and couldn't
396 otherwise be turned off)
397
398 \item[0.7b1, 2011 March 17]\relax
399 Allow parameterisation of literal strings, with option |--literal|.
400
401 \item[0.6-5, 2011 March 8]\relax
402 Adjust support for inline links (should now work for arXiv, DOI and Pubmed)
403
404 \item[0.6-4, 2009 April 28]\relax
405 Work around BibTeX linebreaking bug (thanks to Andras Salamon for the bug report).
406
407 \item[0.6-3, 2009 April 19]\relax
408 Fix inline link generation (thanks to Eric Chamberland for the bug report).
409
410 \item[0.6-2, 2008 November 17]\relax
411 We now turn on inlinelinks when we spot format.vol.num.pages,
412 which means we include links for those styles which don't include a
413 title in the citation (common for articles in physical science styles,
414 such as aip.sty).
415
416 \item[0.6-1, 2008 June 16]\relax
417 Fixed some broken links to the various citation standards
418 (I think in this context this should probably \emph{not} be happening, yes?).
419 The distributed |*url.bst| no longer have the
420 |--inlinelinks| option turned on by default.
421
422 \item[\textbf{0.6, 2007 March 26}]\relax
423 \begin{itemize}
424 \item Added the option |--inlinelinks|, which adds inline hyperlinks
425 to any bibliography entries which have URLs, but does so inline, rather
426 than printing the URL explicitly in the bibliography. This is (primarily)
427 useful if you're preparing a version of a document which will be read
428 on-screen. Thanks to Jason Eisner for the suggestion, and much testing.
429
430 \item Incorporate hyperref bugfixes from Paweł Widera.
431
432 \item Further reworkings of the inlinelinks support, so that it's now
433 fired by a |format.title| (or |format.btitle|) line, with a fallback in
434 |fin.entry|. This should be more robust, and allows me to delete some
435 of the previous version's gymnastics.
436
437 \item Reworked |inlinelinks| support; should now be more
438 robust. Incorporate hyperref bugfixes from Paweł Widera.
439
440 \item Added the option |inlinelinks|, which adds inline hyperlinks
441 to any bibliography entries which have URLs, but does so inline, rather
442 than printing the URL explicitly in the bibliography. This is (only)
443 useful if you're preparing a version of a document which will be read
444 on-screen.
445 \end{itemize}
446
447
448 \item[0.5.2, 2006 September 6]\relax
449 Another set of documentation-only changes, hopefully clarifying
450 installation.
451
452 \item[0.5.1, 2006 January 10]\relax
453 No functionality changes. Documentation and webpage changes only,
454 hopefully clarifying usage and configuration
455
456 \item[\textbf{0.5, 2005 June 3}]\relax
457 Added support for Digital Object Identifiers (DOI) fields in
458 bibliographies.
459
460 \item[0.4-1, 2005 April 12]\relax
461 Documentation improvements -- there are now examples in the help text!
462
463 \item[\textbf{0.4, 2004 December 1}]\relax
464 Bug fixes: now compatible with mla.bst and friends.
465 Now uses |./configure| (optionally). Assorted reorganisation.
466
467 \item[\textbf{0.3, 2003 June 4}]\relax
468 Added |--eprint|, |--hypertex| and |--hyperref| options.
469
470 \item[\textbf{0.2, 2002 October 23}]\relax
471 The `editor' field is now supported in the webpage entry type. Basic
472 documentation added.
473
474 \item[\textbf{0.1, 2002 April}]\relax
475 Initial version
476 \end{description}
477
478 \bibliography{urlbst}
479 \bibliographystyle{plainurl}
480
481 \end{document}