GNU TeXmacsUser manualReferenceAboutEnglish
The universal encoding and universal strings

1.Characters and symbols

A string in the TeXmacs universal encoding is a sequence of characters, each of which is

The less-than and greater-than signs themselves are written <less> and <gtr>. There is no escape for a lone angular bracket, and a string with unbalanced brackets is malformed. The routines below do not validate the names of symbols: whether <foo> means anything is decided by the fonts which render it, the converters which translate it and the editing code which interprets it (for instance as a mathematical operator).

Unicode escapes are normally written with upper case hexadecimal digits and without leading zeros (this is what as_hexadecimal produces, for instance <#20AC>), but from_hexadecimal also accepts lower case digits, and some tables (such as the transliteration table) register both spellings. Code points below 256 which have a Cork equivalent are represented by the Cork byte rather than by an escape; the converters of the next page take care of this.

2.The Cork table

The Cork encoding (also called T1) is the 8-bit font encoding of LaTeX's fontenc. TeXmacs uses it for single byte characters. Its correspondence with Unicode is given by

langs/encoding/corktounicode.scm

; in summary:

0x00–0x0C

Accents used for composing (grave, acute, circumflex, tilde, dieresis, double acute, ring, caron, breve, macron, dot, cedilla, ogonek).

0x0D–0x17

Quotes, guillemets, the en and em dashes, and a compound word mark (mapped to U+2060).

0x18–0x1F

The per mille zero (so that % followed by 0x18 is the per mille sign), dotless i and j, and the ligatures ff, fi, fl, ffi, ffl.

0x20–0x7F

Essentially ASCII, with three exceptions: 0x60 is the typographic opening quote (U+2018), 0x7F is a hyphen (U+2010), and < and > are not used as characters (see above).

0x80–0x9F

Upper case letters of central and eastern European languages (0x80 is A with breve, 0x98 is Y with dieresis, 0x9C is IJ, …), except 0x9F, which is the section sign.

0xA0–0xBF

The corresponding lower case letters, at an offset of 0x20, except 0xBD, 0xBE and 0xBF, which are the inverted exclamation mark, the inverted question mark and the pound sign.

0xC0–0xFF

As in ISO-8859-1, except 0xD7 (OE instead of the multiplication sign), 0xF7 (oe instead of the division sign), 0xDF (upper case SS) and 0xFF (sharp s instead of y with dieresis).

The Cork encoding is therefore not ISO-8859-1: only the range 0xC0–0xFF almost coincides, and even there four positions differ. Bytes which come from outside TeXmacs must always be converted.

The control characters 0x09 (tab), 0x0A (line feed) and 0x0D (carriage return) are Cork glyphs too (macron, dot accent and a low quote). Document trees do not contain them, since paragraphs are separate children of document nodes, but strings of verbatim text do; see the pitfalls in string utilities and pitfalls.

3.Iterating over universal strings

The routines of

Data/String/analyze.cpp

whose name starts with tm_ treat a symbol as one character:

tm_char_forwards (s, pos), tm_char_backwards (s, pos)

Move pos over one character: one byte, or a whole symbol from < to >. tm_char_next and tm_char_previous return the new position.

tm_string_length, tm_forward_access (s, k), tm_backward_access (s, k)

The number of characters and the \(k\)-th character from the start or from the end (Scheme: tmstring-length, tmstring-ref, tmstring-reverse-ref).

tm_tokenize, tm_recompose

Split a string into its characters and join them again.

tm_string_split

Split a string into two pieces near its middle (tmstring-split): preferably at the first space from the middle on, or at the last space if all spaces are before the middle (the space becomes a piece of its own); otherwise at the first boundary from the middle on between runs of letters, digits and other characters; and otherwise at the first character boundary from the middle on.

tm_search_forwards, tm_search_backwards

Substring search which only matches at character boundaries.

contains_unicode_char

Whether the string contains a <#…> escape.

Conversions between universal strings and plain text which only touch the brackets:

tm_encode (s)

Replaces < and > by <less> and <gtr> and leaves all other bytes unchanged (string->tmstring). It does not convert the bytes, so it is only correct for ASCII input.

tm_decode (s)

The converse (tmstring->string). It turns <less> and <gtr> back into brackets, keeps Unicode escapes with exactly four hexadecimal digits, and drops all other symbols. A < without matching > truncates the result.

tm_var_encode (s)

Like tm_encode, but keeps <#…> escapes.

tm_correct (s)

Removes stray > signs and symbols which contain a nested <, and drops an unterminated symbol at the end.

4.Case, accents and letters

Two families of routines change the case of letters. The routines of

analyze.cpp

(upcase, locase, upcase_first, locase_all, …; Scheme: upcase-all, locase-all, …) work on bytes and only know ASCII and the Cork letters, which they recognize with is_iso_locase and is_iso_upcase and shift by 0x20.

The routines of

universal.cpp

(uni_locase_char, uni_upcase_char, uni_locase_first, uni_upcase_first, uni_locase_all, uni_Locase_all (all but the first character), uni_upcase_all; Scheme: tmstring-upcase-all and friends) work on universal characters. Besides the Cork letters, they handle the Unicode escapes for Latin Extended-A and part of Latin Extended-B, Greek and Cyrillic, and the symbolic names of Greek letters (<alpha> and <Alpha>; <varepsilon> and similar variants are mapped to the upper case letter).

The remaining routines of

universal.cpp

are mainly used for sorting, indexing and bibliographies:

uni_translit (s)

Transliteration to ASCII: Cork accented letters lose their accents (using the table Cork_unaccented of

Data/Convert/Tex/parsetex.cpp

), and Cyrillic escapes are transliterated following the ICAO scheme (tmstring-translit).

uni_unaccent_char, uni_unaccent_all, uni_get_accent_char, get_accented_list

Remove the accent of an accented Latin letter, or return the accent. The unaccenting table covers the Cork letters 0x80–0xBF and the letters of U+00C0–U+00FF (converted to their Cork form); the accent table only covers the latter.

uni_is_letter (s)

Whether a character is a letter (tmstring-letter?).

uni_before (s1, s2)

Comparison for sorting (tmstring-before?): both strings are unaccented and put in lower case, then compared bytewise. This is not a locale aware collation.

Some of these tables have errors; see string utilities and pitfalls.

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