[Tex/LaTex] How to set the \boldmath font with unicode-math

fontsfontspecmath-modeunicode-mathxetex

I am trying to typeset a document in Linux Libertine, and I want to use the font for alphanumeric characters in math mode as well. I am using unicode-math, not mathspec, because I need to specify alphabets like mathup explicitly for compatibility with packages like hepnames. I did not find a way to do that with mathspec. The engine I use is XeLaTeX. I initially specify TeX Gyre Pagella Math as a complete math font for symbols etc. I want the subsequent declarations to overwrite the font for text characters as Libertine.

I find several problems, illustrated by the MWE below:

  1. The \boldmath switch doesn't do anything.
  2. Numbers are not rendered correctly in bold and italic, only letters.
  3. \mathbf (the last "A = 1" in the MWE) is rendered in Pagella, not in Libertine at all.

I already tried adding /{latin,Latin,num} to the range declarations, without success. What am I missing here?

\documentclass{minimal}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont[%
    Ligatures=TeX,
    BoldFont=LinLibertine_RB.otf,
    ItalicFont=LinLibertine_RI.otf,
    BoldItalicFont=LinLibertine_RBI.otf]
    {LinLibertine_R.otf}

\setmathfont{texgyrepagella-math.otf}

\setmathfont[range=\mathup]{LinLibertine_R.otf}
\setmathfont[range=\mathbf]{LinLibertine_RB.otf}
\setmathfont[range=\mathit]{LinLibertine_RI.otf}
\setmathfont[range=\mathbfit]{LinLibertine_RBI.otf}

\begin{document}
    \begin{tabular}{lll}
        Text     & A = 1               & \textit{B = 2}\\
        Textbf   & \textbf{A = 1}      & \textbf{\textit{B = 2}}\\
        Math     & $A = 1$             & $\mathit{B = 2}$\\
        Boldmath & {\boldmath $A = 1$} & {\boldmath $\mathit{B = 2}$}\\
        Mathbf   & $\mathbf{A = 1}$    & $\mathbfit{B = 2}$\\
    \end{tabular}
\end{document}

enter image description here

Without font changes, everything looks OK:

\documentclass{minimal}

\begin{document}
    \begin{tabular}{lll}
        Text     & A = 1               & \textit{B = 2}\\
        Textbf   & \textbf{A = 1}      & \textbf{\textit{B = 2}}\\
        Math     & $A = 1$             & $\mathit{B = 2}$\\
        Boldmath & {\boldmath $A = 1$} & {\boldmath $\mathit{B = 2}$}\\
    \end{tabular}
\end{document}

enter image description here

Best Answer

I found a solution that works for me. I started playing around with version=bold, as David suggested, but that kept turning all my math mode text bold. In the end I switched from file names to system font names. (I wanted to avoid that initially, since I am working on the same document from several different machines.) With system font names, \boldmath worked immediately and automatically. I also found that \mathbfup must be specified instead of \mathbf.

Another problem with using system font names is that, for some reason, the semi-bold Libertine style is loaded per default as bold. That is the reason for the BoldFont specification in the MWE below.

The solution is not perfect. You can see that all numbers in math mode are rendered upright, even in \mathit. Also, the number in \mathbfit is not bold. All fonts are correct though, and it's good enough for my purposes.

\documentclass{minimal}

\usepackage{fontspec}
\usepackage{unicode-math}

\setmainfont[
    BoldFont=Linux Libertine Bold,
    BoldItalicFont=Linux Libertine Bold Italic]
    {Linux Libertine}

\setmathfont{TeX Gyre Pagella Math}

\setmathfont[range=\mathup,
    BoldFont=Linux Libertine Bold,
    BoldItalicFont=Linux Libertine Bold Italic]
    {Linux Libertine}
\setmathfont[range=\mathit,
    BoldFont=Linux Libertine Bold Italic]
    {Linux Libertine Italic}
\setmathfont[range=\mathbfup]{Linux Libertine Bold}
\setmathfont[range=\mathbfit]{Linux Libertine Bold Italic}

\begin{document}
    \begin{tabular}{lll}
        ~        &\ Regular             &\ Italic\\
        Text     &\ A = 1               &\ \textit{A = 1}\\
        Textbf   &\ \textbf{A = 1}      &\ \textbf{\textit{A = 1}}\\
        Math     &\ $A = 1$             &\ $\mathit{A = 1}$\\
        Boldmath &\ {\boldmath $A = 1$} &\ {\boldmath $\mathit{A = 1}$}\\
        Mathbf   &\ $\mathbf{A = 1}$    &\ $\mathbfit{A = 1}$\\
    \end{tabular}
\end{document}

enter image description here