# "fj" Ligature in Computer Modern

The simplest way to put this: I need "fj" ligature. It is absolutely crucial especially as I am writing in Icelandic it simply cannot be missed, it just if not more common as fi.

Here is what i've found:

\usepackage{Alegreya} This font does include the fj ligature but I really like Computer Modern. I saw a different answer on TeX.SX and found someone who made a good looking one but it had to be invoked with \fj. I think that would be really silly.

Any ideas? A helpful fellow on the IRC found this: Computer Modern: extralig package but I wasnt able to get it working, (I got it into path and LaTeX loaded the package just fine but it did absolutely nothing)

• latex really has no control over this, it is purely a feature of the fonts used. The extralig package you link to is metafont (bitmap) font sources so probably not what you want. There must be other fonts than Alegreya that have the ligature (if you use luatex or xetex you can use any opentype font you have on your system) Oct 3, 2020 at 22:50
• Oct 3, 2020 at 22:54
• and perhaps this ? tex.stackexchange.com/a/261293/15036 Oct 3, 2020 at 22:55
• Apparently the fj ligature is missing from Unicode.... Oct 3, 2020 at 22:58
• I'm thinking the best option would be to do this through virtual font support. You could define a virtual font that maps straight to computer modern but adds in ligatures that map f+j-> f+\j and ff+j to ff+\j it doesn't appear that this can be done outside editing font metrics though. Oct 4, 2020 at 2:57

This really needs to be addressed in the font, you could try to edit latin modern in fontforge or similar to add the ligature, but simplest is to pick a font that has it.

This is using Stix 2 text font with lualatex (or xelatex would also work)

\documentclass{article}

\usepackage{fontspec}
\setmainfont{STIX2Text-Regular.otf}

\begin{document}

\mbox{f}i\mbox{f}j

fifj

\end{document}

• Wow, this looks absolutely beautiful. Reading on the STIX Github repository, they mention that I should be able to use it directly via LaTeX with their Type 1 fonts. Thank you so so much STIX is a godsend. Oct 3, 2020 at 23:47
• I tried using \usepackage{stix2} and it does not load the ligatures for fj :/ Oct 3, 2020 at 23:50
• I used the overleaf template and after some tweaking it worked perfectly. Thank you so much. Im using XeLaTeX now. Oct 4, 2020 at 0:54
• @user224041 with respect the the pdflatex/type 1 version you can not add fj to a standard tex T1 encoded font as there are no free slots., as Don H comments under the question you could make a virtual font for a custom encoding that gave up some character you don't need to have a slot for the fj and ffj ligatures, but in a unicode font of course there is more space available. Oct 4, 2020 at 9:53

after having had used STIX2 which looks good but a little too heavy/bold for my taste, I had a dream yesterday night. It was the solution. By using a hack with manual kerning and creation of the fj ligature and \extraligfj command and with LuaLaTeX on-the-fly text-replacement I have created a seamless solution.

\ProvidesPackage{extralig}
\usepackage{xcolor}
\usepackage{luacode}
\newcommand{\extraligfj}{fi\llap{\textcolor{white}{\rule[-0.05em]{0.252em}{0.55em}}}\kern-0.01em\llap{\j}\kern-0.05em\relax}
\begin{luacode}
local function vartosrcvar ( line )
return string.gsub(line, "fj" , "\\extraligfj{}")
end
\end{luacode}


By saving this code as extralig.sty in your .tex file directory and calling it with \usepackage{extralig} it will work perfectly!

Obviously because of the Lua code you must compile this with LuaLaTeX

You are not required to use this as a package, simply copy everything into your document in corresponding places and it will work fine too but its much cleaner to have it as a seperate package.

How does this work?

• I define \extraligfj, a hack where the i in fi is replaced with a j, making a perfect fj ligature with some manual kerning. (Thanks to this TeX.SX post!)
• With LuaLaTeX, I use code which replaces all instances of fj with \extraligfj, which we defined before.
• This is all placed neatly inside of extralig.sty and ready to be seamlessly loaded into our document as a package.

TL;DR Save the code snippet as extralig.sty and place it the same directory as your .tex file and load it with \usepackage{extralig}. use LuaLaTeX. This is only guaranteed to work with Computer Modern, no other fonts (they will need manual kerning adjustment). Doing this then fj will automagically be ligatured.

Pros:

• I was expecting there to be some really weird glitches with linebreaks due to the nature of the hacked glyph, but to my surprise, it works perfectly even when broken in lines at f and j
• Only need to compile once because LuaTeX runs it on the fly, which is why its fully seamless, no slowdowns.
• Actually, this solution isnt perfect yet. There appears to be a space before fj appear, which sucks when its used inside of a word. Im still investigating. Oct 20, 2020 at 1:48
• FIXED: It was a single space before \\extraligfj Oct 20, 2020 at 1:51
• yes main issues with these kinds of solutions are that cut and paste of the text will show the underlying fij (you should probably use an ActualText annotation to make that work), searching for the word in the pdf will fail for similar reasons, and as you have used input buffer things like \includegraphics{hfjmm} will break, it would be safer to use a callback at the node level, or use luatex's Lua access virtual font structures so that you only affect typeset text. Oct 20, 2020 at 11:11
• Hm. I did not think of that and you are right. Im not sure I understand exactly what you mean but ive been looking at something like this Oct 20, 2020 at 13:30