54

This question was asked and answered 20 years ago but I wonder if there is a more modern solution today that does not involve quite so much hackery with overriding settings in font files.

I want my font to look exactly like the result of \texttt but in bold face.

How might I achieve this?

merlin2011
  • 3,343
  • 2
    I would guess the same solution still holds. Mainly that \texttt (using Computer Modern Typerwriter font) does not have a bold font. So you'd have to get a bold typewriter font first... – Werner Dec 05 '14 at 05:09
  • 5
    @Werner, In 20 years we have not created a bold typewriter font that looks like Computer Modern with bold? – merlin2011 Dec 05 '14 at 05:15
  • 3
    i did this 30+ years ago, for a special project. the problem is, cmtt is too heavy to support a bold that is readable, and not bold enough to look bold unless the companion lightface is so light that it breaks up in printing. so two new fonts had to be created -- one lighter and one bolder. (they were never released.) latin modern has fixed the problem. – barbara beeton Dec 05 '14 at 15:56
  • Use the courier font: \usepackage{courier} - see: https://tex.stackexchange.com/a/619953/171556 – Victoria Stuart Jan 06 '24 at 18:56

4 Answers4

48

There are the Latin Modern Fonts, from their README:

The fonts are based on Donald E. Knuth's Computer Modern fonts in the PostScript Type 1 format

In family lmtt, there are even three series:

\documentclass{article}
% \usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
\ttfamily
\fontseries{l}\selectfont light
\fontseries{m}\selectfont medium
\fontseries{b}\selectfont bold
\end{document}

Result

They are also available in OpenType font format with a math version.

The number of glyphs is dramatically increased in comparison to the old Computer Modern fonts.

Thus indeed much has happened in the last twenty years.

Heiko Oberdiek
  • 271,626
  • 2
    cfr-lm includes commands to switch analogous to the standard end-user font commands e.g. \textlg{} and \lgweight. (Not series because that conflates two dimensions of fonts: weight and width.) – cfr Dec 05 '14 at 17:38
  • Can I choose a level for the keywords in a lstlisting? – user4417 Jan 18 '19 at 20:06
  • 1
    @user4417 This question seems unrelated to this question or this answer. Therefore I suggest making a new question. – Heiko Oberdiek Mar 28 '19 at 22:25
24

I just ran across it and found a simpler answer here: https://en.wikibooks.org/wiki/LaTeX/Fonts

\usepackage{bold-extra}
...
\texttt{TT Text \textbf{Bold TT Text}}
Werner
  • 603,163
user99745
  • 257
  • 6
    Welcome to TeX.SE. Note that the site you say the excerpt is from has the code snippet as \textsc{TT Text \textbf{Bold TT Text}}, not as \texttt{TT Text \textbf{Bold TT Text}}. Please indicate how you can get your code snippet to work. – Mico Mar 02 '16 at 21:44
  • 3
    It's not working with \texttt{}, only with \textsc{}. – Fuji San Oct 27 '16 at 13:22
  • 4
    Prompted by another answer/comment, I tried this myself, and it works for me on TeX Live 2017 on macOS. (\documentclass{article} \usepackage{bold-extra} \begin{document} \texttt{TT Text \textbf{Bold TT Text}} \end{document}) The first time I ran it, METAFONT was invoked (via mktextfm via kpathsea) to create the font cmttb10. Note that this is a bitmap font (and with sufficient zoom visible as such in the PDF), but at typical print and screen resolutions, this is not a problem. – ShreevatsaR Feb 09 '18 at 21:38
  • I will remember this one! +1 – Amir Parvardi Dec 09 '19 at 12:24
  • This is great, and a solution that "just works" in the way you'd hope +1. – Huck Bennett Oct 22 '20 at 20:37
16

Use Bera Mono:

[...]
\usepackage[T1]{fontenc}
\usepackage{libertine}%% Only as example for the romans/sans fonts
\usepackage[scaled=0.85]{beramono}
[...]
\begin{document}
\texttt{\textbf{foo}}
1

I just solved the same problem. I'm using a ready-made template where individual packages are often colliding. Verbatim fragments (verb, texttt) overflow the page. I finally decided to go with the not exactly correct solution.

{\fontfamily{lmtt}\fontseries{b}\selectfont my coding in text}

I only changed the font style for the text to bold Latin Modern Sans Typewriter.