I'm writing a document using xelatex
and have set up my document fonts using fontspec
as follows:
\usepackage{fontspec}
\setmainfont[Mapping=tex-text,Numbers=OldStyle]{Linux Libertine O}
\setsansfont[Mapping=tex-text,Numbers=OldStyle,Scale=MatchLowercase,SmallCapsFont={Linux Biolinum Capitals O}]{Linux Biolinum O}
\setmonofont[Mapping=tex-text,Scale=MatchLowercase]{DejaVu Sans Mono}
In my document, I'd like the math font to use either Linux Libertine or Linux Biolinum based on whether the surrounding text font is serif or sans serif. For example:
\normalfont This text is Linux Libertine as is the following math: $a^2 + b^2 = c^2$.
\sffamily This text is Linux Biolinum as is the following math: $a^2 + b^2 = c^2$.
Here's what I've tried so far and the components of the problem I'd like to solve:
The normal math text should be set in Linux Libertine, not Computer Modern. CM can serve as a fallback provide any glyphs that LL doesn't provide, however (e.g., large symbols and operators, but not Greek letters). The
mathspec
package handles this requirement fairly well.If the surrounding body text is set in sans serif (this is used for tables, figures, and captions), then the math should be set in sans serif. I'd prefer this be done automatically, but I don't mind adding a
\sfmath
command (or the like) if necessary. Unfortunately, I couldn't figure out how to coercemathspec
into handling this part.
A few things to note:
Neither Linux Libertine nor Linux Biolinum have much if anything in the Unicode range for math glyphs. Therefore, the Greek letters should be pulled from the Greek alphabet block and not the math Greek block, for instance.
I'm not using
\mathsf
or the math sans alphabet to indicate anything special in this document so there won't be any confusion when the math is set in sans serif solely to match the surrounding text.
The similar questions I've found on TeX.sx appear to be for pdflatex
or to make use of the \mathsf
command.
Asana Math
; it has both serif/italics and sans-serif/upright letters. Give it a try. The match with Libertine/Biolinum is by no means perfect, but it's a whole lot better than what's achievable with the Latin Modern, the XITS, or Cambria math fonts. If you choose to use theAsana
math fonts, you can load them with the commands\usepackage{unicode-math}
and\setmathfont[version=asana]{Asana Math}
.mathastext
is one of the best optionLibertine
. useLibertinus
, it has a math font and is more or less the same asLibertine