11

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

Gaussler
  • 12,801
  • 1
    \boldmath has always made all math symbols bold. – egreg Jun 06 '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 06 '15 at 17:16
  • @egreg But I only activated \boldmath in the second line of the \mytest output, and yet all my math is bold in Example 4. – Gaussler Jun 06 '15 at 17:48
  • 1
    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 06 '15 at 18:38
  • @morbusg, so, how do I turn that explanation into a solution? :-) – Gaussler Jun 06 '15 at 18:39
  • 1
    @Gaussler: Man, you're quick! :-D Please, give me just a minute... – morbusg Jun 06 '15 at 18:40
  • Sorry.... ;-) – Gaussler Jun 06 '15 at 18:41
  • 2
    And by "one minute" I of course meant 15 minutes... ;) Hope it helps! – morbusg Jun 06 '15 at 19:01
  • The question now has a bountry. I wonder if someone will come up with a solution then. – Gaussler Nov 19 '15 at 19:05

4 Answers4

4

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

Ulrike Fischer
  • 327,261
  • 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
3

Here is a solution that gets “\boldmath to automatically activate bold italic math,” as desired. It necessarily relies, however, as Ulrike Fischer mentioned on the presence of a “real bold math font.” (Hence, it cannot be achieved with TeX Gyre Pagella Math, because there is no TeX Gyre Pagella Math Bold, as already pointed out by egreg.)

To my knowledge, currently (February 2, 2023) seven math fonts exist that have a bold-math companion:

  1. the open-source font XITSMath (already mentioned in the comments, included in the standard TeX distributions, and used in my solution);
  2. the commercial font Minion Math (which even comes in four weights);
  3. the commercial font Lucida Bright;
  4. the open-source font Fira Math (wich comes in as many as 12 weights, but the non-regular weights have rather incomplete glyph coverage);
  5. the open-source KpMath font (which is included in the standard TeX distributions via the kpfonts-otf package and even comes in four weights plus a sans-serif version);
  6. the open-source Erewhon-Math font (which is included in the standard TeX distributions—the bold weight currently does not cover all glyphs present in the regular weight, e.g., variable-size delimiters are missing); and
  7. the open-source XCharter-Math font (which is included in the standard TeX distributions—the bold weight currently does not cover all glyphs present in the regular weight, e.g., variable-size delimiters are missing).
% !TEX program = xelatex

\documentclass{minimal}

\usepackage{ifthen} \usepackage[svgnames]{xcolor}

\usepackage[ mathit = sym, mathup = sym, mathbf = sym, math-style = ISO, bold-style = ISO ]{unicode-math}

\setmainfont{LinLibertine_R.otf}[ ItalicFont = LinLibertine_RI.otf, BoldFont = LinLibertine_RB.otf, BoldItalicFont = LinLibertine_RBI.otf ] \setmonofont{FiraMono-Medium.otf}[ Scale = 0.81, Color = DarkBlue ]

\setmathfont{XITSMath-Regular.otf}[ BoldFont = XITSMath-Bold.otf ] \setmathfont{XITSMath-Regular.otf}[ version = mathitVersion ] \setmathfont{XITSMath-Regular.otf}[ version = mathbfitVersion ] \setmathfont{XITSMath-Bold.otf}[ version = boldmathVersion ]

\setmathfont{LinLibertine_R.otf}[ range = up/{num, latin, Latin, greek, Greek}, BoldFont = LinLibertine_RB.otf ] \setmathfont{LinLibertine_RI.otf}[ range = it/{num, latin, Latin, greek, Greek}, BoldFont = LinLibertine_RBI.otf, NFSSFamily = mathitalic ] \setmathfont{LinLibertine_RBI.otf}[ range = bfit/{latin, Latin, greek, Greek}, NFSSFamily = mathbolditalic ] \setmathfont{LinLibertine_RB.otf}[ range = bfup/{num, latin, Latin, greek, Greek} ]

\newif \ifBoldMath \BoldMathfalse \let \mathversionorig \mathversion \renewcommand{\mathversion}[1]{% \ifthenelse{\equal{#1}{bold}}{% \BoldMathtrue% }{% \BoldMathfalse% }% \mathversionorig{#1}% }

\AtBeginDocument{% \let \mathitorig \mathit% \renewcommand{\mathit}[1]{% \ifBoldMath% \textbf{% \SetSymbolFont{__um_fam1}{boldmathVersion}{TU}{mathbolditalic}{b}{it}% \SetSymbolFont{__um_fam2}{boldmathVersion}{TU}{mathbolditalic}{b}{it}% \mathversion{boldmathVersion}% (\mathitorig{#1})% } \else% \textit{% \SetSymbolFont{__um_fam1}{mathitVersion}{TU}{mathitalic}{m}{it}% \mathversion{mathitVersion}% (\mathitorig{#1})% }% \fi% }% \let \mathbfitorig \mathbfit% \renewcommand{\mathbfit}[1]{{% \textbf{% \SetSymbolFont{__um_fam1}{mathbfitVersion}{TU}{mathbolditalic}{b}{it}% \mathversion{mathbfitVersion}% (\mathbfitorig{#1})% }% }}% }

\newcommand{\testUnicodeMath}{% \bigskip \begin{tabular}{l @{\quad}l @{\quad} l @{\quad} l @{\quad} l} Row & Math version/alphabet & Regular & Upright & Italic \[\medskipamount] 1 & Text & A = 1a & \textup{B = 2b} & \textit{C = 3c} \ 2 & \texttt{\textbackslash textbf} & \textbf{A = 1a} & \textbf{\textup{B = 2b}} & \textbf{\textit{C = 3c}} \ 3 & \texttt{\textbackslash mathversion{normal}} (default) & $A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}$ & $\mathup{B = 2b + \beta \times \Gamma}$ & $\mathit{C = 3c + \beta \times \Gamma}$ \ 4 & \texttt{\textbackslash mathversion{bold}}/\texttt{\textbackslash boldmath} & \boldmath $A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}$ & \boldmath $\mathup{B = 2b + \beta \times \Gamma}$ & \boldmath $\mathit{C = 3c + \beta \times \Gamma}$ \ 5 & \texttt{\textbackslash mathbf}/\texttt{\textbackslash mathbfup}/\texttt{\textbackslash mathbfit} & $\mathbf{A = 1a + \beta \times \Gamma \int_{-\infty}^{\infty} \frac{\mathup{d}x}{2}}$ & $\mathbfup{B = 2b + \beta \times \Gamma}$ & $\mathbfit{C = 3c + \beta \times \Gamma}$ \ \end{tabular}% \bigskip \bigskip }

\begin{document}

\testUnicodeMath

\textit{Check that everything works properly by invoking it a~second time:}

\testUnicodeMath

\textit{Check that everything works properly by invoking it a~third time:}

\testUnicodeMath

\end{document}

This produces the following output—note that the “3” in table rows 3–5 is italic, in line with the formatting produced by the original LaTeX \mathit:

mathit/mathbfit fixed

I also posted this solution in the different thread that Gaussler mentioned.

2

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}

enter image description here

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.

morbusg
  • 25,490
  • 4
  • 81
  • 162
  • Thanks for the answer. So there is no way to get \boldmath to automatically activate bold italic math? – Gaussler Jun 06 '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 06 '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 06 '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 06 '15 at 19:29
  • 1
    @Gaussler \boldmath works perfectly, provided you have a bold math font. Unfortunately there is no TeX Gyre Pagella Math Bold. – egreg Jun 06 '15 at 19:38
  • @egreg: As I'm sure you already know, but TeX Gyre Pagella Math does have mathematical bold (and -italic) latin and greek alphanumerical characters at their Unicode slots. – morbusg Jun 06 '15 at 19:41
  • @morbusg I'm not talking about bold letters in the appropriate Unicode blocks; I'm talking about a full bold font which exists, for instance, with XITS Math as xits-mathbold.otf. – egreg Jun 06 '15 at 19:44
  • @egreg: I got the impression that's not what the OP was after: "I tried in Example 4 to play around with version=bold, but curiously, this makes all math bold." – morbusg Jun 06 '15 at 19:47
  • @egreg, I'm well aware there is no TeX Gyre Pagella Math Bold, as mentioned in the question. My intention, therefore, was to find out if there was a trick that made it possible to accomplish anyway, at least partially. The fact that it is possible for fonts without a MATH table made me confident that it was also possible for fonts with such a table. However, as my examples demonstrate, that was significantly harder to get to work properly (compared to the non-MATH table case)---unless you replaced all the math font characters with text font characters, which seemed a too big price to pay – Gaussler Jun 06 '15 at 20:17
  • @Gaussler: It is unclear to me what exactly do you want bolded? I mean, if you put the whole expression inside \mathbf{...}, is that what you are after? – morbusg Jun 06 '15 at 20:55
  • The ultimate goal was to get the \boldmath switch working, but it appears impossible in this case. – Gaussler Jun 07 '15 at 07:14
  • @Gaussler: as I don't know what a \boldmath is, maybe I shouldn't have answered ;) But somehow I doubt that was your ultimate goal. I bet your goal was to make something bolded, instead ;) – morbusg Jun 07 '15 at 07:49
1

A bit of necromancy, since this just got bumped up to the front page again. The FakeBold= option works for math fonts, including math fonts that you load with version=bold.

So:

\documentclass{article}
\usepackage{unicode-math}

\setmainfont[Ligatures=TeX]{TeX Gyre Pagella} \setmathfont{TeX Gyre Pagella Math} \setmathfont{TeX Gyre Pagella Math}[ version=bold, FakeBold=1.2 ]

\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}

\mytest

\end{document}

TeX Gyre Pagella sample

Davislor
  • 44,045