4

As the title says, is there any way to make bold text automatically also be typeset in sans serif? I'm thinking something along the lines of

\renewcommand{\bfdefault}{???}

I don't know what to redefine to though?

  • This question is somewhat a duplicate of tex.stackexchange.com/questions/94583/… just with family and series exchanged. However, the egreg's solution seems to be quite complicated to tweak. – yo' Oct 31 '14 at 12:06
3

Have you tried inserting

\renewcommand{\textbf}[1]{{\bfseries\sffamily#1}}

in the preamble of your document? Note the double pair of curly braces; the innner pair serves to constrain the application of \bfseries\sffamily to the argument of \textbf.

Addendum: As the comments by cgnieder and egreg allude to, the LaTeX kernel (see the file latex.ltx, ca. line 3720) provides the following definition of \textbf:

\DeclareTextFontCommand{\textbf}{\bfseries}

The macro \DeclareTextFontCommand takes care to keep things tidy if, say, \textbf is encountered while TeX is in math mode. To keep things equally tidy, then, it's preferable to redefine \textbf as follows:

\DeclareTextFontCommand{\textbf}{\bfseries\sffamily}
  • 1
    I'd rather use \DeclareTextFontCommand{\textbf}{\bfseries\sffamily} – clemens Oct 31 '14 at 12:09
  • @cgnieder I would too. This definition is really poor. – egreg Oct 31 '14 at 12:10
  • @tohecz - Fixed the double brace issue. :-) – Mico Oct 31 '14 at 12:13
  • Sorry, but this is one of the rare cases in which I feel the urge of downvoting. I'll try to resist. – egreg Oct 31 '14 at 12:20
  • @egreg - I've provided an addendum that highlights the virtue of going the DeclareTextFontCommand route. – Mico Oct 31 '14 at 12:26
5

The definition of \bfseries in latex.ltx reads

\DeclareRobustCommand\bfseries
        {\not@math@alphabet\bfseries\mathbf
         \fontseries\bfdefault\selectfont}

so it's sufficient to say

\makeatletter
\DeclareRobustCommand\bfseries{%
  \not@math@alphabet\bfseries\mathbfsf
  \fontfamily\sfdefault\fontseries\bfdefault\selectfont
}
\DeclareMathAlphabet{\mathbfsf}{OT1}{\sfdefault}{\bfdefault}{n}
\makeatother

Here's the complete example:

\documentclass{article}
\usepackage{lmodern} % for sans serif bold slanted

\makeatletter
\DeclareRobustCommand\bfseries{%
  \not@math@alphabet\bfseries\mathbfsf
  \fontfamily\sfdefault\fontseries\bfdefault\selectfont
}
\DeclareMathAlphabet{\mathbfsf}{OT1}{\sfdefault}{\bfdefault}{n}
\makeatother

\begin{document}

This {\bfseries is sans} and this \textbf{too}; what
about math? Here it is: $a\textbf{x}$; also italic is
applied: \textbf{\textit{abc}} or \textit{\textbf{abc}}.

\end{document}

Of course if serif math bold is wanted, \mathbfsf should remain \mathbf and the font alphabet declaration should be removed.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.