Math & ScienceHow do you reliably bold math

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

How do you reliably bold math

Post by Singularity »

How do you bold math? I've been using \bm, but it doesn't work with \nicefrac (or any frac, I think), and now I find it also doesn't work with \sec, and there doesn't seem to be a workaround.

I've read suggestions to use \boldsymbol, but it seems to just be another name for \bm. The command \mathbf seems to have no effect whatsoever. Command \pmb makes it "super" bold, and a bit ugly (but that might have to do).

And none of these bold across an alignment character.

Command \boldmath kicks back the warning that it is not valid in math mode (which sounds like an oxymoron), making it difficult to use on the last line of an align statement. OTOH \mathbold doesn't cause any problems, or any bolding.

So how do you bold math? Especially math with \sec, \frac, \nicefrac in it at the end of a long \align statement, and maybe including the alignment character (unless that's a deal breaker).

I'd provide an MWE, but there is no one original copy. Instead, here are sample lines I would like to be able to bold.

Code: Select all

\documentclass[14pt,fleqn,reqno]{extarticle}
\usepackage{amsfonts,amsmath,amssymb,amsthm}
\usepackage{bm,nicefrac}

                                 
\begin{document}
Bold these lines
\begin{align*}
  \vdots \\
  &\sec \left(\frac{\pi}{4}x\right) \\
  &\sec \left(\nicefrac{\pi x}{4}\right)
\end{align*}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How do you reliably bold math

Post by cgnieder »

As I noted in my answer to your other answer: you can bold \nicefrac with \mathbf. Why not use that? You also found yourself the way to use \bm inside \nicefrac. Why not use that?

Just as a sidenote: bold letters in math usually have a distinct meaning from non-bold letters. $x$ usually is the variable x while $\bm{x}$ often denotes the vector x.

Regards
site moderator & package author
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

How do you reliably bold math

Post by Singularity »

The solution to using \bm inside of \nicefrac is time consuming. BTW, someone posted an even better answer somewhere (that I don't remember and can't find).

Also, \bm it doesn't work at all \sec and \csc and who knows what else.

I'm aware of the difference between, say $\bm{x}$ and $x$. But I'm writing lesson plans which I then deliver in front of the class. I don't want to sit reading it, looking for what I want. I want to bold specific parts so I can find them fast. And that includes the last line of lengthy problems.

I want something to quickly say "bold this whole line", and then move on to the next part of what I'm writing. The precise meaning of the bold is not as important. So far, I have found \pmb. "poor mans bold"?? maybe. That's what it seems like. But I wonder if there isn't a better solution.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How do you reliably bold math

Post by cgnieder »

Singularity wrote:Also, \bm it doesn't work at all \sec and \csc and who knows what else.
I don't understand what you mean here…
However, I did a little research and learned something new myself: the switches \boldmath/\unboldmath

Code: Select all

\documentclass{article}
\usepackage{nicefrac,amsmath}
\begin{document}

$ x^2 + y^2 - \sin z = 4$ \par
$ \nicefrac{x_1}{2} + \nicefrac{x_2}{3} - \nicefrac{x_3}{6} = 5$

\boldmath
$ x^2 + y^2 - \sin z = 4$ \par
$ \nicefrac{x_1}{2} + \nicefrac{x_2}{3} - \nicefrac{x_3}{6} = 5$
\unboldmath

\begin{align}
  x^2 + y^2 - \sin z &= 4 \\
  \nicefrac{x_1}{2} + \nicefrac{x_2}{3} - \nicefrac{x_3}{6} &= 5
\end{align}

\boldmath
\begin{align}
  x^2 + y^2 - \sin z &= 4 \\
  \nicefrac{x_1}{2} + \nicefrac{x_2}{3} - \nicefrac{x_3}{6} &= 5
\end{align}
\unboldmath

\end{document}
Regards
site moderator & package author
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How do you reliably bold math

Post by Johannes_B »

You want to make it bold to find it faster on the page. How about using a frame around the equation/math to stick out. Or a little square in the margin to catch your eye?


Poor mans bold: typesetting the same letter multiple times a bit shifted to the left and the right makes it look bold. But it isn't. It is just a hackish way to get ugly bold letters for people not able to afford a real bold font. That's what poor mans bold is.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

How do you reliably bold math

Post by Stefan Kottwitz »

Generally, I think, the bm package is the best choice. I cite some features of it from my new LaTeX Cookbook:
  • Determining available bold math fonts and use them if available
  • Falling back to poor man's bold if no bold version can be found, which means overprinting with slight offsets
  • Keeping the correct spacing of the symbol
  • Respecting the meaning of symbols, such as delimiters
It just happens that \bm or others may have difficulties in making complex expressions bold. Fractions are non-trivial since they contain several parts.

Emphasizing a whole formula or section in bold is, in my opinion, not good anyway. Bold symbols usually transport a meaning. Like italic x as a variable, but bold x as a vector. It depends on the document and own style of course.

But when I think of bold symbols, I define them in a macro in the preamble. I don't use physical commands in a text. It could be very hard to change all the formatting later if a style should be changed.

So, my way with bm for a big bold X would be:

Code: Select all

\bmdefine{\bX}{X}
Later I use \bX in the text. In case I would decide to switch to medium-bold or heavy or even fancy calligraphic X, I just need to change the macro. No need to do for all occurrences in the text. And, the text has less braces and clearer names, if you would choose them.

Finally, compare bm and amsmath's \boldsymbol - also taken from an example in my book:

Code: Select all

\documentclass{article}
\usepackage{bm}
\bmdefine{\bX}{X}
\bmdefine{\bi}{i}
\bmdefine{\bMinus}{-}
\bmdefine{\bSum}{\sum}
\bmdefine{\bLeft}{(}
\bmdefine{\bRight}{)}
\begin{document}
\[ \sum_{i} ( - X_{i} ) \]
\[ \bSum_{\bi} \bLeft \bMinus \bX_{\bi} \bRight \]
\end{document}
This bm example gives:
bm.png
bm.png (9.99 KiB) Viewed 74377 times
Now to amsmath:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\newcommand{\bX}{\boldsymbol{X}}
\newcommand{\bi}{\boldsymbol{i}}
\newcommand{\bMinus}{\boldsymbol{-}}
\newcommand{\bSum}{\boldsymbol{\sum}}
\newcommand{\bLeft}{\boldsymbol{(}}
\newcommand{\bRight}{\boldsymbol{)}}
\begin{document}
\[ \sum_{i} ( - X_{i} ) \]
\[ \bSum_{\bi} \bLeft \bMinus \bX_{\bi} \bRight \]
\end{document}
That gives:
amsmath.png
amsmath.png (10.02 KiB) Viewed 74377 times
You can see the problems with amsmath \boldsymbol:
  • The summation symbol is not bold.
  • The summation index has moved.
  • The spacing between parenthesis and minus sign has become too wide.
  • The italic correction after the X is lost, the kerning is too high. That is, the index now is too far at the right.
Maybe this sample is not the fairest comparison, but I wanted to show points for bm.

Stefan
LaTeX.org admin
Post Reply