| grefer(1) | User Commands | grefer(1) |
grefer - process bibliographic references for groff
grefer |
[-bCenPRS] [-a n] [-B field.macro] [-c fields] [-f n] [-i fields] [-k field] [-l range-expression] [-p database-file] [-s fields] [-t n] [file ...] |
grefer |
--help |
grefer |
-v |
grefer |
--version |
The GNU implementation of refer is part of the groff(1) document formatting system. grefer is a gtroff(1) preprocessor that prepares bibliographic citations by looking up keywords specified in a roff(7) input document, obviating the need to type such annotations, and permitting the citation style in formatted output to be altered independently and systematically. It copies the contents of each file to the standard output stream, looking up each citation between lines starting with .[ and .] and replacing it with a bibliographic reference. GNU refer furthermore interprets lines between those starting with .R1 and .R2 as instructions directing how citations are to be processed. grefer interprets and generates roff lf requests so that file names and line numbers in messages produced by commands that read its output correctly describe the source document. Normally, grefer is not executed directly by the user, but invoked by specifying the -R option to groff(1). If no file operands are present, or if file is “-”, grefer reads the standard input stream.
A citation identifies a work by reference to a bibliographic record detailing it. Select a work from a database of records by listing keywords that uniquely identify its entry. Alternatively, a document can specify a record for the work at the point its citation occurs. A document can use either or both strategies as desired.
For each citation, grefer produces a mark in the text, like a superscripted footnote number or “[Lesk1978a]”. A mark consists of a label between brackets. The mark can be separated from surrounding text and from other labels in various ways. grefer produces roff language requests usable by a document or a macro package such as me, mm, mom, or ms to produce a formatted reference for each citation. A citation's reference can be output immediately after it occurs (as with footnotes), or references may accumulate, with corresponding output appearing later in the document (as with endnotes). When references accumulate, multiple citations of the same reference produce a single formatted entry.
Interpretation of lines between .R1 and .R2 tokens as preprocessor commands is a GNU refer extension. Documents employing this feature can still be processed by AT&T refer by adding the lines
.de R1 .ig R2 ..
A bibliographic record describes a referenced work in sufficient detail that it may be cited to accepted standards of scholarly and professional clarity. The record format permits annotation and extension that a document may use or ignore. A record is a plain text sequence of fields, one per line, each consisting of a percent sign %, an alphanumeric character classifying it, one space, and its contents. If a field's contents are empty, the field is ignored.
Frequently, such records are organized into a bibliographic
database, with each entry separated by blank lines or file boundaries.
This practice relieves documents of the need to maintain bibliographic data
themselves. The programs glookbib(1) and lkbib(1) consult a
bibliographic database, and gindxbib(1) indexes one to speed
retrieval from it, reducing document processing time. Use of these tools is
optional.
The conventional uses of the bibliographic field entries are as follows. Within a record, fields other than %A and %E replace previous occurrences thereof. The ordering of multiple %A and %E fields is significant.
If the obsolescent “accent strings” feature of the ms or me macro packages is used, such strings should follow the character to be accented; an ms document must call the AM macro before using them. Do not quote accent strings: use one \ rather than two. See groff_char(7) for a modern approach to the problem of diacritics.
Citations have a characteristic format.
.[opening-text flags keyword ... field ... .]closing-text
opening-text, closing-text, and flags are
optional, and only one keyword or field need be specified. If
keywords are present, grefer searches the bibliographic database(s)
for a unique reference matching them. Multiple matches are an error; add
more keywords to disambiguate the reference. In the absence of keywords,
fields constitute the bibliographic record. Otherwise, fields
specify additional data to replace or supplement those in the reference.
When references are accumulating and keywords are present, specify
additional fields at most on the first citation of a particular
reference; they apply to all further citations thereof.
opening-text and closing-text are roff input
used to bracket the label, overriding the bracket-label command.
Leading and trailing spaces are significant. If either of these is
non-empty, the corresponding argument to the bracket-label command is
not used; alter this behavior with the [ and ] flags.
flags is a list of non-alphanumeric characters each of which modifies the treatment of the particular citation. AT&T refer ignores them since they are non-alphanumeric. They direct GNU refer as follows.
An advantage of the [ and ] flags over use of opening-text and closing-text is that you can update the document's bracketing style in one place using the bracket-label command. Another is that sorting and merging of citations is not necessarily inhibited if the flags are used.
grefer appends any label resulting from a citation to the roff input line preceding the .[ token. If there is no such line, grefer issues a warning diagnostic.
There is no special notation for citing multiple references in series. Use a sequence of citations, one for each reference, with nothing between them. grefer attaches all of their labels to the line preceding the first. These labels may be sorted or merged. See the description of the <> label expression, and of the sort-adjacent-labels and abbreviate-label-ranges commands. A label is not merged if its citation has a non-empty opening-text or closing-text. However, the labels for two adjacent citations, the former using the ] flag and without any closing-text, and the latter using the [ flag and without any opening-text, may be sorted and merged even if the former's opening-text or the latter's closing-text is non-empty. (To prevent these operations, use the dummy character escape sequence \& as the former's closing-text.)
Commands are contained between lines starting with .R1 and .R2. The -R option prevents recognition of these lines. When grefer encounters a .R1 line, it flushes any accumulated references. Neither .R1 nor .R2 lines, nor anything between them, is output.
Commands are separated by newlines or semicolons. A number sign (#) introduces a comment that extends to the end of the line, but does not conceal the newline. Each command is broken up into words. Words are separated by spaces or tabs. A word that begins with a (neutral) double quote (") extends to the next double quote that is not followed by another double quote. If there is no such double quote, the word extends to the end of the line. Pairs of double quotes in a word beginning with a double quote collapse to one double quote. Neither a number sign nor a semicolon is recognized inside double quotes. A line can be continued by ending it with a backslash “\”; this works everywhere except after a number sign.
Each command name that is marked with * has an associated negative command no-name that undoes the effect of name. For example, the no-sort command specifies that references should not be sorted. The negative commands take no arguments.
In the following description each argument must be a single word; field is used for a single upper or lower case letter naming a field; fields is used for a sequence of such letters; m and n are used for a non-negative numbers; string is used for an arbitrary string; file is used for the name of a file.
.[ $LIST$ .]
If string is omitted, it will default to AP; if field is also omitted it will default to X. Only one field can be an annotation.
bracket-label \*([. \*(.] ", "
date-as-label D.+yD.y%a*D.-y
et-al " et al" 2 3
join-authors " and " ", " ", and "
Label expressions can be evaluated both normally and tentatively. The result of normal evaluation is used for output. The result of tentative evaluation, called the tentative label, is used to gather the information that normal evaluation needs to disambiguate the label. Label expressions specified by the date-as-label and short-label commands are not evaluated tentatively. Normal and tentative evaluation are the same for all types of expression other than @, *, and % expressions. The description below applies to normal evaluation, except where otherwise specified.
The above expressions are listed in order of precedence (highest first); & and | have the same precedence.
Each reference starts with a call to the macro ]-. The string [F will be defined to be the label for this reference, unless the no-label-in-reference command has been given. There then follows a series of string definitions, one for each field: string [X corresponds to field X. The register [P is set to 1 if the P field contains a range of pages. The [T, [A and [O registers are set to 1 according as the T, A and O fields end with any of .?! (an end-of-sentence character). The [E register will be set to 1 if the [E string contains more than one name. The reference is followed by a call to the ][ macro. The first argument to this macro gives a number representing the type of the reference. If a reference contains a J field, it will be classified as type 1, otherwise if it contains a B field, it will be type 3, otherwise if it contains a G or R field it will be type 4, otherwise if it contains an I field it will be type 2, otherwise it will be type 0. The second argument is a symbolic name for the type: other, journal-article, book, article-in-book, or tech-report. Groups of references that have been accumulated or are produced by the bibliography command are preceded by a call to the ]< macro and followed by a call to the ]> macro.
--help displays a usage message, while -v and --version show version information; all exit afterward.
Other options are equivalent to grefer commands.
The B option has command equivalents with the addition that the file names specified on the command line are processed as if they were arguments to the bibliography command instead of in the normal way.
grefer exits with status 0 on successful operation, status 2 if the program cannot interpret its command-line arguments, and status 1 if it encounters an error during operation.
grefer uses temporary files. See the groff(1) man page for details of where such files are created.
In label expressions, <> expressions are ignored inside .char expressions.
We can illustrate the operation of grefer with a sample bibliographic database containing one entry and a simple roff document to cite that entry.
$ cat > my-db-file %A Daniel P.\& Friedman %A Matthias Felleisen %C Cambridge, Massachusetts %D 1996 %I The MIT Press %T The Little Schemer, Fourth Edition $ refer -p my-db-file Read the book .[ friedman .] on your summer vacation. <Control+D> .lf 1 - Read the book\*([.1\*(.] .ds [F 1 .]- .ds [A Daniel P. Friedman and Matthias Felleisen .ds [C Cambridge, Massachusetts .ds [D 1996 .ds [I The MIT Press .ds [T The Little Schemer, Fourth Edition .nr [T 0 .nr [A 0 .][ 2 book .lf 5 - on your summer vacation.
The foregoing shows us that grefer (a) produces a label “1”; (b) brackets that label with interpolations of the “[.” and “.]” strings; (c) calls a macro “]-”; (d) defines strings and registers containing the label and bibliographic data for the reference; (e) calls a macro “][”; and (f) uses the lf request to restore the line numbers of the input. As noted in subsection “Macro interface” above, it is the document's responsibility to employ and format the information usefully. Let us see how we might turn groff_ms(7) to this task.
$
REFER=my-db-file groff -R -ms
.LP
Read the book
.[
friedman
.]
on your summer vacation.
Commentary is available.\*{*\*}
.FS \*{*\*}
Space reserved for penetrating insight.
.FE
ms's automatic footnote numbering mechanism is not aware of grefer's label numbering, so we have manually specified a (superscripted) symbolic footnote for our non-bibliographic aside.
“Refer — A Bibliography System”, by Bill Tuthill, 1983, Computing Services, University of California, Berkeley.
“Some Applications of Inverted Indexes on the Unix System”, by M. E. Lesk, 1978, AT&T Bell Laboratories Computing Science Technical Report No. 69.
gindxbib(1), glookbib(1), lkbib(1)
| 2026-03-14 | groff 1.24.1 |