8

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.

4
  • 2
    You first need a font that has semi-bold weight. Would you like to do that with pdflatex or with xe/lualatex?
    – Bernard
    Commented Sep 3, 2015 at 16:33
  • If you’re using fontspec, see tex.stackexchange.com/a/264275/7883
    – Thérèse
    Commented Sep 3, 2015 at 16:50
  • I would prefer to use pdflatex.
    – keith77777
    Commented Sep 3, 2015 at 19:06
  • 1
    You could use the package pdfrender. \textpdfrender{TextRenderingMode=2,LineWidth=0.1pt}{enter your text here}
    – corporal
    Commented Sep 4, 2015 at 5:31

2 Answers 2

7

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}

Libertine + CM Bright font sample

12
  • \textsb{something} will change the font indefinitely and not just the weight of something. With XeLaTeX, this sends compilation into an infinite loop which I can only break by killing it. Is there any particular reason not to use the libertine package stuff given that it has configuration for fontspec? You want a \DeclareTextFont... for the \text... commands which should be defined in terms of the relevant font switch.
    – cfr
    Commented Sep 4, 2015 at 1:28
  • 1
    Also utf8x is a Bad Idea.
    – cfr
    Commented Sep 4, 2015 at 1:29
  • 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.
    – Davislor
    Commented Sep 4, 2015 at 1:57
  • 1
    You should use \DeclareTextFontCommand.... Take a look at the code of nfssext-cfr.sty for examples of how to do this. Or font-axes.sty. Or the original nfssext.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.
    – cfr
    Commented Sep 4, 2015 at 2:10
  • 1
    I 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!)
    – Davislor
    Commented Sep 4, 2015 at 3:02
2

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}

Libertine semi-bold

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}

VenturisADF

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}

ElectrumADF

7
  • 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.
    – Davislor
    Commented 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.
    – Davislor
    Commented 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.
    – cfr
    Commented 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.
    – cfr
    Commented Sep 4, 2015 at 11:40
  • 1
    Thanks to Lorehead and cfr for such precise and detailed answers.
    – keith77777
    Commented Sep 4, 2015 at 16:16

You must log in to answer this question.

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