![]() |
The style engine and the shipped styles | ![]() |
An internal style tm-name is the Scheme module (bibtex name) in bibtex/name.scm. generate_bibliography loads it by evaluating (use-modules (bibtex name)) and calls (bib-process prefix name entries); with the database tool, bib-compile does the same. The flow inside bib-process (
bibtex/bib-utils.scm
) is described in the database chapter: set the globals bib-current-prefix and bib-style, run bib-preprocessing, sort with bib-sorted-entries, format each entry with bib-format-entry and return a simplified bib-list.
(bib-define-style name fallback) is a macro which declares the Scheme mode bib-name%, with predicate bib-name?, defined by (bib-mode? name) and, if fallback differs from name, implying the mode of the fallback. bib-mode? is true when its argument is the current bib-style or the global bib-default-style. The macro also sets bib-default-style to fallback, as a side effect of loading the module.
A style file then redefines functions of
plain.scm
with a (:mode bib-name?) clause. Since bib-style is set by bib-process, several style modules can be loaded at the same time: each override only applies while its style is active, and the most specific mode wins as for all Scheme overloading (see editing modes on the Scheme side). The functions of
plain.scm
themselves are defined without a mode, so they are the defaults of every style.
(bib-with-style style f args …) calls a function with another style temporarily active; the alpha style uses it to append the plain sort key to its own.
The functions which a style may override, all defined in
plain.scm
, are:
Called once with the list of entries before sorting; the default does nothing.
A string used by the stable sort of bib-sorted-entries, compared with tmstring-before?. The default is the upper-cased names (authors, or editors for books and proceedings, or the key if there are none), the year and the purified title. bib-sorted-entries itself can be overridden to change the order completely (unsrt, ieeetr and elsart-num keep the citation order).
Dispatches on the entry type to bib-format-article, bib-format-book, …, bib-format-unpublished; the type conference is an alias of inproceedings, and unknown types are formatted by bib-format-misc. Each of these returns a (concat (bibitem* label) (label …) …) paragraph.
The label: the running number n by default, the key for abstract, the computed label for alpha.
bib-format-names, bib-format-name, bib-format-first-name, bib-last-name-sep, bib-format-author, bib-format-editor.
bib-format-date, bib-format-pages, bib-format-chapter-pages, bib-format-vol-num-pages, bib-format-bvolume, bib-format-number-series, bib-format-tr-number, bib-format-in-ed-booktitle.
The output helpers of
bib-utils.scm
(bib-new-block, bib-new-sentence, bib-new-list, bib-format-field and its variants, bib-emphasize, bib-translate) are documented in writing TeXmacs bibliography styles. Two details matter when writing styles: bib-null? treats "", the empty list, the empty symbol and a with around any of these as empty, and the helpers silently drop empty pieces; and bib-translate produces a localize tag, so words such as “in” and “edited by” follow the language of the document when it is typeset, not when the bibliography is generated.
All shipped styles use plain as their fallback.
The defaults, modelled on plain.bst: numbered labels, entries sorted by names, year and title.
Only redefines bib-format-first-name, to abbreviate first names with bib-abbreviate.
Only redefines bib-sorted-entries, as the identity: entries appear in the order of the citations (more precisely, in the order returned by bib_entries or the database, which is the citation order followed by cross-referenced entries).
Only redefines bib-format-bibitem: the label is the citation key.
Labels made of name prefixes and the year, as in alpha.bst, see below.
Larger styles which redefine most of the formatting functions to follow the corresponding .bst files. ieeetr and elsart-num also keep the citation order, and ieeetr replaces the helper new-list-rec of
bib-utils.scm
(the comment there says so) to change the separators.
The list returned by bib-standard-styles (tm-plain, tm-abbrv, tm-abstract, tm-acm, tm-alpha, tm-elsart-num, tm-ieeetr, tm-siam, tm-unsrt) must be kept in sync with these files, see the how-to in the database chapter. When bibtex is not installed, generate_bibliography maps the standard BibTEX style names to these styles, and any other name to tm-plain.
bib-preprocessing computes the label of every entry before sorting, with bib-format-label-prefix:
The names are those of the authors, or of the editors for proceedings, or (for books) of the authors or else the editors. With no names, the first three characters of the key are used, or the entry number.
With one name, the label starts with the abbreviated von part followed by the first character of the last name, or, without von part, by the first three characters of the last name.
With two to four names, it is the concatenation of the von initials and the first character of each last name; with five or more, of the first three names followed by +.
The last two characters of the year are appended.
Labels which occur several times get the suffixes a, b, … in the order in which the entries are formatted, that is, after sorting. The sort key is the upper-cased name part of the label (or the label), the year, and the plain sort key.
open-bibliography-inserter (
bibtex/bib-widgets.scm
) opens a dialog which inserts a new bibliography tag, or modifies the first one of the document (style and file). The file may be stored relative to the document or as an absolute path. The dialog shows a preview: it loads the style module, parses the whole .bib file with parse-bib and formats all its entries with bib-process inside a texmacs-output widget. After validation, the bibliography is regenerated with (update-document "bibliography").
bibtex/bib-complete.scm
provides the completions offered when typing the key of a citation. current-bib-file finds the first bibliography tag of the buffer and resolves its file name relative to the buffer (the result is cached per buffer); citekey-list parses that file (again only when its modification time has changed), stores the keys in a prefix tree (
utils/library/ptrees.scm
) and returns the keys which start with the typed text. citekey-completions formats them for the completion mechanism.