Bold often appears too drastic. I would like to grade the weight of some fonts locally within the text, so that they stand out, but do not overwhelm.
2 Answers
This version displays Linux Libertine and Computer Modern Bright, two fonts that come in semibold weight. These are just examples; the same approach should work for other fonts. It adds \sbseries
and \textsb
commands corresponding to the standard LaTeX font selection commands.
Updated MWE for 2022
\documentclass{article}
\usepackage{iftex}
\iftutex
\usepackage{fontspec}
\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
\setmainfont{Linux Libertine O}[
FontFace = {sb}{n}{* Semibold},
FontFace = {sb}{it}{* Semibold Italic},
BoldFont = {* Bold},
BoldItalicFont = {* Bold Italic},
]
\setsansfont{CMU Bright}[
FontFace = {sb}{n}{* SemiBold},
FontFace = {sb}{it}{* SemiBold Oblique},
]
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % The default since 2018
\usepackage{cmbright}
%% Load without Biolinum, or it will replace CM Bright,
%% and without sb, or it will replace bold:
\usepackage[libertine]{libertine}
\fi % \iftutex
% Suggested by David Carlisle:
\DeclareRobustCommand\sbseries{\fontseries{sb}\selectfont}
% Suggested by Clea F. Rees:
\DeclareTextFontCommand{\textsb}{\sbseries}
\begin{document}
\framebox[10cm][s]{
\rmfamily \makebox[2.5cm][c]{Normal} \makebox[2.5cm][c]{\mdseries Medium} \makebox[2.5cm][c]{\sbseries Semibold} \makebox[2.5cm][c]{\bfseries Bold} \normalfont
} \par
\framebox[10cm][s]{
\makebox[2.5cm][c]{\textsf{Normal}} \makebox[2.5cm][c]{\textsf{\textmd{Medium}}}\makebox[2.5cm][c]{\textsf{\textsb{Semibold}}} \makebox[2.5cm][c]{\textsf{\textbf{Bold}}}
}
\end{document}
-
\textsb{something}
will change the font indefinitely and not just the weight ofsomething
. With XeLaTeX, this sends compilation into an infinite loop which I can only break bykill
ing it. Is there any particular reason not to use thelibertine
package stuff given that it has configuration forfontspec
? You want a\DeclareTextFont...
for the\text...
commands which should be defined in terms of the relevant font switch.– cfrCommented Sep 4, 2015 at 1:28 -
1
-
Thanks for the feedback! It works in PDFLaTeX, XeLaTeX or LuaLaTeX now. (The OP specifically asked for PDFLaTeX code.) The main reason I didn’t just use the package is that I wanted to demonstrate how to do it for an arbitrary font.– DavislorCommented Sep 4, 2015 at 1:57
-
1You should use
\DeclareTextFontCommand...
. Take a look at the code ofnfssext-cfr.sty
for examples of how to do this. Orfont-axes.sty
. Or the originalnfssext.sty
(but this is in the documentation of the Font Installation Guide). But, in general, you cannot show how to do it for arbitrary fonts because it cannot be done for arbitrary fonts. More precisely, to do this, you would have to take the user through all the required steps and that means reading.fd
files (if available) etc. It is just misleading to suggest otherwise.– cfrCommented Sep 4, 2015 at 2:10 -
1I took your advice and re-wrote to use \DeclareTextFontCommand. Thanks! To rephrase slightly, I was trying to show how to do it even if there’s no package that does it for you. (Someone has to write the package!)– DavislorCommented Sep 4, 2015 at 3:02
By default, the New Font Selection Scheme (NFSS) for LaTeX supports a limited range of weights and shapes. Essentially, weight-wise, only bold extended and medium are supported by default. However, many fonts packaged for (pdf)LaTeX support extensions to the scheme.
The only thing to bear in mind here is that extensions, unlike the core LaTeX NFSS, are not uniform. The commands needed to access additional weights and shapes vary from font package to font package. While groups of font packages may share a common interface, there is no interface common to all such packages.
The trick here is to read the manuals of font packages to see which shapes, weights and swishy bits they support and what commands they provide to access these extensions to LaTeX's font selection scheme.
Here are a few examples of such packages. Since you expressed a preference for pdfTeX as an engine, I concentrate on options available here. Further information and options can be found in the LaTeX Font Catalogue.
While it is occasionally possible to access font features only by creating your own extensions to the NFSS, this should be a last resort: always check the packages for support in the first instance as this is (1) easier (2) more portable and (3) less error-prone.
Libertine
The libertine
package supports semi-bold out-of-the-box for all engines. If Xe/LuaLaTeX is used, it will configure opentype versions by default; otherwise, it will use type1.
This example uses pdfLaTeX:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{kantlipsum}
\begin{document}
\kant[1]
\bfseries\kant[2]
\libertineSB\kant[3]
\end{document}
VenturisADF
Here are some examples of VenturisADF serif, titling and sans in various weights:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{venturis}
\begin{document}
Medium serif
{\bfseries Bold serif}
\texttl{\tistyle A demi-bold titling font}
{\sffamily\dbweight Demi-bold sans
\mdseries Regular sans
\lgweight Light sans
\bfseries Bold sans
}
\end{document}
ElectrumADF
Similarly, ElectrumADF features several weights:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{electrum}
\begin{document}
\textlg{From Light} through regular \textsb{and semibold} \textbf{to bold.}
\end{document}
-
You list the advantages of your approach over mine, and I don’t want to argue about which is better, but here are a few drawbacks. First, your Libertine example does not do what the OP wanted, which was to be able to switch between semibold and bold in the same document. The package maintainer only supplied a way to replace bold with semibold. Second, most OpenType fonts don’t have LaTeX packages. Third, what happens if someone using your approach wants to change fonts? There‘s a reason every font package doesn’t have its own, incompatible boldface command.– DavislorCommented Sep 4, 2015 at 6:22
-
While my solution does not work out of the box for literally every font family out there, it does work for every font family with a
sb
series, and every OpenType family with a Semibold font. If you’re going to have to look stuff up and change some of the commands whenever you change fonts anyway, better one line in the preamble than a dozen in the body of your document. That said, I think our approaches are complementary. I would personally recommend that people use semantic markup rather than put dependencies to a specific font in the body of their document.– DavislorCommented Sep 4, 2015 at 6:27 -
@Lorehead (1) The document uses semi-bold and bold Libertine (and supports maths). (2) Most opentype fonts don't have packages but they cannot be used with pdfTeX anyway. Without at least basic support, you can't use a font in (pdf)TeX. (3) This is a limitation of the current system and quite unsatisfactory. But not using provided package support typically loses you a good deal. For example,
venturis
is set up so that you can use swash characters and various styles of figures, as well as different weights and shapes. And a one-size-fits-all-approach is, sadly, unlikely to give good results.– cfrCommented Sep 4, 2015 at 11:33 -
@Lorehead The claim about
libertine
's package maintainer is just false: look at the documentation and/or take a look at the package code and/or take a look at my example.– cfrCommented Sep 4, 2015 at 11:40 -
1Thanks to Lorehead and cfr for such precise and detailed answers. Commented Sep 4, 2015 at 16:16
pdflatex
or withxe/lualatex
?fontspec
, see tex.stackexchange.com/a/264275/7883pdfrender
. \textpdfrender{TextRenderingMode=2,LineWidth=0.1pt}{enter your text here}