[Tex/LaTex] Why doesn’t the ‘bm’ package work with the ‘unicode-math’ package

bmboldmath-modeunicode-math

I want the bold italic math character (as in normal math) in math mode. So, I tried to use the bm package but it doesn't work together with the unicode-math package in my LaTeX document. Again, for some specific characters, it is not possible to remove unicode-math package. Can someone help me to use those packages together? Thanks!

The following codes work properly without \usepackage{unicode-math}. But when adding this package, the \bm command doesn't work.

  \documentclass[12pt, twoside]{book}
  \usepackage[utf8]{inputenc}
  \usepackage[T1]{fontenc}
  \usepackage[explicit]{titlesec}
  \usepackage[english]{babel}
  \usepackage{lmodern}
  \usepackage{fontspec}
  \usepackage{graphicx}
  \usepackage{amsmath}
  \usepackage{amsfonts}
  \usepackage{amssymb}
  \usepackage{bm}
  \usepackage{array}
  \usepackage{tabularx,booktabs}
  \usepackage{color, colortbl}
  \usepackage{pgf, pgfplots}
  \usepackage{tikz}\usetikzlibrary{shapes.misc}
  \usepackage{mathrsfs}
  \usepackage{enumitem}
  \usepackage{geometry}

  \begin{document}
      $\bm{(\sqrt[n]{x})^{n}=\sqrt[n]{x^{n}}=x}$
  \end{document}

Best Answer

First, some general comments and observations about the code shown in your preamble:

  • When using LuaLaTeX or XeLaTeX, you should not load the fontenc and inputenc packages. (Even when using pdfLaTeX, it's no longer necessary to load the inputenc package unless your file's input encoding is not UTF8 or ASCII, which is a proper subset of UTF8.)

  • Loading the colortbl and color packages independently is a mistake, as it doesn't maximize the compatibility and interoperability of these two packages. Hence, do replace \usepackage{color, colortbl} with \usepackage[table]{xcolor}. See section 2.1.2, "Package options", as well as Table 1, "Package options", of the user guide of the xcolor package for more information.

  • When using the unicode-math package along with a suitable OpenType math font (specified via a suitable \setmathfont instruction), there's no need to load the following packages: lmodern, fontspec, amsmath, amsfonts, amssymb, and bm. (Aside: If you load the unicode-math package but do not run a \setmathfont directive, the default math font is Latin Modern Math.)

  • The unicode-math package loads the amsmath package automatically if it hasn't already been loaded prior to LaTeX encountering the instruction \usepackage{unicode-math}. See Section 3, "Getting Started", of the user guide of unicode-math package for more information.

  • If you wish to use the \mathscr directive of the mathrsfs package, be sure to load mathrsfs after unicode-math. (I mention this because the preamble you posted loads the mathrsfs package.)

Now, finally, to the main part of your query:

I want the bold italic math character (as in normal math) in math mode

  • To generate bold italic math-mode letters and symbols, the unicode-math package provides a macro called \symbfit. Use it in lieu of \boldsymbol and \bm. (As you've discovered, \bm doesn't work anyway; hence, don't use it.)

  • To generate bold upright math-mode letters and symbols, use \symbfup. Use it in lieu of \mathbf.

As the following screenshot demonstrates, \symbfit and \symbfup -- as well as their regular-weight counterparts \symit and \symup -- affect the weight and shape of Latin and Greek letters, but not the shape and weight of (math) "operators" such as \int, \sum, \exp, and \ln.

enter image description here

\documentclass{book}
\usepackage{unicode-math}
\setmainfont{Latin Modern Roman} 
\setmathfont{Latin Modern Math}

\newcommand\blurb{(\sqrt[n]{x}\,)^{n}=\sqrt[n]{x^{n}}=x 
     \quad \alpha\beta\Sigma\Omega \quad \int\sum\exp\ln}

\usepackage{setspace}  % just for this example
\setstretch{1.25}

\begin{document}
\obeylines
$\blurb$ --- default
$\symbfit{\blurb}$ --- \verb+\symbfit+
$\symbfup{\blurb}$ --- \verb+\symbfup+
$\symit{\blurb}$ --- \verb+\symit+
$\symup{\blurb}$ --- \verb+\symup+
\end{document}
Related Question