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?

  • 1
    In luatex, yes, with selnolig or by writing your own feature file. With xetex, I don’t know of a way, which doesn’t mean that none exists. – Thérèse Feb 1 '16 at 12:14
  • @Thérèse One could use \XeTeXinterchartoks to insert \kern0pt bewteen the pairs s/t and c/t to prevent the ligature. – Henri Menke Feb 1 '16 at 22:33
  • @HenriMenke, wouldn't this disturb st and ct in command names? – Toothrot Feb 1 '16 at 22:35
  • 1
    @Lawrence No. Charclasses aren't applied on tokenization, but on typesetting. – Henri Menke Feb 1 '16 at 22:41
  • @HenriMenke, ah, I was thinking of active characters. thanks. – Toothrot Feb 1 '16 at 23:07
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}
  • There is a serious side-effect to this, it breaks hyphenation, causing un-der-stand-ing to be broken un-derstanding. – Toothrot Feb 12 '16 at 18:23
  • @Lawrence See the comment below the picture in my updated answer. – Henri Menke Feb 12 '16 at 18:50
  • 2
    @Lawrence The hyphenation will be awkward, though, because un-der-stand-ing will be hyphenated un-ders-tand-ing. Better use the LuaTeX solution. Mico's package selnolig is really good. – Henri Menke Feb 12 '16 at 18:54
  • 1
    Trying to switch to luatex … – Toothrot Feb 12 '16 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.