7

When I used LaTeX without unicode-math, I used \bm to make bold the entire equation or large part of it. Now I need to use \usepackage{unicode-math} for Cyrillic characters in math, and \bf doesn't work with unicode math.

I need a direct alternative for \bm that takes existing styles into account and also affects all operators. For example:

\bm{a + \mathrm{b}}

will produce: {bold italic a} {bold +} {bold non-italic b}. Is there such unicode-compatible command in LaTeX or in some LaTeX package?

13
  • You can use math fonts such as NewCM, Concmath-otf, Kp-Math, etc. which have proper bold math support. NewCM has the highest number of glyphs, iirc. You've to switch to bold math using \mathversion{bold}. Commented Oct 21 at 17:28
  • Or you can use a macro such as \makeatletter \g@addto@macro\bfseries{\boldmath} \makeatother which automatically makes math in titles bold. Commented Oct 21 at 17:29
  • Welcome to TeX.SE! Can you please show a short compilable TeX code resulting in your issue? Then we do not have to guess what you are doing ... Commented Oct 21 at 17:32
  • 1
    @ApoorvPotnis Instead of the (wrong) \g@addto@macro method, you can do \AddToHook{bfseries}{\boldmath}. Commented Oct 21 at 17:46
  • 1
    @ApoorvPotnis \bfseries is a robust command, so you're redefining the wrong one. Commented Oct 21 at 19:00

3 Answers 3

5

You can use font versions (with fonts that support bold math) and also define a “fake bm” command.

\documentclass[a4paper]{article}
\usepackage{fontsetup} % New CM

\AddToHook{bfseries}{\boldmath}

\NewDocumentCommand{\fbm}{m}{\text{\boldmath$#1$}}

\setboldmathrm{NewCM10-Bold.otf}

\begin{document}

This is some normal text. Now for some normal display math.
\[
  \hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(2\pi i\xi x)\,dx.
\]
\textbf{Now some bold text and bold display math.}

{\boldmath\[
\hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(-2\pi i\xi x)\,dx.
\]}
Now some again normal display math.
\[
  \hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(-2\pi i\xi x)\,dx.
\]
Math gets bolded automatically in a chapter or section header, 
or when you use math in a \verb|\textbf{}| environment.

\section*{Header $\int_{-\infty}^{+\infty} f$}

\textbf{Some bold text $\hat{f}(\xi)$ with bold math} and
finally only a part of the formula bold
\[
\hat{f}(\xi) = \fbm{\int_{-\infty}^{+\infty} f(x) \exp(-2\pi i\xi x)\,dx}.
\]


\end{document}

output

8
  • Thank you! Looks as what I exactly wanted! May you please give some comments on how does this work: \NewDocumentCommand{\fbm}{m}{\text{\boldmath$#1$}} and why we need to manually set bold math font: \setboldmathrm{NewCM10-Bold.otf}? Commented Oct 21 at 20:57
  • 2
    @t1m013y \text respects the current math style, choosing the right font size. The setting of \setboldmathrm is needed because fontspec apparently doesn't do it automatically. Commented Oct 21 at 21:08
  • Tested some LaTeX commands and accidently found that wrapping the required part of the equation into \boldsymbol also does exactly what I want after adding font using \setboldmathrm, but it's much simpler. Looks like \boldsymbol is the direct alternative for \bm. Are there any pitfalls? Maybe I'll write my own answer. Commented Oct 21 at 23:19
  • \AddToHook{bfseries}{\boldmath} shouldn't be used, because what if {\bfseries text \mdseries $t\text{hat t was bold!}$? Commented Oct 21 at 23:55
  • 1
    @John What do you propose? Commented Oct 22 at 6:50
5

You can use \mathversion{bold} to switch to the bold math font, and \mathversion{normal} to again switch to normal math. You've to use fonts which come with a bold math font, such as New Computer Modern, Concrete Math, XCharter Math, Erewhon Math, Kp Math, XITS Math, etc. Usually these fonts, except for NewCM, don't have full coverage of the glyphs as compared to the normal weight math font.

\documentclass[a4paper]{article}
%\documentclass[preview, margin=5pt, varwidth, convert={density=1000, convertexe={magick}}]{standalone}

\usepackage{microtype}

\usepackage{unicode-math}
\setmainfont[
    SizeFeatures={
        {Size=-8, Font=NewCM08-Book.otf,
            ItalicFont=NewCM08-BookItalic.otf,
            BoldFont=NewCM10-Bold.otf,
            BoldItalicFont=NewCM10-BoldItalic.otf,
            SlantedFont=NewCM08-Book.otf,
            BoldSlantedFont=NewCM10-Bold.otf,
            SmallCapsFeatures={Numbers=OldStyle}},
        {Size=8, Font=NewCM08-Book.otf,
            ItalicFont=NewCM08-BookItalic.otf,
            BoldFont=NewCM10-Bold.otf,
            BoldItalicFont=NewCM10-BoldItalic.otf,
            SlantedFont=NewCM08-Book.otf,
            BoldSlantedFont=NewCM10-Bold.otf,
            SmallCapsFeatures={Numbers=OldStyle}},
        {Size= 9-, Font = NewCM10-Book.otf,
            ItalicFont=NewCM10-BookItalic.otf,
            BoldFont=NewCM10-Bold.otf,
            BoldItalicFont=NewCM10-BoldItalic.otf,
            SlantedFont=NewCM10-Book.otf,
            BoldSlantedFont=NewCM10-Bold.otf,
            SmallCapsFeatures={Numbers=OldStyle}}
    },
    SmallCapsFeatures={Numbers=OldStyle},
    BoldSlantedFont=NewCM10-Bold.otf,
    SlantedFont=NewCM10-Book.otf,
    BoldItalicFont=NewCM10-BoldItalic.otf,
    BoldFont=NewCM10-Bold.otf,
    ItalicFont=NewCM10-BookItalic.otf,
    SlantedFeatures={FakeSlant=0.25},
    BoldSlantedFeatures={FakeSlant=0.25}
]{NewCM10-Book.otf}

\setmathfont[
    StylisticSet={3},
    BoldFont = NewCMMath-Bold.otf
]{NewCMMath-Book.otf}

\AddToHook{bfseries}{\boldmath} % Correct macro by egreg 

\begin{document}
    \noindent This is some normal text. Now for some normal display math.
    \[
        \hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(2 \symup{\pi i} \xi x) \symup{d}x.
    \]
    \textbf{Now some bold text and bold display math.}
    \mathversion{bold}
    \[
        \hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(-2 \symup{\pi i} \xi x) \symup{d}x.
    \]
    \mathversion{normal}%
    Now some again normal display math.
    \[
        \hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(-2 \symup{\pi i} \xi x) \symup{d}x.
    \]
    Math gets bolded automatically in a chapter or section header, or when you use math in a \verb|\textbf{}| environment.

    \textbf{Some bold text $\hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x) \exp(-2 \symup{\pi i} \xi x) \symup{d}x$.}

    \section*{Header $\int_{-\infty}^{+\infty} f$}
\end{document}

bold math newcm

10
  • But I also need a way to make only part of the single equation bold Commented Oct 21 at 17:49
  • I'll accept this answer later if no better answer will appear Commented Oct 21 at 17:50
  • @t1m013y Do you mean that you want half of the equation in bold and half in normal weight? Commented Oct 21 at 17:52
  • Yes, exactly, I need an option to make only part of the equation bold. Commented Oct 21 at 17:53
  • Currently found only \pmb for this Commented Oct 21 at 17:54
3

I was doing some experiments with different commands in LaTeX and found that \boldsymbol is exactly what I need, without additional macros.

Thanks to @egreg for noticing that it requires to use \setboldmathrm to work properly.

Please tell me in comments if \boldsymbol doesn't satisfy my requirements in the original question and there's any pitfalls with it.

\documentclass{article}
\usepackage[default]{fontsetup}

\setboldmathrm{NewCM10-Bold.otf}

\begin{document}

\(a + \symrm{b} + \boldsymbol{a + \symrm{b}}\)

\[
a + \symrm{b} + \boldsymbol{a + \symrm{b}}
\]

\[
\hat{f}(\xi) = \boldsymbol{\int_{-\infty}^{+\infty} f(x) \exp(-2\pi i\xi x)\,dx}.
\]

\[
\symbb{Z} + \boldsymbol{\symbb{Z}}
\]

\end{document}

enter image description here

5
  • @cfr looks like amsmath issue or some packages incompatibility. I don't define any commands. Commented Oct 22 at 16:13
  • @cfr Fixed by swapping \usepackage{amssymb} and \usepackage[default]{fontsetup}. I edited the answer. Commented Oct 22 at 16:18
  • 1
    @cfr You're right! It's better to use \sym* commands instead of legacy \math* ones, for example, \symrm and \symbb. I edited the answer again. Commented Oct 22 at 21:27
  • 1
    [thanks for editing again. :-)] Commented Oct 22 at 21:28
  • 1
    I think it's better to use \symup instead of \symrm. (\symrm is a "legacy" command that may not work for much longer.) Commented Oct 22 at 22:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.