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

.

1.Settings detected at the first run

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:

KPSEPATH, KPSEWHICH, TEXHASH

"true" or "false", according to whether the programs kpsepath, kpsewhich and texhash are in the PATH (init_helper_binaries).

MAKETFM

The program used to generate missing metrics: the first of mktextfm, MakeTeXTFM and maketfm which is found, or "false".

MAKEPK

Likewise for bitmap glyphs: mktexpk, MakeTeXPK, makepk or "false".

DPI

Always "600"; it is passed to the PK generator as the base resolution of the Metafont mode.

TFM, PK, PFB

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

2.Search paths

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,

  1. the current directory;

  2. all subdirectories of $TEXMACS_HOME_PATH/fonts/tfm (where generated metrics are stored);

  3. all subdirectories of $TEXMACS_PATH/fonts/tfm (the metrics shipped with TeXmacs);

  4. the environment variable $TEX_TFM_PATH;

  5. the TFM setting;

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

3.Looking up a file

resolve_tex (url name) finds a file by name; the kind of file is given by its suffix:

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

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

  3. 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).

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

4.Generating missing files

make_tex_tfm (name) runs the program given by the MAKETFM setting:

mktextfm

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

MakeTeXTFM name, which stores the result in the TeX tree.

maketfm

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.

5.The error cache

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:

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

).

6.What the cache remembers

Besides file locations, font_cache.scm contains three kinds of entries related to TeX fonts:

tfm:familysize

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.

tt:familysize

The name of the Type 1 (or TrueType) font chosen for a family and size (tt_find_name).

ttf:name

The file of an outline font, or the empty string if there is none.

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