9

I'm trying to use XeLaTeX to typeset a word in EB Garamond, and I want only two of the letters in the word to have swashes. However, the swashed characters screw up the letterspacing:

\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont[LetterSpace=40]{EB Garamond}
\begin{document}
% No swashes, correct letterspacing:
\emph{ANAGRAMME.}

% Two swashes, incorrect letterspacing:
\emph{\addfontfeature{RawFeature=+swsh}A\addfontfeature{RawFeature=-swsh}NA\addfontfeature{RawFeature=+swsh}G\addfontfeature{RawFeature=-swsh}RAMME.}
\end{document}

output of the example code

How can I make the letterspacing consistent around the swashed glyphs?

2
  • 2
    Letter spacing doesn't work across font changes.
    – egreg
    Oct 26, 2014 at 21:29
  • 2
    It is notable that this is possible with pdfTeX if the fonts are set up appropriately to support it. That is, if swashes are realised as ligatures, you can use the letter spacing facilities of microtype to do this because no font change is required. [There is a price in terms of control when you switch from traditional TeX fonts to the use of system fonts.]
    – cfr
    Oct 26, 2014 at 21:51

1 Answer 1

7

Letter spacing can't work across font changes. You have to emulate it with an explicit kern. Since the font is at 12pt, LetterSpacing=40 corresponds to adding a 4.8pt kern between letters.

\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont[LetterSpace=40]{EB Garamond}
\begin{document}
% No swashes
\emph{ANAGRAMME}

% Two swashes
\emph{\addfontfeature{RawFeature=+swsh}A\kern4.8pt
  \addfontfeature{RawFeature=-swsh}NA\kern4.8pt
  \addfontfeature{RawFeature=+swsh}G\kern4.8pt
  \addfontfeature{RawFeature=-swsh}RAMME}
\end{document}

enter image description here

3
  • Thanks! In my document I may need to do this with texts of various font sizes and letterspacing values. What's the formula for calculating the kerning in the general case?
    – Psychonaut
    Oct 27, 2014 at 6:02
  • 1
    @Psychonaut <letter spacing factor> * <font size>/10
    – egreg
    Oct 27, 2014 at 7:43
  • I didn’t try this example until today, so I don’t know how TeX Live 2014 behaved, but at least in 2015, luatex seems to get letterspacing right across these font changes. That’s surprising but very welcome! xetex, which the OP asked about, still needs the explicit kerns.
    – Thérèse
    Aug 20, 2015 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .