1

A few months ago, I asked whether the “EB Garamond” font contains a short-arched version of the letter f. I have now found out how to access this letter because it actually exists. Writing

\newcommand\fshort{\XeTeXglyph\the\XeTeXglyphindex "f.short" \relax}

makes it possible to access this letter by writing \fshort.

Writing

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\myreplace}{m}
{
    \tl_set:Nn \l__maxd_argument_tl { #1 }
    \tl_replace_all:Nnn \l__maxd_argument_tl { f } { \fshort }
    \tl_use:N \l__maxd_argument_tl
}
\tl_new:N \l__maxd_argument_tl
\ExplSyntaxOff

will result in the replacement of f with the short-arched version of it when the text is encompassed by \myreplace{}.

This, however, is not very convenient. I would like to globally replace every f character with the short-arched f.

I already tried using catcodes, but they do not work when it comes to (certain) ASCII characters. This answer which contains Cyrillic characters works perfectly fine:

\catcode`\Ё=\active
\defЁ{E}
\catcode`\ё=\active
\defё{e}

But writing something like

\catcode`\f=\active
\deff{\fshort}

or

\catcode`\f=\active
\def f{\fshort}

does not work. Also this question did not solve my problem.


David Carlisle’s solution works!

If you also want to use Q.short in combination with f.short, use the following code which has to be written in that order:

\newcommand\fshortgobble[1]{\XeTeXglyph\the\XeTeXglyphindex "f.short" \relax}

\newXeTeXintercharclass\fclass
\XeTeXcharclass `f =\fclass
\XeTeXinterchartoks 0 \fclass  {\fshortgobble}
\XeTeXinterchartoks \fclass \fclass  {\fshortgobble}
\XeTeXinterchartoks 4095 \fclass  {\fshortgobble}

\newcommand\Qshortgobble[1]{\XeTeXglyph\the\XeTeXglyphindex "Q.short" \relax}

\newXeTeXintercharclass\Qclass
\XeTeXcharclass `Q =\Qclass
\XeTeXinterchartoks 0 \Qclass  {\Qshortgobble}
\XeTeXinterchartoks \Qclass \Qclass  {\Qshortgobble}
\XeTeXinterchartoks 4095 \Qclass  {\Qshortgobble}
2
2

You could use a character class

enter image description here

\documentclass{article}
\usepackage{fontspec}
\newcommand\fshortgobble[1]{\XeTeXglyph\the\XeTeXglyphindex "f.short" \relax}

\newXeTeXintercharclass\fclass
\XeTeXcharclass `f =\fclass
\XeTeXinterchartoks 0 \fclass  {\fshortgobble}
\XeTeXinterchartoks \fclass \fclass  {\fshortgobble}
\XeTeXinterchartoks 4095 \fclass  {\fshortgobble}
\begin{document}

\setmainfont{EB Garamond}

f   ff  difficult football diff biff fence

\XeTeXinterchartokenstate=1

f   ff  difficult football diff biff fence



\end{document}
2
  • Your solution works! Thank you very much. But I do not know for what 0 and 4095 stand for. Do I have to use other numbers when I am also using Q.short as shown in the example I just posted? – Nemgathos Dec 30 '19 at 20:39
  • 1
    @Nemgathos see the xetex manual (texdoc xetex) 0 is the default class (so most letters) and 4095 is the non-letter class (so start of string for example) – David Carlisle Dec 30 '19 at 20:43

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.