# \boldmath with unicode-math AND fonts with a MATH table

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}


• \boldmath has always made all math symbols bold. – egreg Jun 6 '15 at 17:12
• I don't think symbols like integrals are available in bold versions in TeX Gyre Pagella Math. At least there is no dedicated "TeX Gyre Pagella Math Bold" font (as far as I have understood). On the contrary, XITS Math has a bold version with all symbols in both. So in other words, XITS and Lucida (from what I've heard---I haven't bought it myself) are currently the only unicode math fonts that are useful in practice, since the lack of a bold version is an extremely severe limitation. – Gaussler Jun 6 '15 at 17:16
• Unicode has the latin and greek alphabet at the "Mathematical alphanumeric symbols"-range: 0x1D400–0x1D7FF, which covers, among others, the bold and bold italic. – morbusg Jun 6 '15 at 18:38
• @Gaussler: Man, you're quick! :-D Please, give me just a minute... – morbusg Jun 6 '15 at 18:40
• And by "one minute" I of course meant 15 minutes... ;) Hope it helps! – morbusg Jun 6 '15 at 19:01

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}


• Well, it's the best solution so far, but I would still prefer if \boldmath simply activated either (preferably) the bold symbols in the standard math font (in the case they exist) or (alterantively) the bold symbols in the text font. But perhaps that requires changes in how unicode-math works. – Gaussler Nov 25 '15 at 19:52
• Imho there aren't suitable bold symbols in unicode. There is a bold "a", but not a bold int, sum, equal sign, prime, accents etc. What you suggest is a (not very good) patchwork. The only really good solution is a real bold math font. The second best a faked bold like in my answer. A patchwork solution should be only the last resort. So even if the unicode-math code is improved I don't think that it will a satisfactory output. – Ulrike Fischer Nov 25 '15 at 20:54

Unicode has defined the bold and bold italic (and others) mathematical alphanumeric characters covering latin, greek, and digit characters, so they are already included in an conforming OpenType mathematical font.

Here is an example using the bold range:

\documentclass{article}
\usepackage{fontspec,amsmath}
\usepackage{unicode-math}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\begin{document}
$\hat f(t) = \int_0^t \hat f'(x)\, dx$
$\mathbf{\hat f}(t) = \int_0^t \mathbf{\hat f}'(x)\, dx$
\end{document}


A couple of notes. I remember there being an issue with accents with single-atom elements which can be fixed by prefixing the atom to be accented with an empty group (so, for example, \hat{{}f}, if need be).

Also, whether or not the bolded alphabets are in italic, can be determined by – according to the unicode-math documentation – the bold-style=ISO configuration option.

• Thanks for the answer. So there is no way to get \boldmath to automatically activate bold italic math? – Gaussler Jun 6 '15 at 19:01
• @Gaussler: Actually, I'm quite sure there is! It's just that I'm a little bit unfamiliar with unicode-math. (I mean, not necessarily with \boldmath, but a switch which activates the bold-italic range). I hope some of our LaTeX experts could chime in. – morbusg Jun 6 '15 at 19:05
• Of course, it would be possible to redefine \boldmath to insert a hook in all math environments, activating \mathbfit. However, that seems like a hacky and undesirable solution. – Gaussler Jun 6 '15 at 19:07
• @Gaussler: I was thinking more in lines of defining another font-selecting command (so, say, \myboldmath would use the same font, but with the aforementioned ranges activated). The documentation speaks of [range=\mathsfit->\mathbfsfit], but for some reason I couldn't get it to work with [range=\mathit->\mathbfit]. – morbusg Jun 6 '15 at 19:29
• @Gaussler \boldmath works perfectly, provided you have a bold math font. Unfortunately there is no TeX Gyre Pagella Math Bold. – egreg Jun 6 '15 at 19:38