# Using package 'libertine' overrides my sans-font with Libertine instead of Biolinum

I'm trying to use the libertine package instead of using the installed Libertine fonts on my machine (macOS). It seems that after adding the libertine package, it overrides my sans-serif font and uses Libertine instead of Biolinum.

I have the following layout:

\documentclass{book}

\usepackage{fontspec}
% \usepackage{libertine}

\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}

\usepackage{titlesec}

\titleformat{\chapter}[display]
{\normalfont\sffamily\bfseries\LARGE}
{\filright \sffamily\mdseries
\fontsize{10em}{0em}\selectfont
\oldstylenums{\thechapter}}
{1em}
{\filright}

\begin{document}
\chapter{Chapter 1}
\end{document}


If I build this with xelatex, I get the following output:

If I uncomment the \usepackage{libertine}, this will be rendered instead:

The big 1 is rendered with the Libertine font instead of Biolinum, even though the \titleformat block uses \sffamily.

Is there a way I could force the sans-serif rendering?

• Try removing your \oldstylenums and loading the libertine package with osf. – TeXnician Jul 30 '18 at 19:56
• @TeXnician oh wow, removing \oldstylenums worked! – Igal Tabachnik Jul 30 '18 at 19:58

The problem is \oldstylenums which switches the font. Just use the fontspec syntax.

\documentclass{book}

\usepackage{fontspec}
\usepackage{libertine}

%\setmainfont{Linux Libertine O}
%\setsansfont{Linux Biolinum O}

\usepackage{titlesec}

\titleformat{\chapter}[display]
{\normalfont\sffamily\bfseries\LARGE}
{\filright \sffamily\mdseries
\fontsize{10em}{0em}\selectfont
{1em}
{\filright}

\begin{document}
\chapter{Chapter 1}
\end{document}

• (Still need to wait 5 minutes to accept your answer. Thanks again for the tweak, it looks even better!) – Igal Tabachnik Jul 30 '18 at 20:01
• @IgalTabachnik You're welcome. These are the parts of LaTeX's behaviour the end user will never expect :) – TeXnician Jul 30 '18 at 20:03

## The fontspec Way

The libertine package redefines \oldstylenums{} to switch the font. You can change back to a definition like the one from fontspec, which adds the OpenType font feature to the currently-selected font. Note that this is an incompatibility between the libertine and fontspec packages!

\documentclass{book}

\usepackage{fontspec}
\usepackage{libertine}

%% \oldstylenums and \liningums will change the style of the current font, as
%% in fontspec, not switch to the serif font, as in libertine.

\usepackage{titlesec}

\titleformat{\chapter}[display]
{\normalfont\sffamily\bfseries\LARGE}
{\filright \sffamily\mdseries
\fontsize{10em}{0em}\selectfont
\oldstylenums{\thechapter}}
{1em}
{\filright}

\begin{document}
\chapter{Chapter 1}

\oldstylenums{1234567890} vs. \liningnums{1234567890}.
\end{document}


You could alternatively give the command a new, unambiguous name or save the definitions after loading fontspec and before loading libertine.

## The libertine Way

The libertine package provides a second command, \oldstylenumsf{}, to switch the font to Biolinum with old-style numbers. You could simply replace \textsf{\oldstylenums{}} with \oldstylenumsf{}.

The package defines the \biolinumOsF font:

\usepackage{libertine}


and

\titleformat{\chapter}[display]
{\normalfont\sffamily\bfseries\LARGE}
{\filright\mdseries\fontsize{10em}{0em}\selectfont
\biolinumOsF\thechapter}
{1em}
{\filright}