GNU TeXmacsUser manualReferenceAboutEnglish
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.

1.What the smart font records

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:

font

The requested font.

rule

A family named by a font rule (the specification subfont, or an attempt number of 1).

fallback

Another family found by feature distance (other, a later attempt), or the shipped math font (shipped-math).

emulated

A virtual font, an emulation, an assembled bracket or a derived (poor-*) font.

error

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.

2.Colouring glyphs by route

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.

3.The font inspector

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

(font-debug-info at-mouse?)
(the glyph at the cursor or the mouse)
(font-debug-info-of buffer at-mouse?)
(the same in another buffer)

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.

4.The font report

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

(font-debug-report)
(every character, by route)

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.

5.Mathematical symbols

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:

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.

6.Tests

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:

check.sh

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.

7.Open problems

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.

8.Source files

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.

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