GNU TeXmacsUser manualReferenceAboutEnglish
The built-in functions

The BibTEX style language has a few built-in functions which operate on LaTeX strings. The TeXmacs styles need the same operations on TeXmacs trees, since the field values have already been converted (see parsing). They are implemented in C++ in

Plugins/Bibtex/bibtex_functions.cpp

and exported to Scheme by

Scheme/Glue/build-glue-basic.scm

. All of them take Scheme trees, convert them to TeXmacs trees and simplify them with simplify_correct before working, and most return a Scheme tree. The descriptions below are meant for style writers who need to know the exact behaviour; the list of functions is also in writing TeXmacs bibliography styles.

1.Access to fields

(bib-field entry name)
(value of a field)

Returns the value of the field name of a bib-entry, or "" if there is no such field or if entry is not a well formed entry (three children, the last one a document). Field names are compared literally; since the parser lower-cases them, they should be given in lower case.

(bib-empty? entry name)
(test for a missing field)

True if bib-field returns "". A field whose value is a non-atomic tree without text (for instance an empty concat) is not considered empty; use bib-null? from

bibtex/bib-utils.scm

for such tests.

2.Text functions

(bib-purify t)
(analogue of purify$)

Returns the concatenated text of t: atomic strings are kept, with contributes its body, keepcase, concat and document their children, and every other tag is dropped together with its contents. Unlike purify$, punctuation is not removed and no character is replaced by a space. Used to build sort keys.

(bib-text-length t)
(analogue of text.length$)

Meant to return the length of the text of t. For an atomic tree it returns the number of bytes, so that a Cork entity such as <alpha> counts as seven characters. For any compound tree it currently returns 0 (see the pitfalls). The shipped styles use it to choose between a space and a non-breaking space after short volume and number fields.

(bib-prefix t n)
(analogue of text.prefix$)

Returns, as a string, the first n bytes of the text of t, collected from atomic strings and the children of concat and document. The special value "others" (the BibTEX convention for “and others”) gives "+". Bytes, not characters, are counted, so the result may end in the middle of a Cork entity, and the body of a with is ignored. Used by the alpha style to build labels.

(bib-abbreviate t dot sep)
(abbreviate first names)

Replaces every word of the text of t by its first character followed by dot, and separates the abbreviated words by sep. A Cork entity counts as one character. In hyphenated words, every part is abbreviated and the hyphens are kept, so Jean-Pierre becomes J.-P. with dot equal to ".". The result is a concat. The styles call it as (bib-abbreviate first "." '(nbsp)).

(bib-add-period t)
(analogue of add.period$)

Looks at the last non-space character of the last non-empty atomic string of t. If it is a comma or a semicolon, it is replaced by a period; if it is ., ! or ?, nothing happens; otherwise a period is appended. Replacing commas and semicolons is a difference with BibTEX, which only appends.

3.Case changes

Case changes respect the keepcase tags produced by the parser from BibTEX brace groups, and never touch verbatim, slink, math, typewriter text (font-family tt) and text with a math-font. They use the Unicode aware functions uni_locase_all, uni_upcase_all, uni_locase_first and uni_upcase_first, so accented Cork characters are handled.

(bib-locase t), (bib-upcase t)

Change the case of all text, except inside keepcase. The keepcase tags themselves are removed (their contents are kept as they are), so the result can be displayed directly. This is the analogue of change.case$ with "l" and "u".

(bib-locase-first t), (bib-upcase-first t)

Change the case of the first character of the first non-blank atomic string (for with, of its body). Since keepcase is not skipped specially here, the first character inside a keepcase is changed as well.

(bib-default-preserve-case t)

Only simplifies the tree; keepcase tags are kept.

(bib-default-upcase-first t)

Despite its name, changes no case: it removes the keepcase tags (keeping their contents) and is what bib-format-field applies to every field it formats.

The analogue of change.case$ with "t" (title case conversion: lower case except the first letter) is obtained in the styles by combining these functions, for instance bib-format-field-Locase in

bibtex/bib-utils.scm

is (bib-upcase-first (bib-locase field)).

4.Functions which are not exported

The header also declares bib_preamble, bib_strings_dict, bib_subst_vars, bib_entries, bib_parse_fields and bib_field_pages, which are used by the parser and by generate_bibliography but have no glue. In particular the contents of @preamble items are not available to the Scheme styles. The C++ function bib_num_names (the analogue of num.names$) is defined but not used anywhere; styles count the children of bib-names instead.

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