GNU TeXmacsUser manualReferenceAboutEnglish·Français
Writing TeXmacs bibliography styles

1.Introduction

TeXmacs admits support both for BibTEX and a native tool for managing bibliographies. BibTEX styles are denoted by their usual names. TeXmacs styles are prefixed by tm-. For example, the TeXmacs tm-plain style is the replacement for the BibTEX plain style. Equivalents for the following BibTEX styles have been implemented: abbrv, abstract, acm, alpha, elsart-num, ieeetr, plain, siam and unsrt. These styles can therefore be used without installation of BibTEX. When BibTEX is not installed and a document uses a BibTEX style name, then TeXmacs falls back on tm-name, or on tm-plain if no such style exists. (Without the database tool, this fallback is a fixed list in

edit_process.cpp

, which does not contain abstract: a document with the style abstract then uses tm-plain.)

New bibliography styles can be defined by the user. Each style is associated to a unique Scheme file, which should be added to the directory $TEXMACS_PATH/progs/bibtex. Style files are treated as regular Scheme programs. Since the creation of a style file from scratch is a complex task, we recommend you customize existing style files or modules. In the next sections, we will describe the creation of a new style on a simple example and give a detailed lists of available Scheme functions which facilitate the creation of new styles.

The bibliography is generated by generate_bibliography in

edit_process.cpp

, in one of two ways, depending on the preference "database tool" (Tools\(\rightarrow\)Database tool, off by default):

The formatting routines of the styles are described below. See the TeXmacs database and bibliographies, Zotero and the bibliography styles for the underlying machinery.

2.Example of a simple bibliography style

Bibliographic style files are stored in directory $TEXMACS_PATH/progs/bibtex. They have the name of the style followed with extension .scm. For example, example.scm is the file name associated to the style example, which is denoted by tm-example when it is used in a TeXmacs document.

All style files must be declared as a module as follows:

(texmacs-module (bibtex example)
  (:use (bibtex bib-utils) (bibtex plain)))

The module bib-utils contains all useful functions needed to write bibliographic styles; the module of the fall-back style (here plain, see below) should also be used, so that its formatting routines are defined.

All style files must be declared as a bibliographic style as follows:

(bib-define-style "example" "plain")

The first argument to bib-define-style is the name of the current style. The second argument is the name of a fall-back style, plain in our case. If a function is not defined in current style, the function from the fall-back style is used instead. Hence, the following minimalistic style file behaves in an identical way as the plain style:

(texmacs-module (bibtex example)
  (:use (bibtex bib-utils) (bibtex plain)))

(bib-define-style "example" "plain")

Each formatting function defined in the default style can be overloaded in the current style. For example, the function bib-format-date is used to format the date in the plain style. It is redefinable in our example style as follows:

(tm-define (bib-format-date e)
  (:mode bib-example?)
  (bib-format-field e "year"))

All exported functions must be prefixed with bib-. Overloaded functions must be followed with directive (:mode bib-example?), in which example is the name of the current style.

Our complete example file example.scm is as follows:

(texmacs-module (bibtex example)
  (:use (bibtex bib-utils) (bibtex plain)))

(bib-define-style "example" "plain")

(tm-define (bib-format-date e)
  (:mode bib-example?)
  (bib-format-field e "year"))

It behaves in a similar way as the plain style, except that all dates are formatted according to our custom routine.

With the database tool, TeXmacs only uses its internal styles for the names returned by (bib-standard-styles); other style names are passed to BibTEX. (Without the database tool, any style tm-name is loaded directly.) In order to make a new style available in both cases, one therefore also has to extend this list, for instance in the style file itself or in my-init-texmacs.scm:

(tm-define (bib-standard-styles)
  (append (former) (list "tm-example")))

The style module (bibtex example) is loaded automatically when a bibliography with style tm-example is generated.

3.Scheme functions for writing bibliography styles

3.1.Style management

(bib-define-style name default)
(style declaration)

This function declares a style called name (string) with fall-back style default (string). The style is selected by choosing tm-name when adding a bibliography to a document. Whenever a formatting function is not defined in the current style, its definition in the fall-back style is used as replacement. This macro defines a TeXmacs mode whose predicate bib-name? can be used in (:mode …) clauses of tm-define.

(bib-with-style style fun . args)
(local style)

This function applies the function fun to the arguments args as if the current style were style (string), and returns the result.

3.2.Field related routines

(bib-field entry field)
(field data)

This function creates a TeXmacs tree corresponding to the field field (string) of entry entry without format. In some cases, the output is special:

(bib-format-field entry field)
(basic format)

This function creates a TeXmacs tree corresponding to the field field (string) of entry entry, with basic format: the first letter is put in upper case, except inside keep-case blocks. The empty string is returned if the field is empty or absent. The variants bib-format-field-preserve-case and bib-format-field-locase-first respectively preserve the case and put the first letter in lower case.

(bib-format-field-Locase entry field)
(special format)

This function is similar to bib-format-field, but fields are formatted in lower case with an upper case letter at the beginning.

(bib-empty? entry field)
(null-test of a field)

This function returns boolean #t if the field field (string) of entry entry is empty or absent; it returns #f in the other cases.

3.3.Routines for structuring the output

(bib-new-block tm)
(new block)

This function creates a TeXmacs tree consisting of a block containing TeXmacs tree tm, with its first letter in upper case and a period at the end. The variant bib-new-case-preserved-block does not change the case.

(bib-new-list sep ltm)
(separated list)

This function creates a TeXmacs tree which is the concatenation of all the elements of list ltm separated with TeXmacs tree sep.

(bib-new-list-spc ltm)
(blank separated list)

This function is equivalent to the evaluation of (bib-new-list " " ltm).

(bib-new-sentence ltm)
(new sentence)

This function creates a TeXmacs tree corresponding to a sentence containing all the elements of list ltm separated by commas. Empty elements are skipped. The variant bib-new-case-preserved-sentence does not put the first letter in upper case.

3.4.Routines for textual manipulations

(bib-abbreviate name dot spc)
(name abbreviation)

This function creates a TeXmacs tree corresponding to the abbreviation of the name contained in name TeXmacs tree: it retrieves the list of first letters of each word, followed by dot (TeXmacs tree) and separated by spc (TeXmacs tree).

(bib-add-period tm)
(dot)

This function creates a TeXmacs tree with a dot at the end of tm.

(bib-default-preserve-case tm)

(bib-default-upcase-first tm)
(default TeXmacs tree)

These functions simplify the TeXmacs tree tm; the second one also puts its first letter in upper case (except inside keep-case blocks). They are used by the bib-format-field family of routines.

(bib-emphasize tm)
(italic)

This function creates a TeXmacs tree corresponding to the italic version of tm.

(bib-locase tm)
(lower case)

This function creates a TeXmacs tree, which is equal to tm with all letters in lower case, except for those within keep-case blocks.

(bib-prefix tm nbcar)
(beginning of a TeXmacs tree)

This function returns a string containing the first nbcar characters of tm.

(bib-upcase tm)
(upper case)

This function creates a TeXmacs tree, which is equal to tm with all letters in upper case, except for those within keep-case blocks.

(bib-upcase-first tm)
(upper case first letter)

This function creates a TeXmacs tree, which is equal to tm with its first letter in upper case, except inside keep-case blocks. Similarly, (bib-locase-first tm) puts the first letter in lower case.

3.5.Miscellaneous routines

(bib-null? v)
(null-test)

This function returns boolean #t if value v is empty (the empty string, the empty list, or a with whose body is empty); it returns #f in the other cases.

(bib-purify tm)
(flattening of a TeXmacs tree)

This function returns a string made of all letters of the TeXmacs tree tm.

(bib-simplify tm)
(simplification of a TeXmacs tree)

This function returns a TeXmacs tree corresponding to the simplification of TeXmacs tree tm.

(bib-text-length tm)
(length of a TeXmacs tree)

This function returns the length of TeXmacs tree tm.

(bib-translate msg)
(translation)

This function returns the markup (localize msg), which translates the string message msg from English into the language of the document.

(bib-standard-styles)
(internal styles)

This function returns the list of the names (with the tm- prefix) of the styles which are handled by the Scheme implementation.

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