6

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: without-libertine

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

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?

2
  • 1
    Try removing your \oldstylenums and loading the libertine package with osf.
    – TeXnician
    Commented Jul 30, 2018 at 19:56
  • @TeXnician oh wow, removing \oldstylenums worked! Commented Jul 30, 2018 at 19:58

3 Answers 3

5

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

biolinum

\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
    {\addfontfeature{Numbers=OldStyle}\thechapter}}
  {1em}
  {\filright}

\begin{document}
\chapter{Chapter 1}
\end{document}
2
  • (Still need to wait 5 minutes to accept your answer. Thanks again for the tweak, it looks even better!) Commented Jul 30, 2018 at 20:01
  • @IgalTabachnik You're welcome. These are the parts of LaTeX's behaviour the end user will never expect :)
    – TeXnician
    Commented Jul 30, 2018 at 20:03
5

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.
\renewcommand\oldstylenums[1]{{\addfontfeatures{Numbers=OldStyle}{#1}}}
\renewcommand\liningnums[1]{{\addfontfeatures{Numbers=Lining}{#1}}}

\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}

Oldstyle numbers in Libertine and Biolinum

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{}.

4

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}

enter image description here

You must log in to answer this question.

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