[Tex/LaTex] How to add overline on top of $\bm B$

boldmath-modesymbols

I represent a matrix in bold form throughout my paper, as $\bm B$. I need to add an overline to indicate a subtle transformation to this matrix. However the command $\overline{\bm{B}}$ does not seem to work. Dito with using $\bar$.

How to achieve a line on top of a bold matrix?

Best Answer

After showing how \bar and \overline can be made to work by embracing the argument, I then introduce \overlinebold that scales with math style and perhaps looks better. It uses the width of the upright version of the letter, and offsets the overstoke by 3mu to account for the italics.

\documentclass{article}
\usepackage{bm}
\usepackage{scalerel}
\def\overlinebold#1{\ThisStyle{\ooalign{%
  $\SavedStyle\mkern3mu\overline{\phantom{\mathrm{#1}}}$\cr $\SavedStyle\bm #1$}}}
\begin{document}
$\overline{\bm B}\quad \bar{\bm  B} \quad\overlinebold{B}$

$\scriptstyle \overline{\bm J}\quad \bar{\bm  J} \quad\overlinebold{J}$

$\scriptscriptstyle \overline{\bm M}\quad \bar{\bm  M} \quad\overlinebold{M}$
\end{document}

enter image description here