I'm using a type family that supports a semi-bold (sb) face, and I'd like to use that whenever \textbf is called for. How can I redefine \textbf to do this? Can I do it on a per family basis, or only for all families in my document at once?
3 Answers
Fonts are identified by five attributes:
- encoding
- family
- series (weight)
- shape
- size
For the first four attributes, LaTeX maintains "default" definitions, contained in
\encodingdefault\familydefault\seriesdefault\shapedefault
but also other commands
- Family defaults:
\rmdefault,\sfdefault,\ttdefault - Series defaults:
\mddefault,\bfdefault - Shape defaults:
\updefault,\itdefault,\sldefault,\scdefault
When you call \bfseries (or \textbf, which calls \bfseries internally), LaTeX looks at \bfdefault, whose normal definition is
\newcommand{\bfdefault}{bx}
and doesn't change any of the other attributes.
At a lower level LaTeX maintains also
\f@encoding\f@family\f@series\f@shape\f@sizeand\f@baselineskip
Your problem seems to be in the fact that the sans serif family has a "semibold" shape that you want to be selected in case \bfseries is called, but the roman and typewriter families don't.
A definition such as
\makeatletter
\renewcommand{\bfdefault}{\ifx\f@family\sfdefault sb\else bx\fi}
\makeatother
will do the right thing unless you call a family changing command after the switch for bold face. So
\textrm{\textbf{x}}
would work, while \textbf{\textrm{x}} wouldn't.
Another way is to use \DeclareFontShape as explained by David Carlisle
\renewcommand{\bfdefault}{sb}
\DeclareFontShape{\encodingdefault}{\rmdefault}{sb}{n}
{<->ssub*\rmdefault/bx/n}{}
\DeclareFontShape{\encodingdefault}{\rmdefault}{sb}{sl}
{<->ssub*\rmdefault/bx/sl}{}
and similarly for the typewriter type family.
In case you're using fontspec the situation is completely different, as you can fix the boldface variant on a family basis, as explained by rdhs.
- 1,121,712
If you're already using fontspec, just adjust the BoldFont setting for each family:
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\setmainfont[BoldFont="Minion Pro Semibold"]{Minion Pro}
\setsansfont[BoldFont="Myriad Pro Semibold"]{Myriad Pro}
- 6,110
-
5I had to omit the quotes to get it working, but apart from this it is a nice solution. – matth Oct 16 '12 at 12:09
Globally you can override the default definition of
\newcommand\bfdefault{bx}
with
\renewcommand\bfdefault{sb}
To do it for a single face, probably the easiest is to have a command like this one (from the base ot1cmtt.fd file)
\DeclareFontShape{OT1}{cmtt}{bx}{n}
{<->ssub*cmtt/m/n}{}
which substitutes non bold tt font for the bold version, just adjust the arguments for the font family you want to change.
- 757,742
-
1could you please explain the arguments here? (like, what is "n"? is it an integer parameter?) – Daniel Apr 30 '20 at 00:17
\usepackage[defaultsans]{open sans}and both methods above behave as if they don't recognize\sfdefault. The first method does nothing, while the second fails with "Font family `T1+fos' unknown". – orome Mar 13 '12 at 18:06\DeclareFontShapemethod now works; the\ifx\f@family\sfdefaulthas no effect. – orome Mar 13 '12 at 18:40opensansdoesn't act as expected. – egreg Mar 13 '12 at 18:47\renewcommand\bfdefault{sb}would do the trick — would you then have any idea why https://pastebin.com/W7q2LNdn doesn't seem to work? – tecosaur Jul 08 '19 at 15:28