![]() |
From markup to glyph | ![]() |
Between the font you asked for and the ink on the page there are several steps, and each of them can be configured. This page follows one character through them.
The text of a document is a sequence of characters in the internal encoding of TeXmacs: ASCII characters and the accented Latin letters of the Cork encoding stand for themselves, and everything else is written between angle brackets. The letter \(\textit{\alpha}\) is the character <alpha>, and a character which has neither a byte nor a name is written by its Unicode code point, such as <#1D6FC>. Stretchable characters have names of their own, such as <left-(-2> for the third size of an opening parenthesis (sizes count from 0).
A name is not a glyph, and it is not a code point either: it is what the editor stores and what the font system is asked to draw.
When the typesetter reaches a piece of text it reads the mode it is in, text, mathematics or program, and the corresponding variables (selecting fonts). From them it builds a logical font: a family name followed by normalized features, such as (Pagella bold italic). The font a document asks for is a request in the same sense: the family may not exist on this machine, and the features may not all be available.
What the typesetter receives back is a smart font. It is not one font: it is a router which keeps a list of subfonts and decides, character by character and once for each, which of them draws it. This is why a formula can mix a Greek letter from the math font, a blackboard bold letter which is drawn by hand and an arrow taken from a third font, without the document saying anything about it.
The decision follows a ladder, from the most faithful to the most desperate:
a few rewritings which come first: in a formula an italic Greek letter, a dotless letter or a prime taken from the italic font, a few special characters, and the brackets which TeXmacs knows how to build out of pieces;
the families of the font request, the main one first, in successive attempts, each one less demanding than the last: the font itself, its derived, or “poor”, variants (bold by thickening, for instance), its stretchable characters, and at the later attempts another family which has the character, found in the font database and rendered at a size adjusted so that its x-height matches the one of the main font. A symbol the main font lacks may also be emulated there, as a construction over its other glyphs; when the main font is an OpenType math font and the construction could only be exported as a bitmap, the symbol is taken from STIX Two Math instead, which comes with TeXmacs, so that the document looks the same on every system;
the mathematical letters: a bold, script, fraktur or double-struck letter taken from the Unicode mathematical alphanumerics or from an emulated alphabet;
a virtual font which defines the character as a construction over other glyphs;
failing everything, the error font, which draws the name of the character in red.
A red name in a formula therefore does not mean that the character is unknown to TeXmacs: it means that no font was found for it. The most common cause is a font database which was written before the font you need was installed; see the font configuration files.
Steps 2 and 6 need to know which Unicode character a name stands for. The tables of $TEXMACS_PATH/langs/encoding answer that question:
tmuniversaltounicode.scm
and its companions map <alpha> to U+03B1 and back. The same tables serve the converters, which is why a symbol without an entry there can be typed and printed but not exported.
Choosing the file is the work of the font database. A logical font is compared with every style of every family it knows, by a distance which counts the features that match and the ones that had to be dropped; the first attempt is strict, the following ones are increasingly tolerant, which is how the fallback of step 6 finds a font for a rare character. The files which hold that knowledge are described in the font configuration files.
The TeX fonts are addressed differently: their metrics come from a .tfm file and their glyph positions have no Unicode meaning, so an encoding file in $TEXMACS_PATH/fonts/enc maps each position to a TeXmacs character name. Those files are simply lists of names with the position where they start, and a font rule says which one a font uses.
FreeType opens the file and gives back an outline, which is rasterized at the size and the resolution in use; the resulting bitmaps are kept in memory, per size and per resolution, for the session (the directory $TEXMACS_HOME_PATH/fonts holds the font database and the bitmaps and metrics of the TeX fonts, not those of FreeType). When a document is exported to PDF or PostScript the same glyphs are written as vectors and the fonts are embedded as subsets. The glyphs which TeXmacs builds out of other glyphs are written as vectors too, except those whose construction works on pixels, a few emulated symbols and alphabets, which become small bitmap fonts.
The ladder is a strength: a document can use any font, and whatever the font lacks is found elsewhere or emulated. Tools\(\rightarrow\)Fonts\(\rightarrow\)Font inspector opens a window which shows what it decided, and gives access to the other tools; none of them slows the typesetter down when it is not in use. The window stays above the editor windows.
Reports, as the cursor (or, with Follow the mouse, the mouse) moves, what the font system did with the glyph before the cursor: its route, the font file which draws it, the rewriting into another character (a letter into its mathematical italic, for instance), and whether the OpenType math path applies. It reads the routing tables and resolves nothing, so inspecting a glyph changes nothing. Freeze keeps the report of one glyph while the cursor moves on. While a font report or another auxiliary document has the focus, the inspector keeps showing the glyph at the cursor of the document it was looking at.
Draws every glyph in the colour of its route: as usual for the requested font, blue for a family which a font rule names, orange for another family found by feature distance, green for an emulation (a virtual or a derived font); the error font is red anyway. Only the drawing changes, so the switch takes effect at the next repaint, and it is turned off with the inspector. The same switch is fonts in the Debug menu.
A document attached to the document being edited, like the bibliography viewer, which lists every character of the typeset document by route: a summary per family, then the emulated characters, those taken from other families or from families of a font rule, and those no font has, each shown and counted. For an emulated character it also says whether a PDF export will draw it as vectors or as a bitmap. Opening it again regenerates it.
Glyphs which TeX fonts assemble themselves, inside the compound fonts of the traditional mathematics, are not marked: the tools see the routes of the smart font, not the insides of those fonts.
No font was found for it. Try Tools\(\rightarrow\)Fonts\(\rightarrow\)Scan disk for fonts, and read about the merge of the shipped database in the font configuration files.
The database was written before you installed it; the same scan adds it.
The file found for a font name is cached; Tools\(\rightarrow\)Fonts\(\rightarrow\)Clear font cache removes that cache (system/cache/font_cache.scm) and the local database files (
font-database.scm
,
font-features.scm
,
font-characteristics.scm
and shipped-stamp.scm under fonts), which are rebuilt at the next start.
The fonts it asks for are not installed there, and the closest matches were used instead. Fonts shipped with TeXmacs do not have this problem.