How to modify main font?

I would like to define \textsb command for semibold text as I could not find a package providing one (I very much wonder why it’s not part of the standard commands). I’ve found a nice solution in related answer but I do not want to use \setmainfont as it overwrites settings provided by the libertine package.

So I tried with \addfontfeatures, but unlike with \setmainfont

• it works only after a font is actually selected, i.e. it does not work from a preamble,
• it is forgotten as soon as the family is changed, e.g. after \ttfamily \normalfont.

I would like to know if there is a way to modify mainfont such that it is remembered throughout the document. Or if my approach is completely wrong, is there a more viable way?

\documentclass{scrreprt}
\usepackage[mono=false,oldstyle=true,proportional=true]{libertine}
FontFace = {sb}{n}{LinLibertine_RZah.ttf},
FontFace = {sb}{it}{LinLibertine_RZIah.ttf}
}
\DeclareOldFontCommand{\sbseries}{\fontseries{sb}\selectfont}{\mathbf}
\DeclareTextFontCommand{\textsb}{\sbseries} % {\sbseries foo} \textsb{bar}

• \DeclareOldFontCommand is just for defining the old 2-letter commands such as \bf for compatibility with latex2.09, you shouldn't need it here, a more normal definition for \sbseries would be \newcommand\sbseries{\fontseries{sb}\selectfont} as that would match other \..series commands. – David Carlisle Jul 7 '18 at 16:52
• the reason that the setting is forgotten after \ttfamily etc is because \DeclareOldFontCommand defines commands that do not combine \bf\it is normal weight italic, not bold italic, for compatibility with latex2.09 font commands. – David Carlisle Jul 7 '18 at 16:54
• @Davislor I just looked at the link now, the only mention I can see of oldfontcommand in the comments is cfr correctly saying it is wrong to use it: \DeclareOldFontCommand is not intended to be used in this way – David Carlisle Jul 8 '18 at 8:31
• @DavidCarlisle Either a comment was deleted or (more likely) I misunderstood what I read in 2015. i should go back and update that answer, when I get the chance. Thanks. – Davislor Jul 8 '18 at 9:10

I'm glad you found my answer from 2015 helpful, but it's not the best example of how to use the Linux Libertine font in practice. (You could, however, duplicate all the options you selected with the Numbers= font feature of fontspec if you wanted.) I picked the examples I did because they were fonts that contained a semibold series and were present in the TeX Live distribution as both Type 1 and OTF.

Here is an answer compatible with the package. Ulrike Fischer beat me to it (+1), but this one is a little more minimal and uses the font you want. It also works whether you change the main font or use \libertine. So, I hope it's still useful along with hers.

\documentclass[varwidth, previeww]{standalone}

\usepackage{fontspec}

\defaultfontfeatures[LinLibertine]{
FontFace = {sb}{n}{LinLibertine_RZ.otf},
FontFace = {sb}{it}{LinLibertine_RZI.otf}
}

\usepackage[mono=false,
oldstyle=true,
proportional=true]{libertine}

\newcommand\sbseries{\fontseries{sb}\selectfont}
\DeclareTextFontCommand{\textsb}{\sbseries}

\begin{document}

Linux Libertine \textbf{bold \textit{italic}}
\textsb{semibold \textit{italic}}

\end{document}


It is also possible to use \defaultfontfeatures[\rmfamily]{...}, \defaultfontfeatures[\sffamily]{...}, and so on.

Also be aware that the package declares a \libertineSB font family that can be used without fontspec, or supports the sb package option to replace bold with semibold.

• I’m glad that you updated the answer for 2018 and also for mentioning \libertineSB. I’m aware of sb but it seems to fail with \description environment, where \items are still in bold (and bold in Libertine is like a punch in the eye). I also find the approach of completely eliminating one font weight in favor of another a bit too radical. Fortunately, there is an answer for almost everything at SE ;-) – Mr. Tao Jul 8 '18 at 11:02
• With regard to my previous comment – of course, \items are in Biolinum, for which there is no semi-bold variant. – Mr. Tao Jul 8 '18 at 11:20

I don't have the fonts but something like this should work (replace arial by your fonts and adjust the font features if needed):

\documentclass{scrreprt}

\usepackage{fontspec}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,NFSSFamily=libertine}
\usepackage[mono=false,oldstyle=true,proportional=true]{libertine}

\DeclareFontShape{TU}{libertine}{sb}{n}{<->s*[1] [arial.ttf]:mode=node;script=latn;language=DFLT;+tlig;+pnum;
+onum;+smcp;}{}

\DeclareFontShape{TU}{libertine}{sb}{it}{<->s*[1] [ariali.ttf]:mode=node;script=latn;language=DFLT;+tlig;+pnum;
+onum;+smcp;}{}

\DeclareRobustCommand\sbseries{\fontseries{sb}\selectfont}
\begin{document}

some text {\sbseries some text \itshape some text}

\ttfamily some text {\sbseries some text \itshape some text}

\rmfamily some text {\sbseries some text \itshape some text}

\end{document}


• This certainly works (after adjusting features and font) and provides some food for thought. Of course, some parts of \DeclareFontShape are more of an incantation to me, so I’ve dug in font selection, the loading-info part brought me to luaotfload and then I’ve landed back on SE. It’s like realizing you’ve got lost in Wikipedia at 3 AM 🤓 – Mr. Tao Jul 8 '18 at 10:41