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.



\setmainfont{TeX Gyre Pagella}[%
    Ligatures   = TeX,%
    Numbers     = {OldStyle,Proportional},%
\setsansfont{TeX Gyre Heros}[%
    Ligatures   = TeX, %
    Numbers     = {Lining,Monospaced}, %
    Scale       = MatchLowercase, %

    Scale       = MatchLowercase,%
]{TeX Gyre Pagella Math} %

    version     = table,%
    Scale       = MatchLowercase,%
]{TeX Gyre Pagella Math} %


% etoolbox
   \sffamily\addfontfeature{Numbers={Lining, Monospaced}}%


some & text & and some math \\
$a^{2}$ & $+b^{2}$ & $=c^{2}$

  (x + a)^n = \sum_{k=0}^n {n \choose k} x^k a^{n-k}

  • 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. – cfr Aug 24 '15 at 16:08
  • You are not switching to "sans serif math" with \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 slanted a. Regarding the automation I would have expected that range={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). – Ulrike Fischer Aug 24 '15 at 16:09
  • @cfr the Pagella Math font includes a few sans serif symbols that can be selected using \mathsf{}; as in the $\mathsf{a^{2}+b^{2}=c^{2}}$ line in my MWE. – Matthijs Aug 24 '15 at 19:52
  • @UlrikeFischer Point taken, but I use math in the tables sparingly (but enough that I would like to automate it), and I don't think it would confuse anyone. It's just that a single serif math glyph thrown into sans serif table looks very ugly and unprofessional. The sans serif Pagella Math with my sans serif text font is still not ideal, but better. And I just want to learn how this stuff works… – Matthijs Aug 24 '15 at 19:58
  • OK. That doesn't include any specifically-mathematical symbols. I didn't know Pagella offered sans variants. I assume they are intended to be used for cases where the mathematical symbol should be sans serif, even though the main maths font is serif. (Which is why using them otherwise is likely going to be confusing.) Why are you activating the T1 font encoding? Do you need it? – cfr Aug 24 '15 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.