GNU TeXmacsUser manualReferenceAboutEnglish
The style engine and the shipped styles

1.The engine

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.

1.1.Style dispatch

(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.

1.2.The protocol of a style

The functions which a style may override, all defined in

plain.scm

, are:

(bib-preprocessing entries)

Called once with the list of entries before sorting; the default does nothing.

(bib-sort-key entry)

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).

(bib-format-entry n entry)

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.

(bib-format-bibitem n entry)

The label: the running number n by default, the key for abstract, the computed label for alpha.

Name formatting

bib-format-names, bib-format-name, bib-format-first-name, bib-last-name-sep, bib-format-author, bib-format-editor.

Parts of entries

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.

2.The shipped styles

All shipped styles use plain as their fallback.

plain

The defaults, modelled on plain.bst: numbered labels, entries sorted by names, year and title.

abbrv

Only redefines bib-format-first-name, to abbreviate first names with bib-abbreviate.

unsrt

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).

abstract

Only redefines bib-format-bibitem: the label is the citation key.

alpha

Labels made of name prefixes and the year, as in alpha.bst, see below.

acm, siam, ieeetr, elsart-num

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.

2.1.Labels of the alpha style

bib-preprocessing computes the label of every entry before sorting, with bib-format-label-prefix:

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.

3.User interface

3.1.Inserting a bibliography

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").

3.2.Completion of citation keys

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.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".