1

As above, I'm having difficulty getting small caps and old style numerals to print properly when using CMU Serif with XeTeX.

I'm aware that this is a topic that has been discussed before but I wasn't able to solve my problem using those previous answers. Previous solutions seem mostly to concern fixing a bug in a MikTeX update, and I use TeX Live.

Here's a MWE of my problem. You can obtain the same version of CMU Serif as me from the link above.

\documentclass{amsart}

\usepackage{fontspec}

\setmainfont[Numbers=OldStyle]{CMU Serif}

\begin{document}

Hello, 1234567890!\\

\textsc{goodbye!}

\end{document}

If I run the above through a xelatex main.pdf, the numbers are not old style, and the 'goodbye' is printed in all lower case letters. However, if I change the line setmainfont[Numbers=OldStyle]{CMU Serif} to setmainfont[Numbers=OldStyle]{Linux Libertine O}, everything works - except that it's not in the font I want! This suggests to me that the font files for CMU Serif are the problem. Is that the case?

My current file for "CMU Serif, Roman" contains 700 glyphs. Is that too few? If it is, I'm having trouble tracking down a more complete set of Computer Modern .ttf files.

6
  • 1
    cmu is part of the standard tex distributions you shouldn't need to install it by hand. Using the copy in texlive 2021 on your test ffile (minus the spurious \\ ) I get this output Commented Aug 24, 2021 at 23:58
  • 1
    specifically it is in texlive as /usr/local/texlive/2021/texmf-dist/fonts/opentype/public/cm-unicode/cmunrm.otf Commented Aug 25, 2021 at 0:01
  • 1
    oh check if it works with lualatex xelatex by default can not find texlive fonts by internal font name, so use \setmainfont[Numbers=OldStyle]{cmunrm.otf} Commented Aug 25, 2021 at 0:04
  • @DavidCarlisle Your suggestions worked. Feel free to put it into a proper answer.
    – Tom Hosker
    Commented Aug 25, 2021 at 22:12
  • That might have some trouble finding the other faces, such as bold and italic.
    – Davislor
    Commented Aug 26, 2021 at 0:35

1 Answer 1

3

Loading fonts by file name is currently the recommended way, but simply loading cmunrm.otf will not find the other font faces, such as bold or italic. To enable these, you may use the following:

\documentclass{article}
\usepackage{fontspec}

\defaultfontfeatures[CMUSerif]{
  Ligatures={Common,TeX},
  Numbers=OldStyle,
  UprightFont=cmunrm,
  BoldFont=cmunbx,
  ItalicFont=cmunti,
  SlantedFont=cmunsl,
  BoldItalicFont=cmunbi,
  BoldSlantedFont=cmunbl,
  Extension=.otf}

\setmainfont{CMUSerif}

\begin{document}
\noindent Computer Modern Serif \textit{Italic} \textsl{Slanted} \textsc{Small Caps \textsl{Oblique}}
\textbf{Bold \textit{Italic} \textsl{Slanted} \textsc{Small Caps}}
\end{document}

You may also save the \defaultfontfeatures command to a file named CMUSerif.fontspec, which will allow you to use \setmainfont{CMUSerif} in your documents.

If you need to do the same for sans-serif or typewriter, the index of filenames is here. Another good alternative is to load \usepackage{newcomputermodern}.

You will not need to bother with this extra setup, although it will still work, if XeTeX or LuaTeX is already configured to look up the font by its display name. You can test whether XeTeX has this font in its index with fc-match "CMU Serif", and whether LuaTeX does with luaotfload-tool --find="CMU Serif".

If your Linux system does not find your fonts automatically, locate the configuration file you need with kpsewhich texlive-fontconfig.conf and symlink or copy it to /etc/fonts/conf.d/, or the appropriate directory on your system. You might also want to refresh your font caches with fc-cache -f -s -v and luaotfload-tool -f -u -p -v. You can also install the fonts as system fonts, to be able to use them in all your applications. On Linux, XeTeX and LuaTeX should also be able to find them in your user font directories, so you should be able to put a copy or symlink to a font directory of your TeX tree in ~/.fonts/.

You must log in to answer this question.

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