summaryrefslogtreecommitdiff
path: root/biblio/bibtex/contrib/urlbst/urlbst.tex
blob: 8f16c6260f925a7d74a14e401b8f7878d619b302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
\documentclass[a4paper]{article}

\title{The \texttt{urlbst} package}
\author{Norman Gray\\\texttt{<https://nxg.me.uk>}}
\date{Version 0.9.1, 2023 January 30}

%\usepackage{times}
\usepackage{url}
\usepackage{hyperref}

% Not long enough to make it useful to number sections
\setcounter{secnumdepth}{0}

% Squeeze a bit more on to the page
%\addtolength\textwidth{1cm}
%\addtolength\oddsidemargin{-0.5cm}

\makeatletter
% Easy verbatim mode
\catcode`\|=\active
\def|{\begingroup \let\do\@makeother \dospecials \verbatim@font \doverb}
\def\doverb#1|{#1\endgroup}

\renewcommand{\verbatim@font}{\normalfont\small\ttfamily}
\makeatother

\newcommand{\ub}{\package{urlbst}}
\newcommand{\BibTeX}{Bib\TeX}
\newcommand{\package}[1]{\texttt{#1}}
\newcommand{\btfield}[1]{\textsf{#1}}

\begin{document}
\maketitle

The \ub\ package consists of a Perl script which edits \BibTeX\ style
files (|.bst|) to add a \btfield{webpage} entry type, and which adds a
few new fields -- notably including \btfield{url} --
to all other entry types.  The distribution includes preconverted
versions of the four standard \BibTeX\ |.bst| style files.

It has a different goal from Patrick Daly's \package{custom-bib}
package~\cite{url:daly} -- that is intended to create a \BibTeX\ style
|.bst| file from scratch, and supports \btfield{url} and
\btfield{eprint} fields.  This package, on the other hand, is intended
for the case where you already have a style file that works (or at
least, which you cannot or will not change), and edits it to add the
new \btfield{webpage} entry type, plus the new fields.

The added fields are:
\begin{itemize}
\item \btfield{url} and \btfield{lastchecked}, to associate a URL with
  a reference, along with the date at which the URL was last checked
  to exist;
\item \btfield{doi}, for a reference's DOI
  (see \url{https://doi.org});
\item \btfield{eprint}, for an arXiv eprint reference
  (see \url{https://arxiv.org}); and
\item \btfield{pubmed} for a reference's PubMed identifier
  (\textsc{PMID}, see \url{http://pubmed.gov}).
\end{itemize}

The script's home page is \url{https://purl.org/nxg/dist/urlbst}
(\textbf{please quote this rather than the URL it redirects to}).
It is on CTAN at \url{https://ctan.org/pkg/urlbst}.
The code repository is at \url{https://heptapod.host/nxg/urlbst}.


\section{Usage}
Command line:
\begin{verbatim}
% urlbst [--setting key=value] [--literal key=value]
    [input-file [output-file]]
\end{verbatim}
where the |input-file| is an existing |.bst| file, and
the |output-file| is the name of the new style file to be
created.  If either file name is missing, the default is the
standard input or standard output respectively.

There are a number of settings which can be applied on the
command-line, to adjust the support in the generated style file.  See
the following tables for the (current) list, and \texttt{urlbst --setting help}
and \texttt{urlbst --literal help}.  Some of these can be alternately
set with particular options as shown in Table~\ref{t:options}.  Each
of these options sets a flag in the generated \texttt{.bst} file, but
you should feel free to adjust/hack these flags by editing the generated
file (for example |#0 'adddoi :=| will disable generation of DOI
links; don't blame me for the eccentric \texttt{.bst} syntax).

\begin{table}
  \begin{tabular}{lll}
    setting&description&default\\
    \hline
inlinelinks & 0=URLs explicit; 1=URLs attached to titles & 0\\
addpubmed & 0=no PUBMED resolver; 1=include it & 1\\
addeprints & 0=no eprints; 1=include eprints & 1\\
hrefform & 0=no crossrefs; 1=hypertex hrefs; 2=hyperref hrefs & 0\\
adddoi & 0=no DOI resolver; 1=include it & 1\\
doiform & 0=with href; 1=with |\doi{}| & 0\\
  \end{tabular}
  \caption{Defined settings}
\end{table}
\begin{table}
  \begin{tabular}{lll}
    literal&description&default\\
    \hline
urlintro & prefix before URL & URL: \\
pubmedprefix & prefix before PUBMED ref & PMID:\\
pubmedurl & prefix to make URL from PMID \\
  && \multicolumn1r{\llap{http://www.ncbi.nlm.nih.gov/pubmed/}}\\
eprintprefix & prefix printed before eprint ref & arXiv:\\
linktextstring & anonymous link text & [link]\\
citedstring & label in `lastchecked' remark & cited \\
eprinturl & prefix to make URL from eprint ref & https://arxiv.org/abs/\\
doiurl & prefix to make URL from DOI & https://doi.org/\\
doiprefix & printed text to introduce DOI & doi:\\
onlinestring & label that a resource is online & online\\
  \end{tabular}
\caption{Literal strings for inclusion in the generated file}
\end{table}

\begin{table}
  \begin{tabular}{ll}
    option & setting\\
    \hline
    \texttt{--[no]eprint} & addeprints\\
    \texttt{--[no]doi} & adddoi\\
    \texttt{--nohyperlinks} & hrefform=0\\
    \texttt{--hyper[tex/ref]} & hrefform=1/2\\
    \texttt{--inlinelinks} & inlinelinks\\
  \end{tabular}
  \caption{Backward-compatibility options\label{t:options}}
\end{table}

For example:
\begin{verbatim}
% urlbst --eprint bibstyle.bst
\end{verbatim}
would convert the style file \texttt{bibstyle.bst}, including support
for e-prints, and sending the result to the standard output (ie, the
screen, so it would more useful if you were to either redirect this to
a file or supply the output-file argument).

If the setting \texttt{addeprint} is true (ie, 1), then we switch on support for
\btfield{eprint} fields in the modified .bst file, with a citation
format matching that recommended in
\url{https://arxiv.org/help/faq/references}.  If the option
\texttt{adddoi} is true, we include support for a \btfield{doi} field, referring
to a Digital Object Identifier (DOI) as standardised by
\url{https://doi.org/}.  And if \texttt{addpubmed} is true, we include
support for a \btfield{pubmed} field, referring to a PubMed identifier as
supported at \url{http://www.pubmed.gov}.

The genereated .bst file may include support for hyperlinks where
appropriate, in the generated entries in the bibliography.  If the
\texttt{hrefform} setting is zero, this is suppressed, and it if is~1
or~2, the support is include using Hyper\TeX\ (see
\url{https://arxiv.org/hypertex/#implementation}), supported by xdvi,
dvips and others, or the \package{hyperref} package, respectively.  When
URLs are included in the bibliography, they are written out using the
|\url{...}| command.  The \package{hyperref} support is more generic,
and more generally supported, and so you should choose this unless you
have a particular need for the Hyper\TeX\ support.  The
\texttt{--nohyperlinks} option, which is present by default,
suppresses all hyperlinking.

By default, any URL field is displayed as part of the bibliography
entry, linked to the corresponding URL.  If the \texttt{inlinelinks}
setting is true, however, then the URL is not displayed in the
printed entry, but instead a hyperlink is created, linked to suitable
text within the bibliography entry, such as the citation title.  This
option does not affect the display of eprints, DOI or PubMed fields.  It makes
no sense to specify \texttt{inlinelinks} with \texttt{hrefform=0}, and the
script warns you if you do that, for example by failing to specify one
of the link-style options.  This option is (primarily) useful if
you're preparing a version of a document which will be read on-screen;
the point of it is that the resulting bibliography is substantially
more compact than it would otherwise be.

The support for all the above behaviours is always included in the
output file.  The options instead control only whether the various
behaviours are enabled or disabled, and if you need to alter these,
you may do so by editing the generated |.bst| file and adjusting
values in the |{init.urlbst.variables}| function, where indicated.

The generated references have URLs inside |\url{...}|.  The best
way to format this this is with the \package{url} package
(see~\cite{texfaq} for pointers), but as a poor alternative, you can
try |\newcommand{\url}[1]{\texttt{#1}}|.  The \package{hyperref}
package automatically processes |\url{...}| in the correct way to
include a hyperlink, and if you have selected \package{hyperref}
output, then nothing more need be done.  If you selected Hyper\TeX\
output, however, then the script encloses the |\url| command in an
appropriate Hyper\TeX\ special.

When the style file generates a link for DOIs, it does so by
prepending the string \texttt{https://doi.org/} to the DOI.  This is
generally reasonable, but some DOIs have characters in them which are
illegal in URLs, with the result that the resulting
\texttt{doi.org} URL doesn't work.  The only real way of resolving
this is to write a URL-encoding function in the style-file
implementation language, but while that would doubtless be feasible in
principle, it would be hard and very, very, ugly.  The only advice I
can offer in this case is to rely on the fact that the DOI will still
appear in the typeset bibliography, and that users who would want to
take advantage of the DOI will frequently (or usually?) know how to
resolve the DOI when then need to.  As a workaround, you could include
a URL-encoded DOI URL in the \btfield{url} field of the entry (thanks
to Eric Chamberland for this suggestion).  A slightly more generic
approach is to apply the setting \texttt{doiform=1}, which will
generate DOIs wrapped in the macro |\doi{...}|.  This allows you to
supply a generic |\doi| macro to format them as you desire.

The \btfield{doi} field may include the \texttt{https://doi.org/}, or
it may omit it; the stylefile adds or removes the prefix as
appropriate.  Note that this parsing is rudimentary: it won't detect
any of the variants of this prefix, meaning \texttt{http:} or
\texttt{dx.doi.org}, both of which are now deprecated.
% Note that this string is configured in configure.ac, but changing it
% there wouldn't change it here (I could, but... Makefile)

The \ub\ script works by spotting patterns and characteristic function
names in the input |.bst| file.  It works as-is in the case of the
four standard \BibTeX\ style files |plain.bst|, |unsrt.bst|,
|alpha.bst| and |abbrv.bst|.  It also works straightforwardly for
many other style files -- since many of these are derived from, or at
least closely inspired by, the standard ones -- but it does not
pretend that it can do so for all of them.  In some cases, such as the
style files for the \package{refer} or \package{koma-script} packages,
the style files are not intended to be used for formatting; others are
sufficiently different from the standard files that a meaningful edit
becomes impossible.  For the large remainder, however, the result of
this script should need only relatively minor edits before being
perfectly usable.

\section{New \texttt{.bib} entry and field types}

The new entry type \btfield{webpage} has required fields
\btfield{title} and \btfield{url}, and optional fields
\btfield{author}, \btfield{editor}, \btfield{note}, \btfield{year},
\btfield{month} and \btfield{lastchecked}.  The \btfield{url} and
\btfield{lastchecked} fields are new, and are
valid in other entry types as well: the first, obviously, is the URL
which is being cited, or which is being quoted as an auxiliary source
for an article perhaps; the second is the date when you last checked
that the URL was there, in the state you quoted it; this is necessary
since some people, heedless of the archival importance of preserving
the validity of URLs, indulge in the vicious practice of reorganising
web pages and destroying links.  For the case of the \btfield{webpage} entry
type, the \btfield{editor} field should be used for the `maintainer'
of a web page.

For example, in Figure~\ref{f:ex} we illustrate two potential |.bib|
file entries.  The \texttt{@webpage} entry type is the new type
provided by this package, and provides reference information for a
webpage; it includes the new \texttt{url} and \texttt{lastchecked}
fields.  There is also an example of the standard \texttt{@book} entry
type, which now includes the \texttt{url} and \texttt{lastchecked}
fields as well.  The difference between the two references is that in
the \texttt{@book} case it is the book being cited, so that the
\texttt{url} provides extra information; in the \texttt{@webpage} case
it is the page itself which is of interest.  You use the new |eprint|,
|doi| and |pubmed| fields similarly, if the bibliographic item in
question has an e-print, DOI or PubMed reference.
\begin{figure}
\begin{verbatim}
@Manual{w3chome,
  url =          {http://www.w3.org},
  title =        {The World Wide Web Consortium},
  year =         2009,
  lastchecked =  {26 August 2009}}

@Book{schutz,
  author =      {Bernard Schutz},
  title =       {Gravity from the GroundUp},
  publisher =   {Cambridge University Press},
  year =        {2003},
  url =         {http://www.gravityfromthegroundup.org/},
  lastchecked = {2008 June 16}}
\end{verbatim}
\caption{\label{f:ex}The new \texttt{@webpage} entry type, and the \texttt{url}
  field in action}
\end{figure}

How do you use this in a document?  To use the the
\texttt{alphaurl.bst} style -- which is a pre-converted version of the
standard \texttt{alpha.bst} style, included in the \texttt{urlbst}
distribution -- you simply make sure that \texttt{alphaurl.bst} is in
your BibTeX search path (use the command \texttt{kpsepath bst} to find
this path and \texttt{kpsewhich alphaurl.bst} to confirm that BibTeX
can find it) and add |\bibliographystyle{alphaurl}| to your \LaTeX\ document.

\section{Sources}

There are various sources which suggest how to format references to
web pages.  I have followed none specifically, but fortunately they do
not appear to materially disagree.

ISO-690~\cite{url:iso690} is a formal standard for this stuff.  Walker
and Taylor's \emph{Columbia Guide to Online Style}~\cite{walker06}
provides extensive coverage (but is only available on dead trees).
There are two style guides associated with the APA, namely
the published APA style
guide~\cite{apastyle} (a paper-only publication, so should be
ignored by all, if there's any justice in the world), and what appears
to be the 1998 web-citation proposal for that~\cite{url:weapas}, which
also includes some useful links.
The TeX FAQ~\cite{texfaq} has both practical advice and pointers to other sources.%
\footnote{Emory University's Goizueta Business Library once had a collection of
useful links on this topic, but they've whimsically changed the URL at least twice
since I first distributed \ub, and I've got fed up fixing their broken link.}

\section{Hints}

If you use Emacs' \BibTeX\ mode, you can insert the following in your
|.emacs| file to add knowledge of the new \btfield{webpage} entry:
\begin{verbatim}
(defun my-bibtex-hook ()
  (setq bibtex-mode-user-optional-fields '("location" "issn")) ; e.g.
  (setq bibtex-entry-field-alist
        (cons
         '("Webpage"
           ((("url" "The URL of the page")
             ("title" "The title of the resource"))
            (("author" "The author of the webpage")
             ("editor" "The editor/maintainer of the webpage")
             ("year" "Year of publication of the page")
             ("month" "Month of publication of the page")
             ("lastchecked" "Date when you last verified the page was there")
             ("note" "Remarks to be put at the end of the entry"))))
         bibtex-entry-field-alist)))
(add-hook 'bibtex-mode-hook 'my-bibtex-hook)
\end{verbatim}
After that, you can add a \btfield{webpage} entry by typing |C-c C-b webpage|
(or |M-x bibtex-entry|).

It is a \emph{very} good idea to use the \package{url} package: it deals with
the problem of line-breaking long URLs, and with the problem that
\BibTeX{} creates, of occasionally inserting \%-signs into URLs in
generated bibliographies.

See also the URL entry in the UK \TeX\ FAQ~\cite{texfaq}, and
references therein.

\section{Acknowledgements, and release notes}

%%% include:release-notes.tex


Thanks are due to many people for suggestions and requests:
to Jason Eisner for suggesting the |--inlinelinks| option;
to ‘ijvm’ for code contributions in the |urlbst| script;
to Paweł Widera for the suggestion to use |\path| when formatting DOIs;
to Michael Giffin for the suggestion to include PubMed URLs;
to Katrin Leinweber for the pull request which fixed the format of DOI
references.

\begin{description}
\item[\textbf{0.9.1, 2023 January 30}]\relax 

  Added code to spot and wrangle the |https://doi.org/| URL
  prefix – the code now behaves correctly whether this is present or not.


\item[\textbf{0.9, 2022 December 1}]\relax 
\begin{itemize}
  \item Changed repository location to heptapod\footnote{\url{https://heptapod.host/nxg/urlbst}}
  (when Bitbucket dropped support for Mercurial).
  The issue links below, pointing to Bitbucket, will therefore no
  longer work.
  \item Refactoring of the mechanism for configuring the generated
  |.bst| file, specifically adding the
  |--setting| option.
  \item Added the |doiform| setting to generate DOIs wrapped
  in |\doi{...}|.
\end{itemize}


\item[0.8, 2019 July 1]\relax 
\begin{itemize}
\item The presence of a preexisting |format.doi|,
|format.eprint| or |format.pubmed| function is
now detected, and warned about.  The resulting |.bst| file
might still require some manual editing.
Resolves issue 8\footnote{\url{https://bitbucket.org/nxg/urlbst/issue/8}}.
\item Clarified licences (I hope).
\item Adjust format of DOI resolver.
Resolves issue 11\footnote{\url{https://bitbucket.org/nxg/urlbst/issue/11}},
thanks to
code contributed by Katrin Leinweber\footnote{\url{https://bitbucket.org/nxg/urlbst/pull-requests/1/}}.
\end{itemize}


\item[0.7, 2011 July 20]\relax 
Add |--nodoi|, |--noeprints| and
|--nopubmed| options (which defaulted on, and couldn't
otherwise be turned off)

\item[0.7b1, 2011 March 17]\relax 
Allow parameterisation of literal strings, with option |--literal|.

\item[0.6-5, 2011 March 8]\relax 
Adjust support for inline links (should now work for arXiv, DOI and Pubmed)

\item[0.6-4, 2009 April 28]\relax 
Work around BibTeX linebreaking bug (thanks to Andras Salamon for the bug report).

\item[0.6-3, 2009 April 19]\relax 
Fix inline link generation (thanks to Eric Chamberland for the bug report).

\item[0.6-2, 2008 November 17]\relax 
We now turn on inlinelinks when we spot format.vol.num.pages,
which means we include links for those styles which don't include a
title in the citation (common for articles in physical science styles,
such as aip.sty).

\item[0.6-1, 2008 June 16]\relax 
Fixed some broken links to the various citation standards
(I think in this context this should probably \emph{not} be happening, yes?).
The distributed |*url.bst| no longer have the
|--inlinelinks| option turned on by default.

\item[\textbf{0.6, 2007 March 26}]\relax 
\begin{itemize}
\item Added the option |--inlinelinks|, which adds inline hyperlinks
to any bibliography entries which have URLs, but does so inline, rather
than printing the URL explicitly in the bibliography.  This is (primarily)
useful if you're preparing a version of a document which will be read
on-screen.  Thanks to Jason Eisner for the suggestion, and much testing.

\item Incorporate hyperref bugfixes from Paweł Widera.

\item Further reworkings of the inlinelinks support, so that it's now
fired by a |format.title| (or |format.btitle|) line, with a fallback in
|fin.entry|.  This should be more robust, and allows me to delete some
of the previous version's gymnastics.

\item Reworked |inlinelinks| support; should now be more
robust.  Incorporate hyperref bugfixes from Paweł Widera.

\item Added the option |inlinelinks|, which adds inline hyperlinks
to any bibliography entries which have URLs, but does so inline, rather
than printing the URL explicitly in the bibliography.  This is (only)
useful if you're preparing a version of a document which will be read
on-screen.
\end{itemize}


\item[0.5.2, 2006 September 6]\relax 
Another set of documentation-only changes, hopefully clarifying
installation.

\item[0.5.1, 2006 January 10]\relax 
No functionality changes.  Documentation and webpage changes only,
hopefully clarifying usage and configuration

\item[\textbf{0.5, 2005 June 3}]\relax 
Added support for Digital Object Identifiers (DOI) fields in
bibliographies.

\item[0.4-1, 2005 April 12]\relax 
Documentation improvements -- there are now examples in the help text!

\item[\textbf{0.4, 2004 December 1}]\relax 
Bug fixes: now compatible with mla.bst and friends.
Now uses |./configure| (optionally).  Assorted reorganisation.

\item[\textbf{0.3, 2003 June 4}]\relax 
Added |--eprint|, |--hypertex| and |--hyperref| options.

\item[\textbf{0.2, 2002 October 23}]\relax 
The `editor' field is now supported in the webpage entry type.  Basic
documentation added.

\item[\textbf{0.1, 2002 April}]\relax 
Initial version
\end{description}

\bibliography{urlbst}
\bibliographystyle{plainurl}

\end{document}