4

I use XeLaTeX, fontspec and unicode-math. When I put some math in the header of a theorem, it is typeset in the default Latin Modern font, instead of the custom font set up with \setmathfont.

See the following MWE :

%!TeX program = xelatex

\documentclass{article}

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

\usepackage{mathtools}

\RequirePackage{unicode-math}
\setmathfont{Libertinus Math}

\RequirePackage[hyperref,amsmath,thmmarks]{ntheorem}
\theorembodyfont{\normalfont}
\theoremheaderfont{\sffamily\scshape\bfseries}
\theoremstyle{break}
\newtheorem{example}{Example}

\newcommand{\Set}{\mathbf{Set}}

\begin{document}

\begin{example}[monomorphisms in $\Set$]
Some text involving $\Set$.
\end{example}

\end{document}

which produces:

output of the MWE

Instead of this, I would like one the two following behaviours in the header of the example:

  1. \Set is typeset using my math font, Libertinus Math, as it is in the body of the example.
  2. \Set is typeset using my sans serif font, so that it fits into the header of the theorem.

Has anybody an idea of how to solve this? Thanks a lot in advance!

2
  • 2
    Have you tried \setmathfontface{\mathbf}{Libertinus Sans Bold} or \setmathfontface{\mathbf}{Linux Libertine O Bold} (whichever you prefer) to set the \mathbf font?
    – frabjous
    Aug 15, 2022 at 19:29
  • It works, thanks a lot (with the Semibold series instead of Bold to mimic the default behaviour)! But I wonder what is the reason why this is not what is done by default by unicode-math. Aug 15, 2022 at 19:40

2 Answers 2

3

I suggest you use \symbf (a macro provided by the unicode-math package) instead of \mathbf.

For the following screenshot, we have \setmathfont{Libertinus Math}. And, because no text font is loaded explicitly, \mathbf employs the default bold Latin Modern glyphs, not the Libertinus Math glyphs. In contrast, \symbf does use the bold Libertinus Math glyphs.

enter image description here

%!TeX program = lualatex  %% or xelatex
\documentclass{article}

\RequirePackage{unicode-math}
\setmathfont{Libertinus Math}

\begin{document}
$\mathbf{Set}$ $\symbf{Set}$
\end{document}
2
  • Thanks for the answer, it's perfect so! And you also answered to my answer to @frabjous' comment, thanks. :-D Aug 15, 2022 at 19:50
  • @sparusaurata - You're most welcome.
    – Mico
    Aug 15, 2022 at 19:52
2

Most of the times, such problems are due to ntheorem; this is one case. Use amsthm.

%!TeX program = xelatex

\documentclass{article}

\usepackage{mathtools}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{amsthm}

\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmathfont{Libertinus Math}

\newtheoremstyle{sfbreak}
  {\topsep}     % ABOVESPACE
  {\topsep}     % BELOWSPACE
  {\normalfont} % BODYFONT
  {0pt}         % INDENT
  {\sffamily\scshape\bfseries} % HEADFONT
  {.}           % HEADPUNCT
  {\newline}    % AFTER HEAD SPACE
  {\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}} % HEAD SPEC
\theoremstyle{sfbreak}
\newtheorem{example}{Example}

\newcommand{\Set}{\mathbf{Set}}

\begin{document}

\begin{example}[monomorphisms in $\Set$]
Some text involving $\Set$.
\end{example}

$\mathbf{Eff}\neq\symbf{Eff}$

\end{document}

Note that for your usage \mathbf is preferable to \symbf as the example shows: you do want the ligature.

enter image description here

You must log in to answer this question.

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