----
title: SUBTEX module – expanding simple TeX commands
SPDX-FileCopyrightText: 2025 Norman Gray <https://nxg.me.uk>
SPDX-License-Identifier: BSD-2-Clause


Most of the (La)TeX commands found in BibTeX files are there to
produce accented characters of one type or another.  When Beastie
parses such a file, it expands an assortment of such commands into the
corresponding Unicode characters.

For example, the field

    author = {Ku\v rt G\"{o}del and Ren{\'e}e R{\o}mer}

will be processed as if it were

    author = {Kuřt Gödel and Renée Rømer}

Note the special case of `{\'e}` and `{\o}` – if this expansion
process results in a single character appearing in braces, then the
braces are discarded.  This corresponds to a related, but distinct,
special case in `bibtex`’s parsing of ‘accented characters’:
`bibtex` treats such sequences, at brace-level one, as being a single
character for the purposes of counting characters and generating
labels.  In Beastie, we support this case at any brace level, and go
further by replacing the input sequences with the corresponding
character.

Beastie recognises a fairly extensive set of such commands, and in
particular should be able to manage all of the characters in ISO
8859-1 and the Unicode Latin-1 range, and most of the letters in the
Unicode Latin Extended-A range, with a few exceptions where the LaTeX
command is hard to find, which are therefore unlikely to be used in
practice.

The set of supported commands is currently fixed, but may become
expandable in future versions of Beastie.

Beastie also natively recognises Unicode characters in `.bib` files,
so one could use either of the examples above in such a file, in this
or any other script covered by Unicode.

Other commands in `.bib` files, such as `\emph{foo}` or `\LaTeX`, are not
recognised by default, but you can add support for these within the
Scheme layers (not within `.bst`) using the
[`user-char-command`](#fn-user-char-command) function.

Beastie manipulates these internally using a ‘bstring’ type (for
‘braced string’).  _You will typically not manipulate bstrings
directly_, except if you use the combination of
`ustring-iterator/bstrings` and `list->bstring` to iterate through a
ustring in a bstring-aware way.  Functions such as
`uppercase-string/bst` from the `'bst` module use this to uppercase
strings while leaving brace-level-1 content alone, in the way that
`.bst` files require.

You may have a use for function `ustring->ustring`, which converts a
ustring to a ustring in a way which allows you to control how braces
and no-break spaces, or tildes in TeX terms, are managed.  This is
logically part of this module because it does this _via_ a bstring.
The function [`untexify-string-or-list`](#fn-untexify-string-or-list)
wraps this in a way which might be convenient if you are generating
`xexpr` structures, on the way to generating (X)HTML.
