[Tex/LaTex] \boldmath with unicode-math AND fonts with a MATH table

boldmathunicode-math

There are several questions on this site about \boldmath with unicode-math. As Example 1 below shows, \boldmath does not in general work for unicode fonts with a MATH table, unless there is a specific bold version of the math font. So far, I have not found one for any fonts except XITS Math; from what I have heard, Lucida has one, too, but it is not free. How can I set the \boldmath font with unicode-math? provides an ugly solution that only works for XeLaTeX. Since I am using LuaLaTeX, I am looking for something else (and prettier).

Bold italic math with unicode-math contains a solution to get it to work using unicode fonts without a proper MATH table. The solution also works for fonts with a proper MATH table, provided you replace the math font with the italic text font (see Example 2). As the example shows, the accent (\hat) does not look good in this case.

So the preferable solution would be:

  • Ordinary, non-bold math should be typeset using TeX Gyre Pagella Math
  • \boldmath math should be typeset using the bold italic text font TeX Gyre Pagella Bold Italic

I tried that in Example 3 below, but it seems text and math fonts do not work together in this case, for integral signs and everything else break.

Finally, I tried in Example 4 to play around with version=bold, but curiously, this makes all math bold. Is this a bug?

Can someone get this to work for me?

% !TeX program=luatex
\documentclass{article}

\usepackage{fontspec,amsmath}

\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}

\usepackage{unicode-math}

\newcommand\mytest{
    \[ \hat f(t) = \int_0^t \hat f'(x)\, dx \]
    {\boldmath \[ \hat f(t) = \int_0^t \hat f'(x)\, dx \]}
}

\begin{document}

Example 1:

\setmathfont{TeX Gyre Pagella Math}

\mytest

Example 2:

\setmathfont{TeX Gyre Pagella Math}

\setmathfont[
   range=\mathit/{latin,Latin,greek,Greek,num},
   BoldFont=TeX Gyre Pagella Bold Italic
]{TeX Gyre Pagella Italic}

\mytest

Example 3:

\setmathfont[BoldFont=TeX Gyre Pagella Bold Italic]{TeX Gyre Pagella Math}

\mytest

Example 4:

\setmathfont{TeX Gyre Pagella Math}
\setmathfont[
     version=bold,
     range=\mathit/{latin,Latin,greek,Greek,num}
]{TeX Gyre Pagella Bold Italic}

\mytest

\end{document}

enter image description here

Best Answer

Well the logical solution is to setup a new math version, which should be independant from the normal math version.

But imho there is today not much chance to get the version key working in your use case. As long as only real math fonts are involved it works fine, but in the combination with range and text fonts it is buggy as one math version affects the other.

Currently I would implement a bold mathversion by embolden a real math font. In xelatex this can be done with FakeBold and version (as long as no other text fonts are involved). In lualatex you could use a pdfliteral:

\documentclass{article}
\usepackage{fontspec,amsmath}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}

\begin{document}

\[ \hat f(t) = \int_0^t \hat f'(x)\, dx \]

\pdfliteral direct {2 Tr 0.2 w} %the second factor is the boldness

\[ \hat f(t) = \int_0^t \hat f'(x)\, dx \]

\pdfliteral direct {0 Tr 0 w}%

\end{document}

enter image description here

Related Question