4

I want to use bold sf-fonts to designate a special kind of variable. I do this by using the bm package and then wrapping \mathsf in \bm.

Unfortunately, this approach has the side effect that somehow other text is also printed in bold but only in certain cases. The whole thing is rather weird.

\documentclass{acmart}
\usepackage{bm}

\newcommand{\mybold}[1]{\ensuremath{\bm{\mathsf{#1}}}}
\newcommand{\func}[1]{\mathit{func}\left(#1\right)}
\newcommand{\xy}{\mybold{xy}}

\begin{document}
\begin{align*}
    \func{a~\xy}
    \func{a} 
\end{align*}
\begin{align*}
    \func{a} 
    \func{a~\xy}
\end{align*}
\begin{align*}
    \func{a~\xy}\\
    \func{a} 
\end{align*}
\begin{align*}
    \func{a} \\
    \func{a~\xy}
\end{align*}
\end{document}

Produces this output:

output of the latex code

The first line happens to look like what I want, but since it seems dependent on the order of expressions, the whole macro more often than not produces the wrong outputs.

Is there any way to restrict this style to xy?

8
  • I don't know what the explanation is but I am sure someone will help. Meantime I only get the unexpected output if I compile your code by pdflatex. Any other engine, such as xelatex, and lualatex produce the correct output.
    – Celdor
    Apr 12, 2023 at 14:20
  • 1
    I can't test now but it sounds like this bug github.com/latex3/latex2e/issues/1028 Apr 12, 2023 at 14:48
  • I checked . It is the bug and the next latex will repair that. You can use \setcounter{localmathalphabets}{0} for a work-around now. Apr 12, 2023 at 14:56
  • @UlrikeFischer I was just going to say the same.... Apr 12, 2023 at 15:05
  • 1
    @DavidCarlisle so slow ... Apr 12, 2023 at 15:07

2 Answers 2

6

It is a bug which will be resolved with the next LaTeX release https://github.com/latex3/latex2e/issues/1028

As a work-around you can for now add \setcounter{localmathalphabets}{0}:

\documentclass{acmart}
\usepackage{bm}

\newcommand{\mybold}[1]{\ensuremath{\bm{\mathsf{#1}}}}
\newcommand{\func}[1]{\mathit{func}\left(#1\right)}
\newcommand{\xy}{\mybold{xy}}
\setcounter{localmathalphabets}{0}

\begin{document}
\begin{align*}
    \func{a~\xy}
    \func{a} 
\end{align*}
\begin{align*}
    \func{a} 
    \func{a~\xy}
\end{align*}
\begin{align*}
    \func{a~\xy}\\
    \func{a} 
\end{align*}
\begin{align*}
    \func{a} \\
    \func{a~\xy}
\end{align*}
\end{document}

enter image description here

4

I don't think you need bm for this purpose.

\documentclass{acmart}

\DeclareMathAlphabet{\mathbfsf}{\encodingdefault}{\sfdefault}{b}{n}
\newcommand{\mybold}[1]{\mathsf{#1}}
\newcommand{\func}[1]{\mathit{func}(#1)}
\newcommand{\xy}{\mathbfsf{xy}}

\begin{document}

\begin{align*}
    \func{a\,\xy}
    \func{a}
\\
    \func{a}
    \func{a\,\xy}
\\
    \func{a\,\xy}\\
    \func{a}
\\
    \func{a} \\
    \func{a\,\xy}
\end{align*}

\end{document}

enter image description here

Without loading bm, the count of math groups falls down to 12.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .