1

Say I have turned on 'discretionary' ligatures with \fontspec[Ligatures=Rare]{Junicode} but want to disable the st and the ct ligatures; is that possilbe?

Toothrot
  • 3,346

1 Answers1

5

In TeX ligatures can be broken up by inserting an explicit kern between the letters. For instance, to prevent the st ligature, we might write s\kern0pt t instead. This is tedious though, but fortunately xetex offers the concept of charclasses, which comes with the possibility of inserting custom tokens between characters, previously assigned to a class.

We proceed to define two classes, one for c and s and one for t:

\newXeTeXintercharclass\charclasscs
\newXeTeXintercharclass\charclasst

Then we assign the characters to these classes

\XeTeXcharclass`\c\charclasscs
\XeTeXcharclass`\s\charclasscs
\XeTeXcharclass`\t\charclasst

If in a character combination the left character is of class \charclasscs and the right of \charclasst, then we want to insert the kern \kern0pt

\XeTeXinterchartoks\charclasscs\charclasst={\kern0pt}

Finally we enable the functionality with

\XeTeXinterchartokenstate=1 % or 0 to disable

A complete example would read

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=Rare]{Junicode.ttf}
\newXeTeXintercharclass\charclasscs
\newXeTeXintercharclass\charclasst
\XeTeXcharclass`\c\charclasscs
\XeTeXcharclass`\s\charclasscs
\XeTeXcharclass`\t\charclasst
\XeTeXinterchartoks\charclasscs\charclasst={\kern0pt}
\begin{document}
st ct
\XeTeXinterchartokenstate=1
st ct
\end{document}

enter image description here

To restore hyphenation you'd have to use something more complicated

\XeTeXinterchartoks\charclasscs\charclasst={%
  \penalty10000\discretionary{-}{}{\kern0pt}%
  \penalty10000\hskip0pt\relax}

For completeness, here a solution using luatex and the selnolig package.

\documentclass{article}
\pagestyle{empty}
\usepackage{fontspec,selnolig}
\setmainfont[Ligatures=Rare]{Junicode.ttf}
\nolig{ct}{c|t}
\nolig{st}{s|t}
\begin{document}
st ct
\end{document}
Henri Menke
  • 109,596