3

I would like to typeset almost all of a formula in bold sans-serif font using \boldsymbol and \mathsf. For example:

$$\boldsymbol{\mathsf{x+{}}}n\boldsymbol{\mathsf{{}=y}}$$

or

$$\boldsymbol{\mathsf{S}}^n\boldsymbol{\mathsf{0}}$$

Output

However, I would like to be able to do it more simply, by enclosing that parts that should be typeset normally in some sort of command. Like this:

$$\boldsymbol{\mathsf{x+\something{n}=y}}$$

Is there a way to do that?

Stefan Pinnow
  • 29,535

1 Answers1

3

Do yourself a favor and define macros:

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}

\newcommand{\svar}[1]{\bm{\mathsf{#1}}} % syntactic variable
\newcommand{\sfun}[1]{\bm{\mathsf{#1}}} % syntactic function

\begin{document}

Some text before the formula
\[
\svar{x}+n=\svar{y}
\]
and some text in between
\[
\sfun{S}^{n}\svar{0}
\]

\end{document}

enter image description here

Don't use $$ in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

Here is an alternative:

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}

\newcommand{\lf}[1]{\bm{#1}}
\newcommand{\var}[1]{\mathsf{#1}}
\newcommand{\meta}[1]{{\mathpalette\dometa{#1}}}
\newcommand{\dometa}[2]{\mbox{\mathversion{normal}$#1#2$}}

\begin{document}

Some text before the formula
\[
\lf{ \var{x}+\meta{n}=\var{y} }
\]
and some text in between
\[
\lf{ \var{S}^{\meta{n}}\var{0} }
\]

\end{document}

enter image description here

egreg
  • 1,121,712