![]() |
Inspecting the font system, tests and open problems | ![]() |
Emulation is how TeXmacs lets any font be used for mathematics: what a font lacks is taken from another family or constructed. The question is therefore less whether a glyph is emulated than being able to see what happened to it. This page describes the tools which show the decisions of the smart font (the font inspector, the colouring of glyphs by route and the font report), the work on mathematical symbols which came with the OpenType support, the tests which guard that support, and the problems which are still open.
The tools are described for users in from markup to glyph; the routing they report on is the subject of smart, virtual and emulated fonts and in particular resolving a character.
A smart font (
Graphics/Fonts/smart_font.cpp
) routes each character to one of its subfonts once, and remembers the answer in its smart_map: chv for the single bytes, cht for the other characters, and for every subfont its specification fn_spec[nr] (a tuple such as ("emulate" "emu-fundamental") or (family variant series shape attempt)) and its rewriting fn_rewr[nr]. The debugging tools read these tables and never call the resolver, so inspecting a character changes neither the routing nor the font caches, and a character which has not been routed yet is reported as unresolved.
smart_font_rep::debug_origin (nr) classifies a subfont, from its specification, into one of five routes, and caches the answer in the array origins:
The requested font.
A family named by a font rule (the specification subfont, or an attempt number of 1).
Another family found by feature distance (other, a later attempt), or the shipped math font (shipped-math).
A virtual font, an emulation, an assembled bracket or a derived (poor-*) font.
The error font.
A main font extended by a virtual font (its name contains #enhance-) draws some characters itself and constructs the others; those are classified one by one with virtual_font_constructs.
The debug switch fonts (DEBUG_FLAG_FONTS, toggled from the Debug menu or by toggle-font-colours-by-origin) affects drawing only. draw_fixed tests the switch once per string; when it is on, each piece is drawn by debug_draw, which sets the pencil to blue for rule, orange for fallback and green for emulated around the ordinary drawing, and leaves the requested font and the red error font as they are. Metrics, routing and caches are untouched, so turning the switch on or off needs a repaint, not a new typesetting. Glyphs which the compound fonts of the traditional mathematics assemble internally are not distinguished: the switch sees the routes of the smart font, not the insides of its subfonts.
TeXmacs/progs/fonts/font-debug.scm
implements Tools\(\rightarrow\)Fonts\(\rightarrow\)Font inspector (open-font-inspector). The window is built as top-window builds one, from an alternative window handle, but with (alt-window-set-on-top win #t), so that it stays above the editor windows (see alternative windows). Closing it also turns the colouring off.
The inspector is driven by two overloadings, active only while it is open: notify-cursor-moved and, when it follows the mouse, mouse-event on move. Both remember the document being edited (not a tmfs://aux/ buffer nor a report) and schedule an update, which asks one of the glue routines
Implemented in
Texmacs/Data/new_view.cpp
. The editor provides its root box and the box path of the cursor or of the last mouse position (get_box_root, get_box_path_at, new in
edit_main.cpp
); box_font_debug_info (
Typeset/Boxes/Basic/font_debug_boxes.cpp
) finds the text box there, takes the character before the position (after it, under the mouse) and calls smart_font_debug_info. The result is a tuple of (key value) pairs: the character, the font, family, variant, series and shape, the subfont number, its specification and name, the route, the math type (OpenType, hand-tuned TeX Gyre or STIX, or traditional), whether the OpenType math path applies, the rewritten character if any, and, for an emulated character, whether a PDF export draws it as vectors or as a bitmap (virtual_font_draws_vectors). The second form looks at a view of buffer shown in a window and creates none; the inspector uses it while a report or another auxiliary buffer has the focus.
The report is displayed by a texmacs-output widget inside a refreshable, with Follow the mouse, Freeze and Colour glyphs by origin toggles and a Font report button.
Font report opens tmfs://fontdbg/document, a buffer whose Scheme handlers (tmfs-load-handler, tmfs-master-handler and the others, in
font-debug.scm
) generate a document attached to the edited one: its master is that document, as for the bibliography viewer. The content comes from
box_font_debug_report walks the typeset boxes of the current editor, asks smart_font_debug_info about every character of every text box and counts the distinct answers. The result is a tuple of entries (origin char family subfont pdf variant series shape count).
The report shows a summary per family, then the emulated characters, those taken from other families or from the families of a font rule, and those no font has, each drawn and counted; reopening it regenerates it. Only text boxes are visited, so the sized variants and assemblies of stretchable characters, which are drawn by other boxes, do not appear.
Of the 2437 code points of the symbol list of the LaTeX package unicode-math, about seven hundred had no TeXmacs name and could only be entered as <#XXXX>, without palette, shortcut or LaTeX conversion. Two hundred of them, those with a free name whose glyph at least half of the shipped math fonts draw, are now named:
TeXmacs/langs/encoding/tmuniversaltounicode-extra.scm
holds the names, generated by
tests/opentype/missing-symbols.py
and reviewed;
Data/String/converter.cpp
loads it next to tmuniversaltounicode in both directions;
progs/language/std-symbols.scm
gives each of them the class which determines its spacing;
progs/convert/latex/latex-symbol-drd.scm
lists them in latex-unicodemath-symbol%, so that a document using one exports with \usepackage{unicode-math}.
src/docs/math-symbol-coverage.md
counts the symbols which are still unnamed, block by block.
TeXmacs/progs/math/math-symbol-tools.scm
arranges the symbols in groups declared with define-math-symbols-group, which expands into one widget per width (sixteen columns for the window, four for a side tool), and offers them in a window (open-math-symbols, All symbols… in the mathematical insert menu) and in a side tool (open-math-symbols-tool); the group shown by the side tool is an argument of the tool, since a refreshed widget of a dock keeps the state it was built with.
Two changes make the buttons show what the typesetter can typeset. The symbol buttons of the palettes are drawn by box_widget (p, s, col, trans, ink) (
Texmacs/Window/tm_button.cpp
), which for the mathematical font classes mr, ms and mt now uses a smart font instead of find_font, so a symbol which lives only in a Unicode font is no longer blank. And in the Qt port (
Plugins/Qt/qt_ui_element.cpp
) a button whose content is a TeXmacs box (a simple_widget) is drawn as the icon of its action, at the size hint of the box, as toolbar buttons are; before, such a button only reached the screen through a menu and stayed empty in a window.
The tests of the OpenType work need a built tree. The C++ unit tests are run by the autotools harness, make -C tests (see building and testing); two of them concern fonts:
tests/Plugins/Freetype/tt_tools_test.cpp
The readers of the MATH, GSUB and GPOS tables.
tests/Graphics/Fonts/opentype_font_test.cpp
The constants, variants and assemblies of the fonts it finds, the corrections and kerning hooks, and the profiles: it reads
fonts-opentype.scm
, checks every key and group, which profile first claims a shared text companion, and that each installed math font is an OpenType math font known to the database under its profile name.
These tests look for their fonts in the directory given by TM_TEST_FONT_DIR and skip themselves without it, even for the fonts which are now shipped; pointing it at
TeXmacs/fonts/truetype
runs all of them but those needing a font which is not shipped (Asana Math). The scripts of
tests/opentype
do the rest:
Runs the unit tests, renders the samples of
tests/opentype/samples
with and without the hand-tuned tables (TM_HAND_TUNED=off evaluates (set-hand-tuned-math-fonts #f)), and fails if a PDF made by the native writer contains a Type 3 (bitmap) font or a syntax error; with TM_UNICODE_MATH_TABLE it also checks the symbol tables.
render-samples.sh
The renders, with a pixel diff against tests/build/ref when that directory exists; a difference is reported, not a failure.
compare-lualatex.sh
Typesets the formulas of
tests/opentype/compare
with TeXmacs and with LuaLaTeX and unicode-math in the same font, and stacks the two renders.
font-gallery.sh
One specimen per installed profiled math font (asked from TeXmacs with opentype-math-font-list), the images of
docs/OPENTYPEMATH.md
.
missing-symbols.py,
survey-math-fonts.py,
assembly-report.py
Tools which generated the symbol tables, surveyed the fonts and report on assemblies.
Without the native (Hummus) PDF writer every exported glyph is a bitmap, so the renders and the Type 3 check depend on how the tree was configured.
The list below was checked against the code; the design log
src/docs/opentype-math-design.md
(sections 6 and 7) has the details and the history.
Alphabets. No profile key declares the mathematical alphabets a font really provides, so an incomplete alphabet (script and double-struck in most fonts) is silently completed by emulated glyphs.
Constants not applied. delimitedSubFormulaMinHeight is left out on purpose (it would enlarge every automatic bracket), the device tables are parsed but never applied, the stack constants for above and below would move every such construct and are not used, and the italic correction of glyph assemblies is ignored; see mathematics from the MATH table.
GPOS. Only pair kerning of the kern feature is read; mark attachment (mark, mkmk), cursive and contextual positioning are not, which matters for fonts placing combining accents by marks. Kerning is not applied across box boundaries, so two single letters of a formula in separate boxes stay unkerned (OpenType features).
Profiles. bold-math is not read, and nothing checks that the companions a profile names exist (profiles).
Bitmaps in PDF. Six symbols only TeXmacs defines (triangleup, blacktriangleup and four nblacktriangle…) and the alphabets emulated with unserif are built with operations on pixels, which have no vector form, and export as small Type 3 bitmaps when the font lacks them. Every other symbol an OpenType math font lacks is either constructed as vectors or, if its emulation would be a bitmap, taken from the shipped STIX Two Math (resolve_shipped_math).
Seams. Assembled glyphs are glued on the measured ink of their parts, corrected to the advances of the table; a font whose parts have unusual side bearings could still show a seam (stretchable glyphs).
Names. Some choices still go by family name: the hand-tuned fonts (tex_gyre_fix, the stix and agella tests in the typesetter, which guard corrections that keep precedence), the traditional math families (is_math_family), and, for fonts without a MATH table only, supports_big_operators in
poor_rubber.cpp
.
Tests. The renders are compared by hand; the font tests skip themselves unless TM_TEST_FONT_DIR is set.
Graphics/Fonts/smart_font.cpp
debug_origin, debug_draw, debug_info, smart_font_debug_info, resolve_shipped_math.
Typeset/Boxes/Basic/font_debug_boxes.cpp
From boxes to characters: box_font_debug_info, box_font_debug_report.
Texmacs/Data/new_view.cpp,
Edit/Editor/edit_main.cpp
The glue entry points and the access to the boxes of an editor.
TeXmacs/progs/fonts/font-debug.scm
The inspector, the colouring toggle and the fontdbg handlers.
TeXmacs/progs/math/math-symbol-tools.scm
The symbol window and side tool.
Texmacs/Window/tm_button.cpp,
Plugins/Qt/qt_ui_element.cpp
Symbol buttons.
tests/opentype/,
tests/Graphics/Fonts/,
tests/Plugins/Freetype/
The tests.