I'd like to select a new font for the monospaced text such as those parts within a \texttt{} and code snippets in the minted context. (As far as I can tell, minted just uses the document's default typewriter font, so I don't think I need to touch its settings.) I just want to change to another monospaced font that looks all right and has a normal tilde character. How do I do that?
Asked
Active
Viewed 2.6k times
8
workerjoe
- 457
3 Answers
10
It's the \ttdefault command which normally takes care of this.
\documentclass{article}
\begin{document}
\texttt{How to use a typewriter font}% CM default typewriter font
\par
\renewcommand\ttdefault{cmvtt} % selects CM typewriter proportional font
\texttt{How to use a typewriter font}
\par
\renewcommand{\ttdefault}{pcr} % selects Courier font
\texttt{How to use a typewriter font}
\end{document}

But indeed it's usually best to let dedicated packages as beramamono do this, since there can be a lot of subtleties behind fonts (of which I'm often not aware myself :-)
Franck Pastor
- 18,756
-
Refer to fonts - Quickest way to search for valid \fontfamily arguments? - TeX - LaTeX Stack Exchange for a list of possible fontfamilies. – user202729 May 10 '23 at 03:32
4
\usepackage[scaled=0.8]{FiraMono}
Put the above line in the preamble of your document, i.e. immediately after
\documentclass. That's it!
Concerning the related question of what font to choose, see my answer at
Alternative monospace fonts.
Reference:
https://tug.org/FontCatalogue/typewriterfonts.html
-
Other fonts work this way too, like Pandora:
\usepackage{pandora}– Paulo Raposo Nov 06 '21 at 21:17
2
Since this just got bumped back up to the front page, I’ll add for completeness: in fontspec, use \setmonofont.
Davislor
- 44,045
-
Yeah, actually I don't have
fontspecin my preamble (since I use just pdfLaTeX). – Henke - Нава́льный П с м Oct 13 '20 at 14:45 -
-
To get a list of available fonts refer to https://tex.stackexchange.com/a/177084/250119 (this one for Linux only, I don't know if a better question exist). – user202729 May 10 '23 at 03:33
\usepackage{beramono}for example. There are other fonts too. Which font do you want? Visit http://www.tug.dk/FontCatalogue/typewriterfonts.html` for details. – Feb 14 '15 at 00:44