Fonts & Character SetsNo ligatures, hyphenation, or kerning using custom ttf font

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
bigm
Posts: 2
Joined: Tue Oct 27, 2009 4:31 am

No ligatures, hyphenation, or kerning using custom ttf font

Post by bigm »

Hi all!

I have recently started experimenting with LaTeX and have come to a point where I need to use my custom fonts with pdfLaTeX. I know I would have less trouble with XeLaTeX but I would like to be able to use the microtype package. I managed to convert my custom fonts to use with LaTeX, but I seem to have lost important functionality!

According to these two tutorials
http://fachschaft.physik.uni-greifswald ... h/ttf.html
http://existentialtype.net/tag/ttf2tfm/
I processed my ttf font files with ttf2afm and afm2tfm.

Code: Select all

ttf2afm -e custom.enc -o GoudyBkltModernR.afm GoudyBkltModernR.ttf
afm2tfm GoudyBkltModernR.afm -t custom.enc
Because I have non-standard ligatures (most notably a "Th" ligature), I used a customized encoding (attached as "custom.txt" - the forum server would not allow the .enc extension). There were some warnings about missing glyphs but none of those was a ligature.

I built a custom.map file, with one entry for each font series/shape, like:

Code: Select all

GoudyBkltModernR <custom.enc <GoudyBkltModernR.ttf
I then built a uenc.def file declaring the new encoding and a few character shortcuts:

Code: Select all

\ProvidesFile{uenc.def}
\DeclareFontEncoding{U}{}{}
\DeclareTextSymbol{\textasteriskcentered}{U}{42}
\DeclareTextSymbol{\textbackslash}{U}{92}
\DeclareTextSymbol{\textcopyright}{U}{254}
\DeclareTextSymbol{\textmult}{U}{255}
And lastly I composed an .fd file:

Code: Select all

\ProvidesFile{UGoudyBookletter1911.fd}
\DeclareFontFamily{U}{GoudyBookletter1911}{}
\DeclareFontShape{U}{GoudyBookletter1911}{m}{n}{ <-> GoudyBkltModernR}{}
\DeclareFontShape{U}{GoudyBookletter1911}{b}{n}{ <-> GoudyBkltModernB}{}
\DeclareFontShape{U}{GoudyBookletter1911}{m}{it}{ <-> GoudyBkltModernIt}{}

\DeclareFontShape{U}{GoudyBookletter1911}{mo}{n}{ <-> GoudyBkltOldstyleR}{}
\DeclareFontShape{U}{GoudyBookletter1911}{bo}{n}{ <-> GoudyBkltOldstyleB}{}
\DeclareFontShape{U}{GoudyBookletter1911}{mo}{it}{ <-> GoudyBkltOldstyleIt}{}

\DeclareFontShape{U}{GoudyBookletter1911}{bx}{n}{ <->ssub* GoudyBookletter1911/b/n}{}
\DeclareFontShape{U}{GoudyBookletter1911}{m}{sl}{ <->ssub* GoudyBookletter1911/m/it}{}
\DeclareFontShape{U}{GoudyBookletter1911}{b}{it}{ <->ssub* GoudyBookletter1911/b/n}{}
In my preamble I replaced the default encoding, map, and font with

Code: Select all

\usepackage[U]{fontenc}
\pdfmapfile{+custom.map}
\renewcommand{\rmdefault}{GoudyBookletter1911}
The output has almost everything in place, font series and shapes are fine, but the ligatures don't show up. This stands for both the custom ones as well as for the common such as --- becoming an em dash. In addition, there is no hyphenation or kerning. I also attached an MWE.pdf, highlighting the absence of ligatures and kerning, from this minimal LaTeX code:

Code: Select all

\documentclass{book}%
\usepackage[U]{fontenc}
\pdfmapfile{=custom.map}
\renewcommand{\rmdefault}{GoudyBookletter1911}
\begin{document}
\frontmatter
\chapter{Introduction}
The field offer affinity fluent efflux frozen after fury attention Tell 
\end{document}
Could someone please provide some pointers as to what can be causing this behaviour?

Thanks a lot in advance!
Attachments
custom.txt
Custom Encoding File
(3.43 KiB) Downloaded 352 times
MWE.pdf
Minimal Working Example
(8.73 KiB) Downloaded 446 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
bigm
Posts: 2
Joined: Tue Oct 27, 2009 4:31 am

No ligatures, hyphenation, or kerning using custom ttf font

Post by bigm »

Ok, after a lot of head-banging I came to the solution to the problem.

The issue is that .tfm files produced by ttf2tfm or afm2tfm do not retain ligature and kerning information, although the format does allow for it! This is not mentioned in most documentation or tutorials.

The correct way to go in this case is to generate a .vpl along the .tfm with any of the above progs, then to convert that .vpl into a .vf and a second .tfm pair using vptovf. Pay attention that the .tfm files must have different namings. For the sake of clarity I will refer to the filenames according to the following list:
f.ttf: the source ttf font;
f1.tfm: a .tfm output by either ttf2tfm or afm2tfm;
f1.vpl: a .vpl produced by any of the above programs (using the -v option)
f2.tfm: a .tfm produced by running vptovf on f1.vpl
f2.vf: a .vf produced by running vptovf on f1.vpl

The two .tfm, the .vf and the initial .ttf file are all that is needed, besides a .map file, the encoding .enc file, the encoding .def file, and a font description .fd file. ( :shock: You have to love LaTeX for its simplicity!)

The used .map file must map f.ttf through the encoding file to the f1.tfm (output by ttf2tfm or afm2tfm, not vptovf). The .fd description file must then map the FontShapes to the f2 virtual font (I always give the f2.tfm and f2.vf the same names; because extensions are omitted in the .fd I am not sure if you should refer to the .tfm or the .vf in case you name them differently). Any FontShape mapped to the f1 font will work, but without kerning.

Another possible way is to use tftopl to convert f1.tfm into a human-readable .pl file, which you can then customize to include ligature info and maybe (haven't tried) also kerning. This info is stored in pretty much the same format as in f1.vpl so you can try to just copy it across. The .pl file must then be reconverted to .tfm using pltotf, and then you'll likely get away without having to build a .vf.


I attached a working example, complete with .map, .fd, .enc and .def files using the first approach (which I recommend over the second). The font is a beautiful and public domain Goudy Bookletter 1911 (thus the short name gblt), which I customized for kerning and ligatures. I had to also add an .fd file for the cmr font otherwise the fontenc package goes mad when it sets the encoding to my custom value and then tries to use the default cmr font. Maybe this is just a dirty workaround, but I didn't have time to dig enough in the fontenc docs.

I will be watching this topic and hope to be able to address further questions on the issue.
Attachments
test.rar
Example illustrating the use of a virtual font and a raw conversion to .tfm, both from the same initial .ttf.
(56.74 KiB) Downloaded 417 times
tabado
Posts: 1
Joined: Fri Mar 11, 2011 5:11 pm

Re: No ligatures, hyphenation, or kerning using custom ttf f

Post by tabado »

Thank you for your post, it was very useful.
Post Reply