3

I'm using XeLaTeX to compile a document, and I'm quite confused. I noticed that the character (the en dash) shows up as a normal in the main document, but as -- (two hyphens) when written with a font family I defined, although they are using the same font. Here's a MWE to show what I mean:

\documentclass[]{article}

\usepackage[]{fontspec}
\usepackage[english,ngerman]{babel}

\setmainfont[SizeFeatures={Size=12]{CMU Sans Serif}
\newfontfamily\somefontfamily[SizeFeatures={Size=12}]{CMU Sans Serif}

\begin{document}

{\somefontfamily The -- looks strange}

But here -- it looks just fine.

\end{document}

Why is there a difference, even though I'm using the same font?

  • 1
    Add the option Ligatures=TeX. – Ulrike Fischer Jun 15 '17 at 22:05
3

The fontspec package reads fontspec.cfg (in a standard directory, so it can be locally overridden), which contains

\defaultfontfeatures
 [\rmfamily,\sffamily]
 {Ligatures=TeX}

\defaultfontfeatures
 [\ttfamily]
 {WordSpace={1,0,0},
  HyphenChar=None,
  PunctuationSpace=WordSpace}

This means that Ligatures=TeX is only applied to \setmainfont and \setsansfont; other features are applied for \setmonofont.

Such default features might not be desired for other font families, thus you have to add Ligatures=TeX yourself to other declared families. So

\newfontfamily\somefontfamily[Ligatures=TeX,SizeFeatures={Size=12}]{CMU Sans Serif}

or (new syntax)

\newfontfamily\somefontfamily{CMU Sans Serif}[
  Ligatures=TeX,
  SizeFeatures={Size=12}
]

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.