I'm using KOMA-Script with pdflatex
(might want to switch to lualatex
eventually) to typeset my thesis and want to use EBGaramond as a font. To this end I am loading the ebgaramond-maths
package, which in turn loads the ebgaramond
package. The latter offers various styles of the font, including different number figures. I really like the default old-style figures in the body text, but I don't think they lend themselves too well for headings. So I want to change the number style only in the headings and TOC. The ebgaramond
README
gives us the following ways to choose a style:
To use, add
\usepackage{ebgaramond}
to the preamble of your document. Options include:
oldstyle
,osf
old-style figureslining
,nf
,lf
lining figures[…] Commands
\oldstylenums{...}
and\liningnums{...}
are defined to allow for local use of old-style figures or liningfigures, respectively.
Changing the style globally is not an option, so we're left with using \liningnums{}
. How do I use it correctly with KOMA-Script?
I've tried various methods, to no success:
- The first intuition would be to use
\addtokomafont
\addtokomafont{disposition}{\rmfamily\liningnums{}}
(\rmfamily
because I want serif style headings). This works for \chapter
s but not \section
s in the MWE, but it doesn't work in my actual document and throws
! Paragraph ended before \text@command was complete.
I don't know what's messing with it here, but it's also discouraged by the KOMA-Script documentation (section 3.6):
Sometimes, although this is not recommended, the font setting of an element is used for settings that are not actually related to the font. […] However, you should not take these commands as legitimizing the insertion of arbitrary commands in an element’s font setting. To do so can lead quickly to errors (see section 21.5, page 476).
- According to this related answer, one should change
\chapterlinesformat
and the like
\renewcommand\chapterlinesformat[3]{\liningnums{#2#3}}
\renewcommand\sectionlinesformat[3]{\liningnums{#2#3}}
% ...
But this doesn't work either. When I only set \chapterlinesformat
it works for \chapter
s but messes with the font styles. In the TOC, the \chapter
font is set to sans-serif Computer Modern, while \section
and \subsection
is left at serif Garamond. In the main document however it's exactly opposite: \chapter
has the correct lining figures and is correctly typeset in Garamond, but now the \section
and \subsection
are in sans-serif Computer Modern. If dare to add the sectionlinesformat
line, I get the error
! You can't use `\glueexpr' in horizontal mode.
How do I correctly tell KOMA-Script to use liningnums{}
for headings in the body text and TOC? No hacks please, I want a clean KOMA-Scriptonic solution.
Minimal (not)Working Example:
\documentclass{scrreprt}
%\addtokomafont{disposition}{\rmfamily\liningnums}
\renewcommand\chapterlinesformat[3]{\liningnums{#2#3}}
%\renewcommand\sectionlinesformat[3]{\liningnums{#2#3}}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{ebgaramond-maths}
\begin{document}
\tableofcontents
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\end{document}