Fontspec – Fixing Lining Numbers Not Working in Certain Fonts

fontspecoldstylenums

I’m using the Linux Libertine font and have old style numbers enabled.

However, in a certain context I want to use lining figures instead. Normally I should be able to switch using \addfontfeature but this doesn’t work. MWE:

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{Linux Libertine}

\begin{document}
C++0x

C++{\addfontfeature{Numbers=Lining}0}x

{\fontspec{Linux Libertine}C++0x}
\end{document}

The output looks like this:

C++ox
C++ox
C++0x

However, the second line should look like the third, not like the first. Setting other font features (i.e. slashed zero) doesn’t work either.

Additionally, if I use another font (e.g. Hoefler Text) then the output is as expected.

Does somebody have an idea what’s going on here?

Best Answer

Here's a workaround to your problem (which is a known issue with respect to how adding font features works (see commentary here and here)). The solution is to define a new fontface and use that to change the number style:

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{Linux Libertine}
\newfontface\lining[Numbers=Lining]{Linux Libertine}
\begin{document}
C++0x

C++{\lining0}x

{\fontspec{Linux Libertine}C++0x}
\end{document}

In general if you are going to be switching fonts its best to use the \newfontfamily or \newfontface commands to make the switch into a macro rather than calling fontspec directly.