4

When I try to use the \vb* macro of the physics package with LuaLaTeX and the unicode-math package, not a single OpenType math font seems to support bold characters.

\documentclass{article}
\usepackage{physics}  % Add \dv, \grad etc.
\newcommand\blurb{$\alpha \pi \lambda \vb*{\alpha\pi\lambda}$}
\usepackage[math-style=ISO,bold-style=ISO]{unicode-math}
%% Load 10 math fonts, plus two alternate/stylistic set variants
\setmathfont{Latin Modern Math}[version=LM]
\setmathfont{Stix Math}[version=Stix]
\setmathfont{XITS Math}[version=XITS]
\setmathfont{XITS Math}[StylisticSet=1,version=XITS1]
\setmathfont{Stix Two Math}[version=Stix2] % see http://stixfonts.org/
\setmathfont{Cambria Math}[version=Cambria]
\setmathfont{Asana Math}[version=Asana]
\setmathfont{Asana Math}[Alternate,version=AsanaAlt]
\setmathfont{TeX Gyre Pagella Math}[version=Pagella]
\setmathfont{TeX Gyre Termes Math}[version=Termes]
\setmathfont{TeX Gyre DejaVu Math}[version=DejaVu]
\setmathfont{Neo Euler}[version=Euler]
\setmathfont{Libertinus Math}[version=Libertinus]

\begin{document}
\renewcommand\arraystretch{1.8}
\begin{tabular}{@{}ll@{}}
Latin Modern & \mathversion{LM}      \blurb \\
Stix         & \mathversion{Stix}    \blurb \\
XITS         & \mathversion{XITS}    \blurb \\
XITS, StySet1& \mathversion{XITS1}   \blurb \\
Stix Two     & \mathversion{Stix2}   \blurb \\
Cambria      & \mathversion{Cambria} \blurb \\
Asana        & \mathversion{Asana}   \blurb \\
Asana Alt    & \mathversion{AsanaAlt}\blurb \\
Pagella      & \mathversion{Pagella} \blurb \\
Termes       & \mathversion{Termes}  \blurb \\
DejaVu       & \mathversion{DejaVu}  \blurb \\[0.5ex]
Neo Euler    & \mathversion{Euler}   \blurb \\[0.5ex]
Libertinus Math& \mathversion{Libertinus} \blurb
\end{tabular}
\end{document}
15
  • 1
    could you explain the connection between your question and the comment? what does bold have to do with physics? your title suggests an incompatibility with luatex, but your question says nothing about what that incompatibility consists in.
    – cfr
    Commented Nov 14 at 5:42
  • 1
    and why do you think your example shows none of the fonts support bold?
    – cfr
    Commented Nov 14 at 5:55
  • 2
    The situation for bold is the same in latex as pdftex boldmath works if you have a bold math font, some do including the default latin modern, you can use FakeBokd to make a bold version of others or you can use the bold glyphs from the same font using symbf Commented Nov 14 at 8:35
  • 2
    I've taken the liberty of editing the title and first sentence of your posting to clarify what it is you're trying to achieve. I've also added the unicode-math tag. Feel free to revert.
    – Mico
    Commented Nov 14 at 8:41
  • 4
    And by the way, don’t use the physics package at all. It’s crap.
    – Gaussler
    Commented Nov 14 at 8:59

4 Answers 4

6

This is what physics does:

\DeclareDocumentCommand\vectorbold{ s m }{\IfBooleanTF{#1}{\boldsymbol{#2}}{\mathbf{#2}}} % Vector bold [star for Greek and italic Roman]
\DeclareDocumentCommand\vb{}{\vectorbold} % Shorthand for \vectorbold

It's really hard to understand the intentions of the package author.1 According to ISO, vectors should be bold italic.2 So it's quite strange that the package offers as standard the wrong notation and the right one as a variant.

Anyway, neither \boldsymbol nor \mathbf will do the right thing with unicode-math.

If you want to reproduce what physics does with pdflatex also when unicode-math is used, you could do

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

\RenewDocumentCommand{\vectorbold}{sm}{%
  \IfBooleanTF{#1}{\symbfit{#2}}{\symbf{#2}}%
}
\RenewCommandCopy{\vb}{\vectorbold}

\begin{document}

$v\vb*{v}\vb{v}$

$\alpha \pi \lambda \vb*{\alpha\pi\lambda}$

\end{document}

unicode-math

Compare with

% compile with pdflatex
\documentclass{article}
\usepackage{physics}

\begin{document}

$v\vb*{v}\vb{v}$

$\alpha \pi \lambda \vb*{\alpha\pi\lambda}$

\end{document}

output with pdflatex

The simplest strategy is to forget about physics that's buggy and has an overall weird syntax for commands, besides taking wrong decisions in several cases.


Footnotes

1 \DeclareDocumentCommand is wrong here and throughout physics.sty.

2 Not that I endorse the notation prescribed by ISO.

10
  • 1
    The \boldsymbol command works fine with unicode-math, if you declare \setmathfont with version=bold. There just aren’t many OpenType math fonts with a bold version. By default \mathbf loads the bold text font, but unicode-math has a package option to make it a synonym for \symbf.
    – Davislor
    Commented Nov 14 at 13:22
  • @Davislor But with \symbfit you can copy the exact Unicode point, which is not the case with \boldsymbol.
    – egreg
    Commented Nov 14 at 13:24
  • I agree that commands should use \symbfit where they can and \boldsymbol where they have to. I suspect the physics package does things that way because LaTeX doesn’t define any bold-italic-math alphabet in the kernel. (The isomath package fills in this gap.)
    – Davislor
    Commented Nov 14 at 14:07
  • Excellent answer, thank you! Could you explain what this does? \RenewDocumentCommand{\vectorbold}{sm}{% \IfBooleanTF{#1}{\symbfit{#2}}{\symbf{#2}}% }? I'd like to ditch the bold-upright and provide a definition of vb now that you've convinced me to ditch physics. Also, is there a way to have a single vb macro that works with Latin and Greek characters?
    – Neil G
    Commented Nov 14 at 16:23
  • @NeilG I'm just throwing away physics' definition and replacing with a new one; since the package makes \vb as an alias to \vectorbold, I do the same. My advice is to throw away physics altogether.
    – egreg
    Commented Nov 14 at 16:31
5

You wrote

When I try to use the \vb* macro of the physics package with LuaLaTeX and the unicode-math package, not a single OpenType math font seems to support bold characters.

and also commented

unicode-math is completely messing everything up

Not really. Just replace \vb*{\alpha\pi\lambda} with \symbf{\alpha\pi\lambda}.

Two additional observations:

  • What's so important about using \vb*?

  • I had to change \setmathfont{Neo Euler} to \setmathfont{Euler Math} to get your code to work without a hitch.

enter image description here

\documentclass{article}
\usepackage{physics}  % Add \dv, \grad etc.
\newcommand\blurb{$\alpha\pi\lambda\  \symbf{\alpha\pi\lambda}$}
\usepackage{unicode-math}
%% Load 10 math fonts, plus two alternate/stylistic set variants
\setmathfont{Latin Modern Math}[version=LM]
\setmathfont{Stix Math}[version=Stix]
\setmathfont{XITS Math}[version=XITS]
\setmathfont{XITS Math}[StylisticSet=1,version=XITS1]
\setmathfont{Stix Two Math}[version=Stix2]
\setmathfont{Cambria Math}[version=Cambria]
\setmathfont{Asana Math}[version=Asana]
\setmathfont{Asana Math}[Alternate,version=AsanaAlt]
\setmathfont{TeX Gyre Pagella Math}[version=Pagella]
\setmathfont{TeX Gyre Termes Math}[version=Termes]
\setmathfont{TeX Gyre DejaVu Math}[version=DejaVu]
\setmathfont{Euler Math}[version=Euler]
\setmathfont{Libertinus Math}[version=Libertinus]

\begin{document}
\begin{tabular}{ll}
Latin Modern   & \mathversion{LM}      \blurb \\
Stix           & \mathversion{Stix}    \blurb \\
XITS           & \mathversion{XITS}    \blurb \\
XITS, StySet1  & \mathversion{XITS1}   \blurb \\
Stix Two       & \mathversion{Stix2}   \blurb \\
Cambria        & \mathversion{Cambria} \blurb \\
Asana          & \mathversion{Asana}   \blurb \\
Asana Alt      & \mathversion{AsanaAlt}\blurb \\
Pagella        & \mathversion{Pagella} \blurb \\
Termes         & \mathversion{Termes}  \blurb \\
DejaVu         & \mathversion{DejaVu}  \blurb \\
Euler Math     & \mathversion{Euler}   \blurb \\
Libertinus Math& \mathversion{Libertinus} \blurb
\end{tabular}
\end{document}
4
  • 1
    @Gaussler - Thanks for the edit.
    – Mico
    Commented Nov 14 at 10:42
  • 1
    Neo Euler isn’t part of the CTAN distribution and would need to be downloaded from its GitHub page.
    – Davislor
    Commented Nov 14 at 13:48
  • @Davislor - Is it correct to say that Euler Math is based (closely, presumably) on Neo Euler?
    – Mico
    Commented Nov 14 at 14:46
  • 2
    Yes, Euler Math is a fork of Neo Euler.
    – Davislor
    Commented Nov 14 at 14:47
5

Your issue is unrelated to luatex or the physics package, you would see the same in classic TeX.

\boldsymbol justt locally uses \boldmath to select \mathversion{bold} so this works well when you just have two math versions, normal and bold but if you define multiple math versions you need to also define multiple bold versions and arrange to switch them.

Here I just locally disable \mathversion so that \mathversion{anything} selects the bold version of the math version just selected, as this saves redefining the underlying commands.

I also just used FakeBold, although some of tehse do have a real bold math font that you coudl use, and a value of 3 is a bit excessive but makes it clear when debugging.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand\blurb{$\alpha \pi \lambda \boldsymbol{\alpha\pi\lambda}$}
\usepackage[math-style=ISO,bold-style=ISO]{unicode-math}
%% Load 10 math fonts, plus two alternate/stylistic set variants
\setmathfont{Latin Modern Math}[version=LM]
%\setmathfont{Stix Math}[version=Stix]
\setmathfont{XITS Math}[version=XITS]
\setmathfont{XITS Math}[StylisticSet=1,version=XITS1]
\setmathfont{STIX Two Math}[version=Stix2] % see http://stixfonts.org/
%\setmathfont{Stix Two Math}[version=Stix2] % see http://stixfonts.org/
\setmathfont{Cambria Math}[version=Cambria]
\setmathfont{Asana Math}[version=Asana]
\setmathfont{Asana Math}[Alternate,version=AsanaAlt]
\setmathfont{TeX Gyre Pagella Math}[version=Pagella]
\setmathfont{TeX Gyre Termes Math}[version=Termes]
\setmathfont{TeX Gyre DejaVu Math}[version=DejaVu]
%\setmathfont{Neo Euler}[version=Euler]
\setmathfont{Euler Math}[version=Euler]
\setmathfont{Libertinus Math}[version=Libertinus]

\setmathfont{Latin Modern Math}[version=boldLM,FakeBold=3]
%\setmathfont{Stix Math}[version=Stix]
\setmathfont{XITS Math}[version=boldXITS,FakeBold=3]
\setmathfont{XITS Math}[StylisticSet=1,version=boldXITS1,FakeBold=3]
\setmathfont{STIX Two Math}[version=boldStix2,FakeBold=3] % see http://stixfonts.org/
%\setmathfont{Stix Two Math}[version=Stix2] % see http://stixfonts.org/
\setmathfont{Cambria Math}[version=boldCambria,FakeBold=3]
\setmathfont{Asana Math}[version=boldAsana,FakeBold=3]
\setmathfont{Asana Math}[Alternate,version=boldAsanaAlt,FakeBold=3]
\setmathfont{TeX Gyre Pagella Math}[version=boldPagella,FakeBold=3]
\setmathfont{TeX Gyre Termes Math}[version=boldTermes,FakeBold=3]
\setmathfont{TeX Gyre DejaVu Math}[version=boldDejaVu,FakeBold=3]
%\setmathfont{Neo Euler}[version=Euler]
\setmathfont{Euler Math}[version=boldEuler,FakeBold=3]
\setmathfont{Libertinus Math}[version=boldLibertinus,FakeBold=3]

\let\oldmathversion\mathversion
\def\bversion#1{\def\mathversion##1{\oldmathversion{bold#1}}}
\begin{document}


\renewcommand\arraystretch{1.8}
\begin{tabular}{@{}ll@{}}
Latin Modern & \mathversion{LM}\bversion{LM}      \blurb \\
%Stix         & \mathversion{Stix}\bversion{Stix}    \blurb \\
XITS         & \mathversion{XITS}\bversion{XITS}    \blurb \\
XITS, StySet1& \mathversion{XITS1}\bversion{XITS1}   \blurb \\
Stix Two     & \mathversion{Stix2}\bversion{Stix2}   \blurb \\
Cambria      & \mathversion{Cambria}\bversion{Cambria} \blurb \\
Asana        & \mathversion{Asana}\bversion{Asana}   \blurb \\
Asana Alt    & \mathversion{AsanaAlt}\bversion{AsanaAlt}\blurb \\
Pagella      & \mathversion{Pagella}\bversion{Pagella} \blurb \\
Termes       & \mathversion{Termes}\bversion{Termes}  \blurb \\
DejaVu       & \mathversion{DejaVu}\bversion{DejaVu}  \blurb \\[0.5ex]
Neo Euler    & \mathversion{Euler}\bversion{Euler}   \blurb \\[0.5ex]
Libertinus Math& \mathversion{Libertinus}\bversion{Libertinus} \blurb
\end{tabular}
\end{document}

In a normal document, even with unicode-math you would just use \setmathfont{...} to set up the normal version and \setmathfont[version=bold]{...} to set up bold math.


Also as Mico shows For these particular characters OpenType math fonts have the bold glyphs in the same font so locally redefining \boldsymbol to be \symbfit would also work.

5
  • Would you mind giving an example of selecting the appropriate bold math font rather than doing the less pretty "fake bold"?
    – Neil G
    Commented Nov 14 at 17:01
  • @NeilG $ find . | grep -i bold | grep -i math ./public/concmath-otf/Concrete-Math-Bold.otf ./public/erewhon-math/Erewhon-Math-Bold.otf ./public/kpfonts-otf/KpMath-Bold.otf ./public/kpfonts-otf/KpMath-SansBold.otf ./public/kpfonts-otf/KpMath-Semibold.otf ./public/lete-sans-math/LeteSansMath-Bold.otf ./public/newcomputermodern/NewCMMath-Bold.otf ./public/xcharter-math/XCharter-Math-Bold.otf ./public/xits/XITSMath-Bold.otf Commented Nov 14 at 17:09
  • @NeilG so of the math fonts you list, only XITS, but you can replace \setmathfont{XITS Math}[version=boldXITS,FakeBold=3] by \setmathfont{XITSMath-Bold.otf}[version=boldXITS] to use the supplied bold font rather than automatically genearting a bold version of the normal Commented Nov 14 at 17:10
  • Got it, so it appears that being able to find a bold math font is quite rare? Considering that fake-bold isn't that pretty, then unicode-math's symbfit seems like the most visually-appealing solution? While I agree that yours is more user-friendly (in that it just "makes the argument bold").
    – Neil G
    Commented Nov 14 at 17:16
  • 1
    @NeilG yes fake bold is less horrible if you use something like 1.5 rather thah 3, but 3 gets noticed:-) as for what to do in general yes it depends, \symbf is a designed visually compatible bold but (a) only for latin and greek, so if you have cyrillic or a symbol such as + you are out of luck and get no bold, choosing a bold math font gives better results, if you can find one... As i say defining a \ignore-technical-issues-and-make-this-bold command is explicitly on the roadmap (we have a github issue somewhere) but it's not entirely clear what it should do Commented Nov 14 at 17:23
3

The physics package uses the \boldsymbol command, I suspect because there is no bold-italic-math command in the LaTeX kernel. This sets \mathversion{bold}. You changed around the math versions but didn’t ever set that one up.

It also uses \mathbf in some places. By default, unicode-math sets \mathbf as the bold text font, for words in math mode, and makes the Unicode bold upright mathematical symbols available through \symbfup. You can override this, however, with the package option mathbf=sym. There are similar package options for \mathrm, \mathup, \mathit, \mathsf and \mathtt.

A MWE that sets up a bold math font and \mathbf:

\documentclass{article}
\usepackage{physics}  % Add \dv, \grad etc.
\newcommand\blurb{$\alpha \pi \lambda \vb*{\alpha\pi\lambda}$}
\usepackage[math-style=ISO,bold-style=ISO,mathbf=sym]{unicode-math}
\usepackage{newcomputermodern}

\setmathfont{NewCMMath-Book.otf}
\setmathfont{NewCMMath-Bold.otf}[version=bold]

\begin{document}
\blurb
\end{document}

New Computer Modern Math sample

If you genuinely need to change between different math fonts in the same document, such as between sans-serif and serif, you want to define math fonts for version=sans and possibly version=boldsans. Use the alphabets like \symsfup and \symbfit whenever you can, but it is also possible to define new commands analogous to \boldsymbol, e.g.:

%% Based on the definition of \boldsymbol from amsbsy.sty"
\makeatletter
\DeclareRobustCommand{\sanssymbol}[1]{%
  \begingroup%
  \let\@nomath\@gobble \mathversion{sans}%
  \math@atom{#1}{%
  \mathchoice%
    {\hbox{$\m@th\displaystyle#1$}}%
    {\hbox{$\m@th\textstyle#1$}}%
    {\hbox{$\m@th\scriptstyle#1$}}%
    {\hbox{$\m@th\scriptscriptstyle#1$}}}%
  \endgroup}
\makeatother

If you’re reconsidering whether you want to use physics at all, see @egreg’s answer. (I respectfully disagree with his suggestion to use low-level formatting commands in the body of your document rather than high-level semantic markup, especially if you might have to copy-and-paste an equation into a document for legacy TeX or change to your publisher’s house style.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .