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}
Best Answer
To avoid ambiguity, for new readers landing, it may be helpful, for reference, to have a visual on the unicode blocks.
Tex Gyre Pagella Math has Basic Latin (call it "text", but mappable)
Greek and Coptic ("text")
... lots of other blocks ...
and the Mathematical Alphanumeric Symbols (MAS) block:
and
(Sidenote: Because of the organic way Unicode has developed, some of the more famous mathematical symbols are located in the earlier Letter-like Symbols block:
)
By comparison, the Fira Sans Math font's MAS is much smaller:
Other Tex Gyre fonts (Bonum, DejaVu, Schola, Termes) have a math version -- see e.g. ...\texmf-dist\fonts\opentype\public\tex-gyre-math\