I am typesetting a document in XeLaTeX using a serif font for main text, and a sans serif for everything else (section titles, tables etc). For setting of mathematics, I use TeX Gyre Pagella Math. Using fontspec
and unicode-math
, this mostly works fine. I use the etoolbox
package to automatically switch to sans serif for floats. However, mathematics are still typeset in the serif font. I know how to switch to sans serif math (which is available in TGPM) using \mathsf{…}
, but I would like to automate this. I've tried the version=…
option of unicode-math
(in combination with etoolbox
), but I can't figure out how to make that work. I also couldn't figure out how to make this work using etoolbox
directly.
Below is an MWE of my current setup; the point is to have the mathematics in the table content in sans serif as well, which is not the case now. To be clear: I use other Komascript options to set the caption labels to sans serif, but left it out here for brevity. Also, in case it matters, I use Minion Pro and Fira Sans as my actual fonts, but not everyone might have those available.
\documentclass[]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}[%
Ligatures = TeX,%
Numbers = {OldStyle,Proportional},%
]
\setsansfont{TeX Gyre Heros}[%
Ligatures = TeX, %
Numbers = {Lining,Monospaced}, %
Scale = MatchLowercase, %
]
\setmathfont[%
Scale = MatchLowercase,%
]{TeX Gyre Pagella Math} %
\setmathfont[%
version = table,%
Scale = MatchLowercase,%
]{TeX Gyre Pagella Math} %
\usepackage{%
tabularx,%
etoolbox,%
}
% etoolbox
\AtBeginEnvironment{tabularx}{%
\sffamily\addfontfeature{Numbers={Lining, Monospaced}}%
\mathversion{table}
}
\begin{document}
\pagestyle{empty}
\begin{table}[t]
\centering
\caption{$\mathsf{a^{2}+b^{2}=c^{2}}$}
\begin{tabularx}{.6\linewidth}{lrr}
some & text & and some math \\
$a^{2}$ & $+b^{2}$ & $=c^{2}$
\end{tabularx}
\end{table}
\begin{displaymath}
(x + a)^n = \sum_{k=0}^n {n \choose k} x^k a^{n-k}
\end{displaymath}
\end{document}
unicode-math
only works with fonts which support mathematics. It works with Pagella because Pagella is one of only a few fonts to support the maths extension for opentype. But Pagella is a serif font, so obviously you won't get sans. Hence, I'm not completely sure that I'm understanding the question.\mathbf
, you are only mapping (a rather small) set of glyphs to the sansserif variants. Also imho you should better use\mathsfit{a}^{\mathsf{2}}
in the caption to get an slanteda
. Regarding the automation I would have expected thatrange={it->sfit, up->sfup }
would do the mapping you want, but I get errors and @WillRobertson will have to look at it. (I don't think that two math versions are really a good idea, imho it can get confusing. Math fonts convey meaning).\mathsf{}
; as in the$\mathsf{a^{2}+b^{2}=c^{2}}$
line in my MWE.T1
font encoding? Do you need it?