1. Introduction

In this tutorial, we’ll show how to get bold math symbols in LaTeX.

For example, in scientific and math texts, we often use bold font for vectors and matrices to distinguish them from scalar values.

2. Example

Let’s say we have a math expression:

(Ax - \alpha)^Tz = x \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_x = \Omega_x

It looks like this:

    [(Ax - \alpha)^Tz = x \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_x = \Omega_x]

There are several ways of making the symbols in it appear bold.

3. The \mathbf Command

We can use the \mathbf command, which is available in LaTeX by default. To use it, we apply it as any other command:

\mathbf{symbols_or_command}

For example, if we want to make A, z, and x bold, we’ll apply \mathbf to them:

(\mathbf{A}\mathbf{x} - \alpha)^T\mathbf{z} = \mathbf{x} \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_{\mathbf{x}} = \Omega_{\mathbf{x}}

The result is:

    [(\mathbf{A}\mathbf{x} - \alpha)^T\mathbf{z} = \mathbf{x} \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_{\mathbf{x}} = \Omega_{\mathbf{x}}]

which is what we wanted.

However, if we wanted to apply \mathbf to the entire expression, it wouldn’t work on all the symbols:

    [\mathbf{(Ax - \alpha)^Tz = x \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_x = \Omega_x}]

As we see, the lowercase alpha, parentheses, operators, and relation symbols stayed in the regular font.

4. The \bm  Command

An alternative is the \bm command from the bm package. We can use it to make individual symbols bold:

(\bm{A}\bm{x} - \bm{\alpha})^T\bm{z} = \bm{x} \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_{\bm{x}} = \Omega_{\bm{x}}

which renders like this:

     $$ (\bm{A}\bm{x} - \bm{\alpha})^T\bm{z} = \bm{x} \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_{\bm{x}} = \Omega_{\bm{x}} $$

Or, if we want to apply bold to the entire expression:

\bm{(Ax - \alpha)^Tz = x \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_x = \Omega_x}

we get:

     $$\bm{(Ax - \alpha)^Tz = x \iff \left( \int_{a}^{b}cf(u)du \right) + \nabla \Psi_x = \Omega_x}$$

As we see, all the symbols are bold, and the spacing between them is as it should be.

For this command to work as intended, we should load the bm package after any packages that define or load fonts.

4.1. Unbolding Symbols

We may sometimes want to “unbold” symbols. For instance, let’s say we want to typeset the variable a in \sqrt{a} using the standard math font but typeset the square root symbol using bold font. To achieve that, we apply \bm to the entire expression, \sqrt{a}, but unbold a using \unboldmath:

\bm{\sqrt{\mbox{\unboldmath$a$}}}

This is the result:

     $$\bm{\sqrt{\mbox{\unboldmath$a$}}}$$

Unbolding is useful when we want to bold a command but not all its arguments.

4.2. The Alias \boldsymbol

The package offers an alias of \bm, and that’s the \boldsymbol command. It’s intended to allow for a faster migration of documents using the command \boldsymbol from the AMS package amsbsy.

The difference between the two is that the command from the bm package is better at spacing.

4.3. Does \bm Always Work?

In general, the \bm command can handle almost any input. However, it can fail if we apply it to a complex command that confuses it when it tries to determine the correct spacing. In that case, we can add an extra set of curly braces around the command:

\bm{{\cmd{args}}}

Unfortunately, this messes up the spacing, so we need to position symbols manually.

5. \mathbf vs. \bm

The most important difference is that \mathbf doesn’t work on all symbols. The \bm command does.

Further, they make symbols appear differently. While \bm only adds boldness, thus preserving everything else from the original look of its arguments, \mathbf changes the symbols when making them bold:

     \begin{align*} &\text{Plain math} && A a \\ &\textit{mathbf} && \mathbf{A a} \\ &\textit{bm} && \bm{A a} \end{align*}

6. Conclusion

In this article, we talked about bolding math symbols. If we don’t want to load any additional package, we can use the \mathbf command, but it doesn’t work in all cases. In contrast, the \bm command from the bm package is very flexible. However, the symbols don’t look the same way in these two approaches.


« 上一篇: 什么是群体智能?
» 下一篇: 参数与超参数