![]() |
Math font profiles, shipped fonts and the database | ![]() |
The MATH table tells TeXmacs how to lay out formulas in a font, but not which font to use for the text around them, whether the letters of a formula should come from the math font or from the italic text face, under which name the font should appear in a menu, or where its file is when the font database has never seen it. This page describes the profiles which record that knowledge for the OpenType math fonts TeXmacs knows by name, the way a profile steers the choice of fonts in the smart font, the menus built from the profiles, the fonts shipped with TeXmacs and the changes made to the font database so that they are found everywhere: the order in which font files are looked for, the merge of the shipped database into the local one, and faster rescans.
How a user picks these fonts, and the environment variables involved, is described in selecting fonts; every shipped font is shown in the fonts which come with TeXmacs. The database itself is the subject of the font database and font selection.
A profile is declared in Scheme, in
TeXmacs/progs/fonts/fonts-opentype.scm
, with the macro define-math-font-profile, which expands into a call of the glue routine math-font-profile-set:
(define-math-font-profile "Libertinus Math"
(file "LibertinusMath-Regular") (text "Libertinus")
(sans "Libertinus") (mono "Libertinus")
(letters "math") (menu "Libertinus") (group "Serif")) |
The name is the family of the math font as the font database names it. The module is loaded at boot with the other font modules (
init-texmacs.scm
), so the twenty-six profiles are in place before the first document is typeset: twenty-five of math fonts and one of a text font without mathematics (see below).
On the C++ side (
Graphics/Fonts/math_font_profiles.cpp
) a profile is stored as a tree, a tuple of (key value) pairs, in a table keyed by the family. Both tables of the file are function-local statics, since they are filled during the Scheme boot, before the global statics of other units are guaranteed to be initialized. The routines, all exported to Scheme by
build-glue-basic.scm
, are
Stores a profile and, when it names a text companion which no earlier profile claimed, records the reverse association text \(\rightarrow\) math. The first claimant wins, so the order of the declarations in
fonts-opentype.scm
decides which math font a shared text family pulls in: TeX Gyre Pagella Math is declared before Euler Math and Asana Math, which name the same text font.
The profile of a family (an empty tuple if there is none) and the list of profiled families.
The value of one key, or the empty string. Values arrive from Scheme as quoted strings and are unquoted.
The math font whose profile names text as its companion. A document may name one of the families of a master (KpRoman) where the profile names the master (Kepler), so the master of the family is tried as well (font_database_master).
The text key.
The keys and the places where they are read are:
The file name of the math font without suffix. It decides whether the font is installed (font-exists-in-tt? in the menus, tt_font_exists in profile_fix) and where to find it when the database does not know it (register_profiled_font).
The text companion, named by its master, the second field of an entry of
TeXmacs/fonts/font-features.scm
, since that is what the font variable holds. Naming a family instead (Fira Sans rather than Fira) makes the font selection fall back on the feature distance.
The companions used for sans serif and typewriter text and mathematics (profile_variant_fix). A value may list alternatives separated by commas, such as "Inconsolatazi4, TeX Gyre Cursor" for the TeX Gyre profiles (except TeX Gyre DejaVu Math), STIX Two Math, Erewhon Math, XCharter Math, Euler Math, Lete Sans Math, XITS Math, Asana Math, Garamond-Math, OldStandard-Math and GFS Neohellenic Math (Concrete Math takes Latin Modern Mono): the first one of which the database knows a style (font_database_styles) is used, and the item is kept when none is.
math or text: whether the letters of formulas come from the math alphabets of the math font or from the italic text face. Read by the constructor of smart_font_rep, see below.
A file of the text companion, for a companion which the database may not know; its directory is then added to the database (register_profiled_font). The menus also require it to exist before they list the font.
The font family, rm or ss, in which the text is set (rm when absent). Read on the Scheme side only (opentype-font-family), by init-opentype-font, the check marks of the menus and opentype-math-companions: KpMath Sans, Noto Sans Math and IBM Plex Math set font-family to ss.
The label of the font in the menus and its section: Serif, Sans serif or Other. The labels follow the names LaTeX users know, so TeX Gyre Termes Math is Times.
Recorded in four profiles but read nowhere. Bold mathematics uses a real bold face when the database attaches a Bold style to the master of the math font, which is the case for all four, so the key only documents that such a face exists.
fonts/fonts-opentype.scm
, give the typewriter companion "Inconsolatazi4, TeX Gyre Cursor" to the text fonts of the menu of text fonts which have no monospaced face of their own, fonts of macOS and of TeX distributions: Palatino, Baskerville, Charter, Cochin, Didot, Garamond, Georgia, Hoefler Text, Iowan Old Style, Times New Roman, Alegreya, Cardo, Crimson, Essays1743, Junicode, Merriweather, Arial, Avenir, Futura, Gill, Helvetica, Lucida Grande, Optima, Verdana, Inter, Lato and Cuprum. Without them the typewriter text would be the closest monospaced font of the database, Linux Libertine Mono for Palatino; with them, it is Inconsolata. The families with a monospaced face of their own (DejaVu, IBM Plex, Noto, Fira, Libertinus, …) need no such profile.
The family string of a smart font goes through a chain of rewritings in smart_font_bis (
Graphics/Fonts/smart_font.cpp
) before a base font is looked for: tex_gyre_fix, kepler_fix, math_fix and, last, profile_fix, which is where the profiles come in. For each item of the font sequence which carries no condition (no =):
The item and, if the item is a text font with a math companion, that companion are registered if needed (see below).
In a math shape (mathitalic, mathupright, mathshape), a text family with an installed math companion is replaced by the companion, the sans or mono companion is substituted for the sans serif and typewriter variants, and the result is replaced by its master, since the font selection is driven by masters (the family KpMath belongs to the master Kepler Math).
In a text shape, a math family is replaced by its text companion (or the sans serif or typewriter one), and a text family with a math companion keeps itself but takes the variant companions of that math font. A math font which has no text face of its own, such as Concrete Math or Euler Math, thus sets its text in the family its profile declares. A text family with neither takes the variant companions of a profile of its own name, if there is one (the companion-only profiles above).
This is why formulas follow the math companion of the text font and not math-font: math-font only counts while font is roman. A pairing which is not the canonical one is written as a rule, math=Euler Math,TeX Gyre Pagella, which math_fix resolves in math shapes; the condition makes the item invisible to profile_fix.
profile_variant_fix splits the variant on -, as variant_features does, and looks for the key mono when one of the parts is tt, for sans when one is ss. This matters for prog mode (the inputs of sessions and the prompt of AI sessions), which asks for the variant rm-tt in the shape mathupright. In that math shape kepler_fix has already turned Kepler into Kepler Math, which names no profile, so the profile is looked up by profile_family: the family itself when it has a profile, else the first profiled family whose master (font_database_master) is the given name, here KpMath. The answers are cached in a static hashmap. Without these two steps the inputs of sessions were set in the closest monospaced font, Libertinus Mono, for Kp Fonts and Palatino alike.
A monospaced font may also give its space another width than its cells (the space of KpMono is 333 units for cells of 530): the constructor of unicode_font_rep (
Plugins/Freetype/unicode_font.cpp
) therefore gives the space the advance of m (stretchable between three quarters and one and a half of it) when m and i have the same advance, so that verbatim text lines up.
The menus are built from the profiles of the fonts which are installed (opentype-math-font-installed?: the file exists, and the text-file if there is one). opentype-math-font-list returns triples (label math text) sorted by label, and opentype-math-font-group-list those of one section. The menu of the font button of the focus toolbar (document-short-design-font-menu) has a submenu for each design, Serif, Sans serif, Typewriter and Decorative: the first two list the fonts with mathematics of their group, then the text fonts. Each list is a menu without arguments (opentype-serif-font-menu and the others), since a submenu is expanded after its parent and a menu with arguments has lost them by then. opentype-math-font-menu appends the installed math fonts to Document\(\rightarrow\)Font\(\rightarrow\)Mathematical font. The text fonts which bring no mathematics are listed apart, in
TeXmacs/progs/fonts/font-short-menu.scm
, declared with define-text-font by master. text-font-list leaves out the text fonts returned by opentype-math-companions, which the menu offers with their mathematics: only the text companions of the installed profiles whose family is rm. A profile set in sans serif names a master which also has a serif face, Noto for Noto Sans Math and IBM Plex for IBM Plex Math, and Noto Serif and IBM Plex Serif must stay in the menu of text fonts.
The entries call
Calls init-font with the value computed by opentype-font-value: the text companion itself when the math font is the one this text font pulls in (math-family-for-text), and the rule math=math,text otherwise. It then sets font-family when the profile asks for another family than rm.
init-font (
generic/document-edit.scm
) sends the four TeX Gyre text fonts to the style packages of their hand-tuned mathematics (pagella-font and the others), unless another math font is asked for (tex-gyre-font?): Euler Math and Asana Math are set with Pagella text, and the package would replace them by Pagella Math. It also no longer adds the packages of fira-font and libertine-font when a profiled math font is given, since those packages take their large operators from TeX Gyre Pagella and are older than the math fonts of the same design. The check marks of the menus (test-opentype-font?) look at the style package for the TeX Gyre fonts and at the initial values of font and font-family otherwise.
The directory
TeXmacs/fonts/truetype
holds, besides the fonts shipped before (the first STIX fonts, the TeX Gyre math fonts, Linux Libertine, OpenDyslexic), one subdirectory per family with the math font, its text faces, a README.md and the license: lm (Latin Modern), newcm (New Computer Modern, regular and bold math, New Computer Modern Sans Math, the NewCM10, NewCMSans10 and NewCMMono10 faces), stix2, kp (KpMath, KpMath Sans and the Kp text faces), fira (Fira Math), libertinus, erewhon, xcharter, concrete (Concrete Math with the CM Unicode Concrete faces), euler, letesans (Lete Sans Math, regular and bold), garamond (Garamond-Math and EB Garamond), oldstandard, gfsneohellenic, plex (IBM Plex Math and the Plex Sans, Serif, Mono and Sans Condensed faces in their eight weights), noto (Noto Sans Math, Noto Sans and Noto Sans Mono) and dejavu (TeX Gyre DejaVu Math with the DejaVu Serif, Sans and Sans Mono faces and the condensed ones). The directory inconsolata holds Inconsolatazi4, the typewriter companion of several profiles. Of the profiled math fonts, only XITS Math and Asana Math are not shipped; they are used when a TeX distribution or the system has them.
Four directories hold text fonts without mathematics, which are in the menu of text fonts (
font-short-menu.scm
): gentium (Gentium Plus), antt (Antykwa Torunska), poltawski (Antykwa Poltawskiego), iwona and kurier. With DejaVu, the weights of IBM Plex and the typewriter of variable width of Latin Modern (lmmonoprop10, the shape proportional of Latin Modern Mono), they complete the fonts of the ConTeXt distribution. The files of IBM Plex are those of TeX Live, which shorten the names of the families (IBM Plex Sans Cond, ExtLt, Medm, SmBld): their entries of
font-features.scm
are written by hand, in the master IBM Plex with the features Condensed, ExtraLight and SemiBold, and the medium weight in a master of its own, IBM Plex Medium, since a medium face inside a master is taken for the regular one. For the same reason the medium faces of Antykwa Torunska, Iwona and Kurier are not shipped.
All their faces are entered in the shipped database (
TeXmacs/fonts/font-database.scm
,
font-features.scm
and
font-characteristics.scm
), so they work in a fresh installation without a scan. A few entries are arranged by hand: KpMath Sans, whose name table calls its family KpMath with the style Sans, is also listed as a family KpMathSans, a master of its own, so that a sans serif document finds it rather than the KpSans text faces. The bold math faces whose name tables call their families otherwise are attached by hand: the bold Erewhon Math is entered in the database as the Bold style of Erewhon Math, and the families XCharter-Math-Bold and Concrete (the bold Concrete Math) are given the masters XCharter Math and Concrete Math in
font-features.scm
. Noto Sans Math is a master of its own, as Fira Math is, rather than a family of the master Noto. A scan files a family X Medium under the style of X, so that the IBM Plex entries of the Regular style also list the medium files (IBMPlexSans-Medium.otf next to IBMPlexSans-Regular.otf); since the first file of an entry is the one used, the database puts the files named Medium after the others, both when it scans and when it loads a database file (medium_last in
font_database.cpp
).
The smart font also uses one shipped file directly: when the main font has a MATH table and a symbol it lacks could only be emulated as a bitmap, resolve_shipped_math takes the glyph from STIXTwoMath-Regular (the macro SHIPPED_MATH_FONT); see inspecting the font system.
tt_font_find_sub (
Plugins/Freetype/tt_file.cpp
) now looks for .otf, .ttf and .ttc before .pfb, and .dfont last. A TeX distribution ships many families in both forms, and the Type 1 file carries the encoding of the TeX world (in XCharter-Roman.pfb the code of a is the pound sign), whereas TeXmacs asks for characters by Unicode and needs the cmap of the sfnt file; the PDF writer also gets real glyph indices that way. Since the answers of tt_font_find are cached in the home directory (font_cache.scm), which outlives an upgrade, the cache key was changed from ttf:name to sfnt:name: a cache written when Type 1 came first would otherwise keep naming the .pfb file, without features or MATH table. The comment in the code asks to change the prefix again whenever the order changes.
The font path on macOS no longer lists the TeX Live directories year by year: texlive_font_dirs looks for every installation under /usr/local/texlive, /usr/share/texlive, /opt/texlive and $HOME/texlive and adds the opentype and truetype directories of their texmf-dist/fonts.
The local database ($TEXMACS_HOME_PATH/fonts) used to be derived from the shipped one only when it was empty, so a home directory written by an older version never saw the fonts a newer version registers, and a character only those fonts draw came out as its name in red. font_database_load (
Graphics/Fonts/font_database.cpp
) now keeps a stamp in $TEXMACS_HOME_PATH/fonts/shipped-stamp.scm of two lines:
the dates and sizes of the three shipped files and the value of $TEXMACS_PATH (shipped_fonts_stamp);
the number of entries of the local database when this installation left it.
The shipped database, features and characteristics are loaded, filtered against the files of this machine and saved again, merged with the local entries, when the first line differs from the current stamp (shipped_fonts_changed, which also holds when the stamp is missing) or when the local database has fewer entries than the second line records (shipped_fonts_shrunk). The installation is part of the stamp because merging only keeps the fonts installed on this machine, and the shipped fonts are installed in the directory of the installation which merges: a home directory shared by several installations would otherwise keep the fonts of whichever ran last. A console line says when a merge happens.
font_database_build used to read and parse every font file on the path, which takes minutes with a TeX Live installation on it. It now builds once an index of the "name size" pairs already recorded (font_database_init_scanned, a static hashset) and skips those files, counting new and skipped files for a summary line printed by font_database_build_local. font_database_build_characteristics likewise skips the styles whose characteristics are known unless force is set. The per-file messages (Process, Analyzing) are only printed with the verbose debug flag, on debug_fonts.
Graphics/Fonts/math_font_profiles.cpp
The profile tables and their accessors.
Graphics/Fonts/smart_font.cpp
profile_fix, profile_variant_fix, profile_family, register_profiled_font, the ot_math flag and the math italic subfont, resolve_shipped_math.
Graphics/Fonts/font_database.cpp
The shipped stamp, the merge and the index of scanned files.
Plugins/Freetype/tt_file.cpp
The order of the suffixes, the cache key, the TeX Live directories.
Plugins/Freetype/unicode_font.cpp
The space of monospaced fonts.
TeXmacs/progs/fonts/fonts-opentype.scm
The profiles, the menus, init-opentype-font.
TeXmacs/progs/fonts/font-short-menu.scm
The text fonts of the focus toolbar.
TeXmacs/progs/generic/document-edit.scm,
document-menu.scm
TeXmacs/fonts/truetype/, TeXmacs/fonts/*.scm
The shipped fonts and database.
A profile names its companions by master, not by family; a wrong name is only noticed when a document asks for it, since the profile test (tests) checks the math font, its family name and its MATH table, not the companions.
The order of the profiles matters when two of them name the same text font. The companion-only profiles (Palatino and the other text fonts without a monospaced face) are declared last, after the menus.
The bold-math key has no effect.
No key says which mathematical alphabets a font really has: a partial alphabet (the script letters of most fonts) is silently completed with emulated glyphs.
register_profiled_font writes to the local database the first time a profiled family is asked for, which may happen while a document is typeset.
The font selection still knows some families by name: is_math_family lists the traditional math families and tex_gyre_fix and tex-gyre-font? the four hand-tuned TeX Gyre fonts, which have no profile to consult.