21

Reading topics about monospaced fonts, I found out that changing \tt font for the document requires replacing only one line in the preambule. For example, I only change the commented line

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% PLACE NEW FONT
\begin{document}
Default
\input{test.tex}
\end{document}

to \renewcommand

  • \renewcommand{\ttdefault}{cmtt} for Computer Modern Typewriter
  • \renewcommand{\ttdefault}{cmvtt} for Computer Modern Typewriter Proportional
  • \renewcommand{\ttdefault}{lcmtt} for Computer Modern Teletype L
  • \renewcommand*\ttdefault{lmvtt} for Latin Modern Typewriter Proportional
  • \renewcommand{\ttdefault}{pcr} for Courier
  • \renewcommand*\ttdefault{txtt} for TXTT

or \usepackage

  • \usepackage[ttdefault=true]{AnonymousPro} for Anonymous Pro
  • \usepackage{ascii} for Ascii
  • \usepackage[scaled=0.82]{beramono} for Bera Mono
  • \usepackage{courier} for Courier
  • \usepackage[scaled=1.04]{couriers} for Scaled Courier
  • \usepackage{DejaVuSansMono} for DejaVu Sans Mono
  • \usepackage[defaultmono]{droidmono} for Droid Sans Mono
  • \usepackage{inconsolata} for Inconsolata
  • \usepackage{kpfonts} for KP Monospaced
  • \usepackage{lmodern} for Latin Modern
  • \usepackage[zerostyle=d]{newtxtt} for New TXTT
  • \usepackage[ocr-a]{ocr} for OCR-A Optical Character Recognition Font A
  • \usepackage{ocr} for OCR-B Optical Character Recognition Font B
  • \usepackage{pxfonts} for PX Fonts
  • \usepackage{tgcursor} for TeX Gyre Cursor
  • \usepackage[scaled=1.05,proportional,lightcondensed]{zlmtt} for Latin Modern Typewriter Z
  • \usepackage{luximono} for LuxiMono (needed getnonfreefonts luximono)
  • \usepackage[scaled=1.05]{ulgothic} for Letter Gothic (needed getnonfreefonts lettergothic)

In the test.tex I simply use {\ttfamily ... } and I get selected font instead of default \tt.

What should I do to use the all listed above fonts in the same document?

The idea is something like this

\begin{document}
Default
\input{test.tex}
% Switch to AnonymousPro
\input{test.tex}
% Switch to ...
\end{document}
14

If you want to run a test document which includes the typewriter font alongside other styles (e.g. to test how well a particular typewriter font works with a serif used for body text) or you just don't like typing, this example provides a couple of commands for convenience:

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand*\ttfontstotry{cmtt,cmvtt,lcmtt,lmvtt,pcr,txtt}% add additional families here, separated by commas
\makeatletter
  \newcommand*\myttfontstest{% defines the actual test command
    \@for \xx:=\ttfontstotry \do {% loops through the families
      \par family: \xx\par
      \renewcommand*\ttdefault{\xx}%
      \input{test}%
    }%
  }
\makeatother

\begin{filecontents}{test.tex}% just for testing
    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    abcdefghijklmnopqrstuvwxyz

    Oh, jinxed quartz of black sphinx, go hear my vow!

    {\ttfamily
      ABCDEFGHIJKLMNOPQRSTUVWXYZ

      abcdefghijklmnopqrstuvwxyz

      Oh, jinxed quartz of black sphinx, go hear my vow!}

\end{filecontents}


\begin{document}

  \myttfontstest% try them out!

\end{document}

typewriter variants with default serif

  • Fonts ascii and cm pica work with \newfont. Do they have families? – mwloda Nov 25 '14 at 11:35
  • @user2793410 ascii is a font family but it is defined only in the package file, and it uses the 'raw' encoding U. The README for cmpica states that 'A modified version of the original companion LaTeX [2.09] style can be found floating around on the net if one looks hard.' I'd assume if a family is declared anywhere, it would be there (assuming that 'modified' means 'updated for LaTeX-2e'). – cfr Nov 25 '14 at 15:53
  • @Down-voter Any particular reason? Or just general animus? – cfr Apr 25 '15 at 23:36
13

preview

You can just use the font family without making it the default. For the packages you need to check their documentation the name of the font family used, then use it in the same way.

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}


{\fontfamily{cmtt}\selectfont abcdef 123}

{\fontfamily{cmvtt}\selectfont abcdef 123}

{\fontfamily{lcmtt}\selectfont abcdef 123}

{\fontfamily{lmvtt}\selectfont abcdef 123}

{\fontfamily{pcr}\selectfont abcdef 123}

{\fontfamily{txtt}\selectfont abcdef 123}

\end{document}
  • Does No file T1something.fd mean that something is not the name of the font family? – mwloda Nov 25 '14 at 8:32
  • @user2793410 it could mean that, or it could mean that is the name, but you do not have the font installed or (least likely) the font package does not use .fd files but includes the definitions directly in the package. – David Carlisle Nov 25 '14 at 9:20
  • @user2793410 Or it could mean that the font family is not available with the T1 encoding but only set up to support (an)other encoding(s). – cfr Nov 25 '14 at 15:45
7

David Carlisle's answer is about changing current font. The answer from cfr changes \ttdefault.
I cannot call my solution complete because I couldn't make it for all the fonts. Looking for font families names took me some time. So I put them in my own answer.

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% Store the default font
\edef\oldtt{\ttdefault}
% Fonts from packages
\usepackage{ascii}
\usepackage[scale=1.05,ttdefault=true]{AnonymousPro}
\usepackage[scaled=0.84]{beramono}
\usepackage[scaled=1.04]{couriers}
\usepackage[scaled=0.9]{DejaVuSansMono}
\usepackage[defaultmono]{droidmono}
\usepackage[scaled=0.95]{inconsolata}
   %\usepackage{kpfonts}
   % ! LaTeX Error: Option clash for package textcomp.
   %\ifkp@text\ifkp@textcomp\RequirePackage[full]{textcomp}\fi\fi
\usepackage[nomath,notext]{kpfonts}
\usepackage{lmodern}
\usepackage[scaled=0.84]{luximono} % getnonfreefonts luximono
\usepackage[zerostyle=d,scaled=0.96]{newtxtt}
   %\usepackage{ocr}
\usepackage[scaled=.93]{newtxtext}
   %\usepackage{pxfonts}
   %\usepackage{txfonts}
\usepackage{tgcursor}
\usepackage[scaled=0.92]{ulgothic} %  getnonfreefonts lettergothic
\usepackage[scaled=1.20,proportional,lightcondensed]{zlmtt}

\addtolength{\voffset}{-1.5cm}
\addtolength{\hoffset}{-2.0cm}
\addtolength{\textheight}{3.0cm}
\addtolength{\textwidth}{4.0cm}

\begin{document}
% The last one
\ttdefault\\ % why do I get zlmvtt?
\input{testtt}

% Back to default
\renewcommand{\ttdefault}{\oldtt}
Default\\
\input{testtt}

pcr\\
{\renewcommand{\ttdefault}{pcr} \input{testtt}}

cmtt\\
{\renewcommand{\ttdefault}{cmtt} \noindent\input{testtt}}

cmvtt\\
{\renewcommand{\ttdefault}{cmvtt} \noindent\input{testtt}}

lcmtt\\
{\renewcommand{\ttdefault}{lcmtt} \noindent\input{testtt}}

lmvtt\\
{\renewcommand{\ttdefault}{lmvtt} \noindent\input{testtt}}

txtt\\
{\renewcommand{\ttdefault}{txtt} \noindent\input{testtt}}

AnonymousPro\\
{\renewcommand{\ttdefault}{AnonymousPro} \noindent\input{testtt}}

Beramono\\
{\renewcommand{\ttdefault}{fvm} \noindent\input{testtt}} % Beramono

% Courier == pcr

Scaled Courier\\
{\renewcommand{\ttdefault}{pcrs} \noindent\input{testtt}} % Scaled Courier

DejaVuSansMono\\
{\renewcommand{\ttdefault}{DejaVuSansMono-TLF} \noindent\input{testtt}}

Droid Mono\\
{\renewcommand{\ttdefault}{fdm} \noindent\input{testtt}} % Droid Mono

Inconsolata\\
{\renewcommand{\ttdefault}{zi4} \noindent\input{testtt}} % inconsolata

KP tt\\
{\renewcommand{\ttdefault}{jkptt} \noindent\input{testtt}} % KP tt

Latin Modern\\
{\renewcommand{\ttdefault}{lmtt} \noindent\input{testtt}} % latin modern

LuxiMono\\
{\renewcommand{\ttdefault}{ul9} \noindent\input{testtt}} % LuxiMono

New TXTT\\ 
{\renewcommand{\ttdefault}{newtxtt} \noindent\input{testtt}} % New TXTT

% Optical Character Recognition Font B ?

% PX Font tt == TX Fonts == txtt ?

New TX\\
{\renewcommand{\ttdefault}{ntxtt} \noindent\input{testtt}} % New TX

qcr\\
{\renewcommand{\ttdefault}{qcr} \noindent\input{testtt}} % gyre cursor looks like courier ?

Letter Gothic\\
{\renewcommand{\ttdefault}{ulg} \noindent\input{testtt}} % Letter Gothic

zlmtt\\
{\renewcommand{\ttdefault}{zlmtt} \noindent\input{testtt}} % Latin Modern Typewriter Z

ascii\\
{\asciifamily \noindent\input{test}} % No file T1ascii.fd

\end{document}

Fo the testtt.tex file (File test.tex for ascii is without {\ttfamily ... })

{\ttfamily 
Normal {\bfseries Bold} 
{\slshape Slanted} {\bfseries\slshape Slanted\&Bold} 
{\itshape Italic} {\bfseries\itshape Italic\&Bold} 
Z2 lI1 S5 O0}

I get the following font comparison (attention, some fonts are scaled!).

Fonts comparison

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.