24

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?

  • 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 5 '14 at 5:09
  • 3
    @Werner, In 20 years we have not created a bold typewriter font that looks like Computer Modern with bold? – merlin2011 Dec 5 '14 at 5:15
  • 2
    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 5 '14 at 15:56
12

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}}
  • libertine is too wide. beramono seems to make no difference – tjt263 May 23 at 2:11
28

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.

  • 1
    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 5 '14 at 17:38
  • Can I choose a level for the keywords in a lstlisting? – user4417 Jan 18 at 20:06
  • @user4417 This question seems unrelated to this question or this answer. Therefore I suggest making a new question. – Heiko Oberdiek Mar 28 at 22:25
8

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}}
  • 5
    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 2 '16 at 21:44
  • 2
    It's not working with \texttt{}, only with \textsc{}. – Fuji San Oct 27 '16 at 13:22
  • 2
    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 9 '18 at 21:38

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.