On this page:
define-cite
author+  date-style
author+  date-square-bracket-style
number-style
bib?
make-bib
in-bib
proceedings-location
journal-location
book-location
booklet-location
misc-location
manual-location
techrpt-location
dissertation-location
book-chapter-location
author-name
authors
org-author-name
other-authors
editor
abbreviate-given-names
url-rendering
9.3.0.9

3 Bibliographies🔗ℹ

 (require scriblib/autobib) package: scribble-lib

This library provides support for bibliography management in a Scribble document. The define-cite form is used to bind procedures that create in-line citations and generate the bibliography in the document.

Individual bibliography entries are created with the make-bib function. See below for an example.

#lang scribble/base
 
@(require scriblib/autobib)
 
@(define-cite ~cite citet generate-bibliography)
 
@(define plt-tr1
   (make-bib
    #:title    "Reference: Racket"
    #:author   (authors "Matthew Flatt" "PLT")
    #:date     "2010"
    #:location (techrpt-location #:institution "PLT Inc."
                                 #:number "PLT-TR-2010-1")
    #:url      "http://racket-lang.org/tr1/"))
 
Racket is fun@~cite[plt-tr1].
 
@(generate-bibliography)

For citations that reference a page number or section, the in-bib function can be used. For example, the following snippet:

Racket has a contract library.@~cite[(in-bib plt-tr1 ", §8")]

includes a citation to section 8 of the Racket reference.

Changed in version 1.61 of package scribble-lib: Added fields and location types for better bibtex support.
Changed in version 1.68: Improved bibliography layout, added support for multi-paragraph notes and extended support for structured content in bibliography fields.

syntax

(define-cite ~cite-id citet-id generate-bibliography-id
             option ...)
 
option = #:style style-expr
  | #:disambiguate disambiguator-expr
  | #:spaces spaces-expr
  | #:render-date-in-bib render-date-expr
  | #:render-date-in-cite render-date-expr
  | #:date<? date-compare-expr
  | #:date=? date-compare-expr
  | #:cite-author cite-author-id
  | #:cite-year cite-year-id
 
  style-expr : (or/c number-style author+date-style author+date-square-bracket-style)
  spaces-expr : number?
  disambiguator-expr : (or/c #f (-> exact-nonnegative-integer? element?))
  render-date-expr : (or/c #f (-> date? element?))
  date-compare-expr : (or/c #f (-> date? date? boolean?))
Binds ~cite-id, citet-id, generate-bibliography-id, (optionally) cite-author-id, and (optionally) cite-year-id which share state to accumulate and render citations.

The function bound to ~cite-id produces a citation referring to one or more bibliography entries with a preceding non-breaking space, by default sorting the entries to match the bibliography order. It has the contract

(->* (bib?) (#:sort? any/c) #:rest (listof bib?) element?)

The function bound to citet-id generates an element suitable for use as a noun—referring to a document or its author—for one or more bibliography entries which have the same authors. It has the contract

(->* (bib?) () #:rest (listof bib?) element?)

The function bound to generate-bibliography-id generates the section for the bibliography, with a title as per the #:sec-title argument (defaults to "Bibliography") and a tag as per the #:tag argument (defaults to "doc-bibliography"). If the #:sec-title argument is #f instead a string, only the content of the bibliography is created, as a table, and not the enclosing section as a part.

(->* () (#:tag string? #:sec-title (or/c #f string?))
     (or/c part? block?))

If provided, the function bound to cite-author-id generates an element containing the authors of a paper.

(->* (bib?) element?)

If provided, the function bound to cite-year-id generates an element containing the year the paper was published in, or possibly multiple years if multiple papers are provided.

(->* (bib?) #:rest (listof? bib?) element?)

The functions bound to cite-author-id and cite-year-id make it possible to create possessive textual citations.

@citeauthor[scribble-cite]'s (@citeyear[scribble-cite]) autobib
library is pretty nifty.

The optional spaces-expr determines the number of blank lines that appear between citations. The default number of lines is 1.

The optional style-expr determines the way that citations and the bibliography are rendered.Programmer-defined styles may be supported in the future. Currently, two built-in styles are provided, and author+date-style is the default.

For author+date-style, if two citations’ references would render the same (as judged by equal authors and dates that are considered the same) but are different, the optionally provided function from disambiguator-expr is used to add an extra element after the date; the default disambiguator adds a, b, etc. until z, and anything more ambiguous raises an exception. Date comparison is controlled by date-compare-exprs. Dates in citations and dates in the bibliography may be rendered differently, as specified by the optionally given render-date-expr functions.

Changed in version 1.22 of package scribble-lib: Add optional ids for author-name and author-year

Styles for use with define-cite.

With number-style, bibliography entries use hanging indentation in HTML and LaTeX output, with citation numbers aligned in a separate label column. Text output instead separates each number from its entry with a non-breaking space.

The author+date-square-bracket-style definition is the same as author+date-style, except that references to citations are enclosed in [] instead of ().

In LaTeX output, Scribble tries to keep short bibliography entries together, reserving at least five lines before starting an entry. This approximates the previous behavior, which prevented page breaks within individual entries altogether. Longer entries may now span pages.

The \AutobibNeedlines counter controls the minimum number of lines, defaulting to 5. Set it to 0 to disable this constraint. The optional needspace package is required for the constraint to take effect; this behavior is disabled if the package is unavailable, as if the counter were 0.

The \AutobibEntrySetup command, empty by default, allows additional LaTeX settings to be applied locally to each bibliography entry.

To require four lines before each entry and relax line breaking for long annotations, configure these settings using \AtBeginDocument from e.g. a tex-addition that you add to your document’s style:

(tex-addition
  (bytes-append
    #"\\AtBeginDocument{%\n"
    #"  \\AutobibNeedlines=4\\relax\n"
    #"  \\renewcommand{\\AutobibEntrySetup}{%\n"
    #"    \\emergencystretch=2em\n"
    #"    \\tolerance=1000}}%\n"))

procedure

(bib? v) → boolean?

  v : any/c
Returns #t if v is a value produced by make-bib or in-bib, #f otherwise.

procedure

(make-bib #:title title    
  [#:author author    
  #:is-book? is-book?    
  #:location location    
  #:date date    
  #:url url    
  #:accessed accessed    
  #:doi doi    
  #:note note]) → bib?
  title : any/c
  author : any/c = #f
  is-book? : any/c = #f
  location : any/c = #f
  date : (or/c #f date? exact-nonnegative-integer? string?) = #f
  url : (or/c #f string?) = #f
  accessed : any/c = #f
  doi : (or/c #f string?) = #f
  note : any/c = #f
Produces a value that represents a document to cite. Except for is-book?, url, and doi, the arguments are used as content, except that #f means that the information is not supplied. Functions like proceedings-location, author-name, and authors help produce elements in a standard format.

The #:note argument may contain multiple paragraphs, separated by blank lines. The first paragraph follows the bibliographic information; subsequent paragraphs remain within the same bibliography entry.

When both #:doi and #:url are supplied, the DOI takes precedence. A period is inserted after a DOI when followed by a non-empty note. No period is appended directly to a URL.

#:accessed gives the date a #:url (in CSL terms, the date it was accessed), and is only used when #:url is displayed, i.e. when no #:doi is supplied. It is rendered right after the URL, separated from it by a space, as (accessed ...). A period is inserted after it when followed by a non-empty note; a naked URL (no #:accessed) never gets that period.

Dates are internally represented as date values, so a date may be given, or a number or string that represent the year.

An element produced by a function like author-name tracks first, last names, and name suffixes separately, so that names can be ordered and rendered correctly. When a string is provided as an author name, the last non-empty sequence of alphabetic characters or - after a space is treated as the author name, and the rest is treated as the first name.

Changed in version 1.49 of package scribble-lib: Added #:doi.
Changed in version 1.68: Added #:accessed, which replaces the accessed-date support formerly provided by the now-removed webpage-location function: the accessed date is now attached directly to the bib entry instead of being embedded in its #:location, so it renders next to the URL rather than before the date.

procedure

(in-bib orig where) → bib?

  orig : bib?
  where : string?
Extends a bib value so that the rendered citation is suffixed with where, which might be a page or chapter number.

Each of the following *-location functions combines its arguments into a single element?. proceedings-location, book-location, booklet-location, misc-location, and manual-location may legitimately be called by scriblib/bibtex with no useful information at all (e.g. a BibTeX entry that supplies none of the corresponding optional fields): each returns #f when every one of its arguments is either omitted (#f) or supplied as empty content. The rest each have at least one genuinely required argument, so they always have something to report and never return #f.

For a handful of fields across these functions – an edition, an editor, a location, a page range, a series number – #f alone isn’t enough to tell “omitted” from “supplied but empty,” because the field gets wrapped in surrounding text (e.g. an editor’s name becomes “NAME (Ed.)”; an edition becomes “EDITION edition”). Omitting the field (#f, the default) still quietly contributes nothing, but explicitly supplying empty or otherwise trivial content for one of these particular fields (e.g. "") raises a contract violation instead of silently producing an orphaned fragment like “(Ed.)” with no name attached. Each function’s entry below says which of its fields this applies to.

procedure

(proceedings-location [#:editor editor_] 
  location 
  [#:series series 
  #:volume volume 
  #:number number 
  #:pages pages 
  #:organization organization] 
  #:publisher publisher 
  #:address address) 
 → (or/c element? #f)
  editor_ : any/c = #f
  location : any/c
  series : any/c = #f
  volume : any/c = #f
  number : any/c = #f
  pages : (or (list/c any/c any/c) #f) = #f
  organization : any/c = #f
  publisher : #f
  address : #f
Combines the supplied information to produce content suitable for describing a paper’s location within a conference or workshop proceedings. Returns #f when every argument is omitted or empty, except that explicitly-supplied-but-trivial content raises for location, #:editor, #:number, and #:pages specifically, since each of those is wrapped in surrounding text (see above).

Changed in version 1.61 of package scribble-lib: Added fields for bibtex support: editor number organization publisher address.
Changed in version 1.68: Added #f as a possible result.

procedure

(journal-location title    
  [#:volume volume    
  #:number number    
  #:pages pages]) → element?
  title : any/c
  volume : any/c = #f
  number : any/c = #f
  pages : (or (list/c any/c any/c) #f) = #f
Combines the supplied information to produce content suitable for describing a paper’s location within a journal.

procedure

(book-location [#:edition edition    
  #:chapter chapter    
  #:editor editor    
  #:series series    
  #:volume volume    
  #:number number    
  #:pages pages    
  #:publisher publisher    
  #:address address]) → (or/c element? #f)
  edition : any/c = #f
  chapter : any/c = #f
  editor : any/c = #f
  series : any/c = #f
  volume : any/c = #f
  number : any/c = #f
  pages : any/c = #f
  publisher : any/c = #f
  address : any/c = #f
Combines the supplied information to produce content suitable for describing a book’s location. Returns #f when every argument is omitted or empty, except that explicitly-supplied-but-trivial content raises for #:edition, #:editor, #:number, and #:pages specifically (see above).

A numeric chapter, supplied as a number or a string of decimal digits, is prefixed with “chapter”. Other chapter content is used unchanged.

Changed in version 1.61 of package scribble-lib: Added fields for bibtex support: editor chapter series volume number pages address. Made all arguments optional.
Changed in version 1.68: Added #f as a possible result.

procedure

(booklet-location [#:howpublished howpublished 
  #:address address]) 
 → (or/c element? #f)
  howpublished : any/c = #f
  address : any/c = #f
Combines the supplied information to produce content suitable for describing a booklet’s location. Neither argument is wrapped in surrounding text, so returns #f when both are omitted or empty, with no exceptions.

Added in version 1.61 of package scribble-lib.
Changed in version 1.68: Added #f as a possible result.

procedure

(misc-location [#:howpublished howpublished])

 → (or/c element? #f)
  howpublished : any/c = #f
Combines the supplied information to produce content suitable for describing a bibtex misc entry’s location. Its one argument isn’t wrapped in surrounding text, so returns #f when it’s omitted or empty, with no exception.

Added in version 1.61 of package scribble-lib.
Changed in version 1.68: Added #f as a possible result.

procedure

(manual-location [#:organization organization 
  #:edition edition]) 
 → (or/c element? #f)
  organization : any/c = #f
  edition : any/c = #f
Combines the supplied information to produce content suitable for describing a manual’s location. Returns #f when both arguments are omitted or empty, except that explicitly-supplied-but- trivial content raises for #:edition specifically (see above).

Added in version 1.61 of package scribble-lib.
Changed in version 1.68: Added #f as a possible result.

procedure

(techrpt-location #:institution institution    
  [#:type type    
  #:number number    
  #:address address]) → element?
  institution : any/c
  type : any/c = #f
  number : any/c = #f
  address : any/c = #f
Combines the supplied information to produce content suitable for describing a technical report’s location.

Changed in version 1.61 of package scribble-lib: Added fields for bibtex support: type address.

procedure

(dissertation-location #:institution institution    
  [#:degree degree    
  #:type type    
  #:address address]) → element?
  institution : any/c
  degree : any/c = "PhD"
  type : any/c = #f
  address : any/c = #f
Combines the supplied information to produce content suitable for describing a dissertation.

Changed in version 1.61 of package scribble-lib: Added fields for bibtex support: type address.

procedure

(book-chapter-location title    
  [#:edition edition    
  #:chapter chapter    
  #:editor editor    
  #:series series    
  #:volume volume    
  #:number number    
  #:pages pages    
  #:publisher publisher    
  #:address address]) → element?
  title : any/c
  edition : any/c = #f
  chapter : any/c = #f
  editor : any/c = #f
  series : any/c = #f
  volume : any/c = #f
  number : any/c = #f
  pages : any/c = #f
  publisher : any/c = #f
  address : any/c = #f
Combines the supplied information to produce content suitable for describing a paper’s location within a chapter or part of a book or collection of books.

The chapter argument is formatted as by book-location.

Changed in version 1.61 of package scribble-lib: Added fields for bibtex support: editor chapter number address.

procedure

(author-name first last [#:suffix suffix]) → element?

  first : any/c
  last : any/c
  suffix : any/c = #f
Combines elements to generate an element that is suitable for describing an author’s name, especially where the last name is not merely a sequence of ASCII alphabet letters or where the name has a suffix (such as “Jr.”).

procedure

(authors name names ...) → element?

  name : content?
  names : content?
Combines multiple author elements into one, so that it is rendered and alphabetized appropriately. Any of name or names that are strings are parsed in the same way as by make-bib.

procedure

(org-author-name name) → element?

  name : (or/c element? string?)
Converts an element for an organization name to one suitable for use as a bib-value author.

procedure

(other-authors) → element?

Generates an element that is suitable for use as a “others” author. When combined with another author element via authors, the one created by other-authors renders as “et al.”

procedure

(editor name) → element?

  name : (or/c element? string?)
Takes an author-name element and create one that represents the editor of a collection. If a name is a string, it is parsed in the same way as by make-bib.

Raises a contract violation if name is empty or otherwise trivial content (e.g. ""), rather than silently producing a name-less “(Ed.)” credit.

Changed in version 1.68 of package scribble-lib: Raises on empty or trivial content instead of silently producing a bogus, name-less credit.

parameter

(abbreviate-given-names) → any/c

(abbreviate-given-names abbreviate?) → void?
  abbreviate? : any/c
Shortens given names in calls to author and make-bib to just the first initial when the parameter value is not #f. Otherwise, does not change the author names.

Defaults to #f.

Added in version 1.5 of package scribble-lib.

parameter

(url-rendering) → (-> string? any)

(url-rendering rendering-function) → void?
  rendering-function : (-> string? any)
Accepts a URL as a string and renders it for use in a bibliography entry.

Defaults to (λ (url) (link url (make-element 'url (list url)))).

Added in version 1.39 of package scribble-lib.