# Suppress 2-letter ligature when 3-letter ligature would apply

Automatic handling of ligatures in TeX seems notoriously difficult but I was wondering whether in a font that has an ff and an fl ligature but no ffl one, it was possible to suppress the usage of any ligatures for instances of "ffl" in the text. Example follows:

\documentclass[a5paper,12pt]{article}
\renewcommand*{\sfdefault}{uop}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\thispagestyle{empty}
Muffling affluent waffles baffles sniffling Mifflin.

Muf{}f{}ling af{}f{}luent waf{}f{}les baf{}f{}les snif{}f{}ling Mif{}f{}lin.
\end{document}


As it stands now, the "ffl" words seem unbalanced because of the inappropriate ligature they contain (the "fl" is closer together than the "ff"). Manually fixing every word is not a solution I'd look forward to.

• Run tftopl on the tfm file, delete the ligatures that you don't want then run pltotf to make a (locally modified) tfm. – David Carlisle Apr 27 '14 at 16:15
• Does this answer of mine help? tex.stackexchange.com/a/106446/4427 – egreg Apr 27 '14 at 16:17
• However, you need to define new ligatures if this must be context sensitive. – egreg Apr 27 '14 at 16:21
• @egreg Your answer should help but when I generate a uopb8r.pl, neither 146 (octal code for f) nor 257 (ﬂ) are anywhere to be found. Which is odd because the above example clearly shows that some ligaturing involving the letter "f" is going on and an "ﬀ" ligature doesn't seem to be part of the font according to fontforge. – Christian Apr 27 '14 at 18:03
• You should do tftopl uopr7t, not using the “raw” font. – egreg Apr 27 '14 at 18:09

The font has only the fi and fl ligatures, which are actually unnecessary; the ff, ffi and ffl ligatures are obtained in the virtual font by putting together two f's or an f with fi or fl respectively; here is the relevant part for ffl:

## tftopl uopr7t

First of all, let's look at f:

(CHARACTER C f
(CHARWD R 0.276)
(CHARHT R 0.745999)
(CHARDP R 0.0055)
(COMMENT
(LIG C i O 14)
(LIG C f O 13)
(LIG C l O 15)
[...]


So ff is octal 13:

(CHARACTER O 13
(CHARWD R 0.573)
(CHARHT R 0.745999)
(CHARDP R 0.0055)
(COMMENT
(LIG C i O 16)
(LIG C l O 17)
[...]


Thus ffl is at position octal 17.

## vptovf uopr7t

[...]
(DESIGNSIZE R 10.0)
[...]
(MAPFONT D 0
(FONTNAME uopr8r)
(FONTCHECKSUM O 35406442446)
(FONTAT R 1.0)
(FONTDSIZE R 10.0)
)


This says what font the glyphs are taken from. Let's see octal 17:

(CHARACTER O 17
(CHARWD R 0.834)
(CHARHT R 0.745999)
(CHARDP R 0.0055)
(COMMENT
(KRN C v R -0.019)
(KRN C y R -0.021)
)
(MAP
(SETCHAR C f)
(MOVERIGHT R 0.021)
(SETCHAR O 3)
)
)


This says that the character f is typeset, there is a kern of 0.21pt (the design size is 10pt) and then character octal 3 is used; in the raw font, the fl ligature is there.

The same kerning is applied when building the ff ligature. However, this results in the two f's being farther apart than they would be without the ligature, as your picture shows.

It seems to have been done not too carefully; my suggestion is to disable all f ligatures.

\documentclass[a5paper,12pt]{article}
\usepackage{microtype}

\DisableLigatures[f]{encoding=*,family=uop}

\renewcommand*{\sfdefault}{uop}

\begin{document}
\thispagestyle{empty}

\noindent % show that ligatures are not disabled altogether
Muffling affluent waffles\\
baffles sniffling Mifflin.

\sffamily
\noindent % but only for the classico font
Muffling affluent waffles\\
baffles sniffling Mifflin.

\end{document}


If you're willing to switch from pdfLaTeX to LuaLaTeX, you could employ the selnolig package -- full disclosure: I'm the author of this package :-) -- to easily disable the ff and fl ligatures for words that include the ffl triple. (Words that contain just ff or fl will see the corresponding ligatures preserved.) Ligature suppression can be switched off and back on via the package's \selnoligoff and \selnoligon macros.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Latin Modern Roman}
\usepackage{selnolig} % for this example, load the package *without* a language option
\nolig{ffl}{f|f|l} % suppress both ff and fl ligatures in words that contain ffl
\begin{document}
ffl'' ligature disabled:

Muffling affluent waffles baffles sniffling Mifflin

\medskip
but ff'' and fl'' ligatures still work:

off fly

\selnoligoff % turn off selnolig's work, i.e., re-enable ffl ligature
\bigskip
ffl'' ligature can be re-enabled:

Muffling affluent waffles baffles sniffling Mifflin
\end{document}


Aside: I've used the "standard" Latin Modern fonts in this example since I don't have the "Classico" fonts on my system. Assuming there exists a package named, say, "classico.sty", that loads the Classico font family, you should be able to execute the macros (after loading fontspec) \usepackage{classico} and \renewcommand{\familydefault}{\sfdefault} to use this Classico font under LuaLaTeX.

• It's a perfect solution but unfortunately I at some point gave up on LuaLaTeX for this particular document because it inflicted terrible mayhem on my math. More precisely, unicode-math did IIRC. – Christian Apr 27 '14 at 20:59
• @Christian - Sorry to learn about your troubles with math support under LuaLaTeX. How long ago was this? The unicode-math has been getting loads better of late. By the way, I looked up information about the Classico font; it seems to be based on Zapf's Optima font. Now, Optima provides ligatures only for fi and fl, but not for ff, let alone for ffi and ffl. If that applies to Classico as well, there's no need to try to suppress the non-existent ff ligature; you can concentrate on the easier task of suppressing the fl ligature in words that contain ffl. – Mico Apr 27 '14 at 21:12
• Oh it's been a while. I just tried to compile my document with the TeXLive 2013 lualatex though and it doesn't even compile anymore :/ Some problem in amsthm apparently. Anyway, yes URW Classico is the free clone of Optima but Zapf was somehow still personally involved (that's why I said I didn't want to argue with him earlier ;) and it inherits its lack of ﬀ. I've been fighting the urge to just shell out a couple hundred bucks and buy Optima Nova for years but that would rely on LuaLaTeX working flawlessly with my document. – Christian Apr 27 '14 at 21:20
• @Christian - You may want to consider posting an MWE that asks how to go about fixing whatever is keeping your math stuff from compiling under LuaLaTeX/unicode-math. Somebody may be able to come up with a solution. :-) – Mico Apr 27 '14 at 21:24
• I should probably do that ;) With the amount of packages I'm using, a MWE can take anything between 2 minutes and an hour to make ... okok, I'll get to it. Here's to hoping for a quick one. – Christian Apr 27 '14 at 21:28