![]() |
Finding and generating TeX font files | ![]() |
This page describes how TeXmacs locates the files of a TeX font and how it generates missing ones with the tools of a TeX distribution. The code is in
Plugins/Metafont/tex_init.cpp
,
Plugins/Metafont/tex_files.cpp
and, for the error cache,
Plugins/Metafont/load_tex.cpp
.
When TeXmacs sets up a new home directory (setup_texmacs in
System/Boot/init_texmacs.cpp
, run when $TEXMACS_HOME_PATH/system/settings.scm does not exist, and after -setup), it calls setup_tex, which removes $TEXMACS_HOME_PATH/fonts/font-index.scm and records the following values in the settings (set_setting), which are saved in settings.scm:
"true" or "false", according to whether the programs kpsepath, kpsewhich and texhash are in the PATH (init_helper_binaries).
The program used to generate missing metrics: the first of mktextfm, MakeTeXTFM and maketfm which is found, or "false".
Likewise for bitmap glyphs: mktexpk, MakeTeXPK, makepk or "false".
Always "600"; it is passed to the PK generator as the base resolution of the Metafont mode.
Search paths obtained by looking for tfm, pk and pfb/type1 subdirectories of a few traditional TeX font directories (/usr/share/texmf/fonts, /usr/lib/texmf/fonts, /var/texfonts, /opt/local/share/texmf-texlive-dist/fonts, …; on Windows, the subdirectories of $TEX_HOME/fonts), see init_heuristic_tex_paths.
These values are not detected again at later runs. Installing a TeX distribution after the first run of TeXmacs therefore has no effect on font generation until the settings are reset (for instance with texmacs -setup, see the main program).
At every start, after the settings have been loaded, init_tex calls reset_tfm_path, reset_pk_path and reset_pfb_path, which build the three static search paths of
tex_files.cpp
. For the metrics, the path is, in this order,
the current directory;
all subdirectories of $TEXMACS_HOME_PATH/fonts/tfm (where generated metrics are stored);
all subdirectories of $TEXMACS_PATH/fonts/tfm (the metrics shipped with TeXmacs);
the environment variable $TEX_TFM_PATH;
the TFM setting;
if fonts may be generated (MAKETFM is not "false", or TEXHASH is "true") and kpsewhich is not available, the directories printed by kpsepath tfm, if the KPSEPATH setting allows it.
The PK path is built in the same way from fonts/pk, $TEX_PK_PATH, the PK setting and kpsepath pk. The Type 1 path uses
fonts/type1
, $TEX_PFB_PATH and the PFB setting, without kpsepath.
resolve_tex (url name) finds a file by name; the kind of file is given by its suffix:
If the name is in the persistent cache font_cache.scm (see the system layer) and the cached file still exists, it is returned; a stale entry is removed.
Names ending in tfm or mf are looked up in the metric path (on Windows, a .mf name is also tried with the suffix .tfm), names ending in pk in the PK path and names ending in pfb in the Type 1 path.
If this fails and the KPSEWHICH setting is "true", the name is passed to kpsewhich (except for PK and Type 1 names on Windows, where the MiKTeX version of kpsewhich is considered unreliable for these files).
A result which was found is stored in font_cache.scm. Failures are not cached here.
exists_in_tex (u) is !is_none (resolve_tex (u)). The Type 1 files are usually not located through resolve_tex directly, but through tt_font_find (
Plugins/Freetype/tt_file.cpp
), which tries name.pfb first (with resolve_tex) and then the TrueType and OpenType suffixes; see Type 1 substitution. Unlike resolve_tex, tt_font_find also caches failures, as an empty entry ttf:name in font_cache.scm.
make_tex_tfm (name) runs the program given by the MAKETFM setting:
mktextfm --destdir $TEXMACS_HOME_PATH/fonts/tfm name, after which the name.600pk file which mktextfm creates as a side effect is removed again.
MakeTeXTFM name, which stores the result in the TeX tree.
The Windows tool, called with --dest-dir and the name without its suffix.
make_tex_pk (name, dpi, design_dpi) runs the MAKEPK program; with mktexpk the command is
mktexpk --dpi dpi --bdpi design_dpi --mag dpi/design_dpi
--destdir $TEXMACS_HOME_PATH/fonts/pk name |
where design_dpi is the DPI setting. Both functions run the command with system, print a message if it fails, and are called between system_wait ("Generating font file", name) and system_wait (""), which show a “please wait” indicator. After a successful generation, the caller looks the file up again, and if it is still not found, it rebuilds the search path (reset_tfm_path or reset_pk_path) and tries once more, since the generator may have created a new directory.
Generating a font is slow and, when the font does not exist at all, pointless.
load_tex.cpp
therefore records failures as empty marker files $TEXMACS_HOME_PATH/fonts/error/file-name:
Before generating a metric or a PK file, try_tfm and try_pk check for such a marker and give up immediately if it exists.
A metric marker is written when generation was attempted and the file could still not be found.
A PK marker is written whenever the file could not be found, also when generation is disabled (MAKEPK is "false").
The markers are removed by the options -setup and -delete-font-cache, by the reset which follows a crash during startup (the boot lock), by an upgrade to a new version (init_upgrade), on macOS when TeXmacs is started with the Alt key pressed, and automatically when the directories
fonts/type1
or
fonts/truetype
of $TEXMACS_PATH or $TEXMACS_HOME_PATH have changed (
System/Misc/data_cache.cpp
).
Besides file locations, font_cache.scm contains three kinds of entries related to TeX fonts:
The size of the metric which was actually used for a request at another size (for instance the design size 10 for a request at a size which has no metric of its own, see the size search), so that the next request goes straight to that file.
The name of the Type 1 (or TrueType) font chosen for a family and size (tt_find_name).
The file of an outline font, or the empty string if there is none.