>> Home / latex / fontspec, fonts
∵ leothelion ∴ 2023-07-09 ∞ 7'
I regularly help people out with their LATEX grievances, and one occasion I was met with this question:
I’m trying to use LXfonts in LuaTEX, but it’s so outdated that it only has Type 1 fonts, and even among those I don’t know where to find the font containing the regular characters. The documentation doesn’t help either since it’s outdated too. Is there a direct or easier way of using its package on LuaTEX?
I’m an avid user of fontspec and have written a CLI tool to ease its use of and incorporating the knowledge of OpenType fonts, but I’ve never tried to load Type 1 fonts through fontspec.
How do you manipulate Type 1 fonts with fontspec in LuaTEX? This will be the topic of this post.
First of all, there’s a lot going on when it comes to fonts and TEX. For the taskmasters of LATEX, nitty-gritty details of the fonts we load are not of significant concern. Often are font selections limited to a few popular choices----pxfonts, stix, or the plain old Computer Modern. Perhaps we take for granted the fonts we load, and the unseen iceberg of complexity in older fonts like lxfonts. This is particularly true for when we are using pdfTEX----where the fonts we load are in some obscure format many of us have no idea about, such as .pfa, .pfb or .tfm. When we venture into the fonts directory of our TEX distribution, we are met with a peculiar list, particularly for the incognoscenti:
$ ls
afm cid cmap enc lig map misc ofm opentype ovf ovp pk sfd source tfm truetype type1 type3 vf
Aside from the obvious truetype and opentype, what do the other ones mean? This 2014 post from TeX.SE gave me a good overview of what some of these might be:
| Name | Description |
|---|---|
afm | Adobe Font Metrics, a text file that contains information about the metrics of a font. |
cid | a format for describing fonts that contains glyphs for CJK characters, provided by fontforge (see e.g., here) |
cmap | seems to contain character mappings, particularly for CJK fonts. |
enc | contains encoding files, which map character code to glyph indices. |
lig | contains ligature files---supposedly for use with fontspec. |
map | helps TEX figure out which font file corresponds to which font, and whether the font encoding has been altered in any way. |
ofm/tfm | contain TEX font metrics files, which are often generated from afm or pfm files. In the context of TEX, these are proper fonts but do not contain actual glyphs (see type1) |
pk | pre-prepared fonts based on METAFONT sources |
sfd | stands for spline font database, which is a font format used by FontForge. As far as TEXLive 2024 is concerned, it seems to contain subfont database for mapping CJK fonts for something. |
source | contains METAFONT source files for generating pre-prepared fonts |
type1 | contains only the pictures of the characters, so these are fairly useless without some metric information. These therefore go hand-in-hand with ofm and tfm files. |
This suggests that any PostScript (PS) Type 1 font actually comprises multiple files, contrary to OpenType (.otf, .otc) and TrueType (.ttf, .ttc) fonts which are single files (see Phinney, 1997).
LXFonts is a package that provides a set of fonts for use with TEX. It is a collection of SliTEX fonts that are based on the Computer Modern fonts with restyled maths fonts, specifically the letters (maths italics, upper and lower Greek); symbols for uppercase calligraphic letters; and the delimiters for large delimiters and operators. The package is just over 10 years old, is largely unmaintained.
Typically, in conjunction with fontspec, the way to load a font is to simply use the font name, or the file name of a font. If we wanted to load a package-less font, such as Baskervaldx, we can look for its files as follows:
# $TEXMFDIR/fonts
fd -e otf -e ttf baskervaldx
opentype/public/baskervaldx/Baskervaldx-Bol.otf
opentype/public/baskervaldx/Baskervaldx-BolIta.otf
opentype/public/baskervaldx/Baskervaldx-Ita.otf
opentype/public/baskervaldx/Baskervaldx-Reg.otf
This is straight forward, it’s a single directory, with a single or a couple OTF files. When we look for a directory named lxfonts, this is not so evident:
# $TEXMFDIR/fonts
$ fd -t dir lxfonts
map/dvips/lxfonts/
source/public/lxfonts/
tfm/public/lxfonts/
type1/public/lxfonts/
For example, the tfm directory contains the following files:
# $TEXMFDIR/fonts/tfm/public/lxfonts
$ tree
.
├── lcmbsy8.tfm
├── lcmex8.tfm
├── lcmmi8.tfm
├── lcmmib8.tfm
├── lcmsy8.tfm
├── leclb8.tfm
├── lecli8.tfm
├── leclo8.tfm
├── leclq8.tfm
├── llasy8.tfm
├── llasyb8.tfm
├── llcmss8.tfm
├── llcmssb8.tfm
├── llcmssi8.tfm
├── llcmsso8.tfm
├── lmsam8.tfm
├── lmsbm8.tfm
├── ltclb8.tfm
├── ltcli8.tfm
├── ltclo8.tfm
└── ltclq8.tfm
1 directory, 21 files
While not shown here, there’s a combination of files to provide lxfonts. Specifically we find .mf, .pfb, .tfm and .map. As a zoomer, I have no idea what these are, and what they do. What we do know is that .tfm files contain designations to glyphs, but not the glyphs themselves. Perhaps we can use these .tfm files to load the fonts in fontspec?
Here is what I found—Loading the .tfm works! The manner in which we load fonts in fontspec does not accommodate the loading of Type 1 fonts—indeed—but trial and error suggests that designating fontspec to load the tfm files by specifying the extension, followed by the font name, works. The following example is a successful example at precisely that:
\setmainfont{lecl}[
Extension = .tfm,
UprightFont = *q8,
ItalicFont = *i8,
BoldFont = *b8,
BoldItalicFont = *o8
]
lecl takes the cakeWith further testing, I found that lecl is the font we should designate as the text font. While llcmss is the suggested one in the lxfonts documentation, lecl is EC or T1 encoded thus contains twice as many glyphs (256) than the OT1 encoded llcmss (128). We don’t want to introduce more headaches by having to deal with legacy encoding issues, so it makes most sense to select lecl.
lcmmiOn that note, it is possible to mix-and-match, such as using lcmmi. According to the source file, lxfonts provides lcmmi which are "math-as-text" fonts. We can thus consider replacing *i8 with lcmmi8.
Upon cross-examining with the source .dtx file with the list of fonts available, others listed relate to mathematical symbols—we will not worry about that with fontspec.
This post concerns the loading of old Type 1 fonts with a modern font loader: fontspec in LATEX using lxfonts as an example. I talked briefly on legacy and modern font file formats, and how they are structured, and how they are loaded in LATEX.
I found that the .tfm files of the Type 1 font can be loaded, such as lecl in the case of lxfonts.
Phinney, Thomas (1997). TrueType & PostScript Type 1: What's the Difference? link.