3

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}
  • 3
    I have no experience with the issue but from questions here on the site I recall that bm and unicode-math are in fact quite incompatible. On the other hand if you are using xetex or luatex you should't have any need for bm in the first place. – campa Feb 17 at 16:17
  • 3
    you shouldn't load inputenc, fontenc, lmodern when using lualatex or xelatex. And no bm doesn't work with unicode-math see e.g. tex.stackexchange.com/a/315389/2388 – Ulrike Fischer Feb 17 at 16:29
  • 1
    As the order matters with unicode-math you should also indicate in the MWE where you would load unicode-math – daleif Feb 17 at 16:31
8

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

\begin{document}
$\blurb$ --- default
$\symbfit{\blurb}$ --- \verb+\symbfit+
$\symbfup{\blurb}$ --- \verb+\symbfup+
$\symit{\blurb}$ --- \verb+\symit+
$\symup{\blurb}$ --- \verb+\symup+
\end{document}
  • I thought the Latin Modern unicode fonts were those loaded by default with Lua(La)TeX. Is that not the case? I don't know for Xe(La)TeX – Franck Pastor Feb 17 at 18:55
  • @FranckPastor - That's what I wrote: "If you load the unicode-math package but do not run a \setmathfont directive, the default math font is Latin Modern Math." I guess I failed to mention that Latin Modern Roman will be the default main or "roman" (upright) text font if no \setmainfont directive is provided. Tut tut. I provided explicit \setmainfont and \setmathfont directives mainly to make it (hopefully utterly) straightforward for future readers of this answer to determine where they should "hook in" to change the text and math fonts to suit their own typesetting needs. – Mico Feb 17 at 19:05
  • 1
    I believe unicode-math now loads amsmath. – Davislor Feb 17 at 19:11
  • @Davislor - You're absolutely right! I'll update my answer accordingly. – Mico Feb 17 at 19:14
  • 2
    @FranckPastor no, xelatex and lualatex default to classic 8bit math fonts unless you load unicode-math, even though they default to latin modern opentype unicode fonts for text – David Carlisle Feb 17 at 21:10
5

The bm package is for legacy 8-bit fonts. In unicode-math, load a math font that comes in bold (currently, XITS Math, Libertinus Math or Minion Math) and use \boldsymbol for bold operators and signs. If you only need bold letters, you can use \mathbf, \mathbfcal, etc. Or the new commands \symbfup for bold upright, \symbfit for bold italic, etc., as Mico brought up. Bold letters work with any Unicode math font.

If you want to bold symbols and a different math font, you can also load a bold math font with \setmathfont[version=bold]{SomeBoldMathFont.otf}.

You’re loading a number of legacy packages that are obsolete with unicode-math, among them amssymb, amsfonts, mathrsfs, fontenc and inputenc. All of these are only needed if you’re using legacy 7- and 8-bit fonts. (You shouldn’t be loading inputenc in any case: XeLaTeX and LuaLaTeX don’t support it, and PDFLaTeX no longer needs it.)

  • 1
    for unicode mmath fonts that have a separate bold font \bm could work, it mostly fails as the usual assumption in unicode-math is that the bold symbols come from plane 1 in the same font, and bm doesn't play that game. – David Carlisle Feb 17 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.