HCoder.org

Controlling ligatures in LibreOffice.org

For a tiny project of mine (that I’ll publish once it’s ready) I needed to write a short document, and I used LibreOffice.org, as always. I wanted a fancy, old fashioned font for the document, so I headed for Font Squirrel and found a font I liked, Elsie. When I had written several paragraphs I realised that there was a ligature (“fi”) that didn’t display correctly. I really liked the font and I didn’t want to change it, but I couldn’t really use it as-is. So I started looking for ways to disable certain ligatures, or at least ligatures in general.

Disabling ligatures in LibreOffice.org

Looking around on the internet (mostly Stack Overflow) it seemed that at least modern versions of LibreOffice.org, with at least certain types of fonts, could disable at least certain ligatures. Or ligatures in general. Or something.

It wasn’t very clear to me at first, but after digging a bit I saw that fonts define certain “flags” that you can turn on and off. And how do you do so? Through a very ugly hack: you can ask LibreOffice.org to use a font like “Elsie:-liga”, and that’s interpreted as using the Elsie font but disabling the liga flag. Unfortunately, in this case there’s no granularity in the ligatures in this font, so I couldn’t disable just the “fi” ligature. In this case it wasn’t a big deal because the other ligatures were a bit over the top for the body text anyway. As I didn’t have any “fi” in the titles, I’ve left the full font plus all ligatures for the titles.

Finding out the tags for a given font

Now, how do you know which flags are available in a given (OpenType) font? Under Linux you have a collection of utilities called lcdf-typetools which includes a utility called otfinfo. You can read more in How the OpenType font system works, the article where I found this information.

In this case, the output of the tool was:

$ otfinfo -f elsie/Elsie-Regular.otf 
liga	Standard Ligatures
salt	Stylistic Alternates

In this case one can guess that there’s no way to disable just the “fi” ligature, and I just had to use the Elsie:-liga to get rid of all of the ligatures. I could have marked the parts with “fi” and remove ligatures only there, but I thought it wasn’t worth it.

Installing a newer LibreOffice.org

Also, all this only works under LibreOffice.org >= 5.3. Unfortunately, my version was older so the trick didn’t work. However, I have the fantastic Flatpak installed for these cases, so it’s easy to install random versions of random programs without messing with the base packages of the operating system or adding new eg. APT sources. So I went to Flathub and found a recent enough version of LibreOffice.org.

Conclusion

It’s possible to tweak certain characteristics of an OpenType font under LibreOffice.org >= 5.3 through a really ugly hack with the font names. These names can of course be used in styles, so one can define the “Body text” style to use eg. Elsie:-liga instead of simply Elsie to remove ligatures from the body text. For more information about OpenType fonts under Linux, read the article How the OpenType font system works.