If I want to apply the courier font to a small piece of text in my file, how can I do that? I have searched around but can't seem to find information for the courier font.
[Tex/LaTex] Use courier font inline on text
fonts
Related Solutions
Monospaced fonts usually set up two features:
- no hyphenation, and
- no stretching or shrinking of the interword spaces.
Courier, selected by \usepackage{courier}
is no exception. The reason is that enabling hyphenation or flexible interword space would have undesired effects on listings, which are the main use for monospaced fonts.
Moreover, long texts in a monospaced font are hard to read (and, of course, math fonts will clash with the text font).
However, if you want to experiment, here's a workaround:
\documentclass[
12pt,
paper=14.5cm:10.5cm,
pagesize=auto,
]{scrartcl}
\areaset{13cm}{9cm}
\usepackage[ngerman]{babel}
\renewcommand{\ttdefault}{pcr} % this is what \usepackage{courier} does
% a copy of ot1pcr.fd with changes for the interword spacing
\DeclareFontFamily{OT1}{pcr}{%
\fontdimen3\font1.67\fontdimen6\font
\fontdimen4\font1.11\fontdimen6\font
}
\DeclareFontShape{OT1}{pcr}{m}{n}{<-> pcrr7t}{}
\DeclareFontShape{OT1}{pcr}{m}{sc}{<-> pcrrc7t}{}
\DeclareFontShape{OT1}{pcr}{m}{sl}{<-> pcrro7t}{}
\DeclareFontShape{OT1}{pcr}{b}{n}{<-> pcrb7t}{}
\DeclareFontShape{OT1}{pcr}{b}{sc}{<-> pcrbc7t}{}
\DeclareFontShape{OT1}{pcr}{b}{sl}{<-> pcrbo7t}{}
\DeclareFontShape{OT1}{pcr}{m}{it}{<->ssub * pcr/m/sl}{}
\DeclareFontShape{OT1}{pcr}{bx}{n}{<->ssub * pcr/b/n}{}
\DeclareFontShape{OT1}{pcr}{bx}{sc}{<->ssub * pcr/b/sc}{}
\DeclareFontShape{OT1}{pcr}{bx}{sl}{<->ssub * pcr/b/sl}{}
\DeclareFontShape{OT1}{pcr}{b}{it}{<->ssub * pcr/b/sl}{}
\DeclareFontShape{OT1}{pcr}{bx}{it}{<->ssub * pcr/b/it}{}
\DeclareFontShape{OT1}{pcr}{m}{ui}{<->ssub * pcr/m/it}{}
\DeclareFontShape{OT1}{pcr}{b}{ui}{<->ssub * pcr/b/it}{}
\DeclareFontShape{OT1}{pcr}{bx}{ui}{<->ssub * pcr/b/it}{}
%%% end of font declarations
%---- Kein Zeileneinzug
\parindent0mm
\newcommand{\highlight}[1]{{\color{red}\textbf{#1}}}
\begin{document}
\ttfamily
Sei $M \subseteq G$ eine beliebige Teilmenge einer Gruppe $G$. Mit $\langle M \rangle$ bezeichnen wir
die kleinste Untergruppe von $G$ welche $M$ enthlt. $\langle M \rangle $ heit die erzeugte Untergruppe
von $M$ in $G$. Falls $\langle M \rangle = G$ gilt, dann sagen wir: $G$ wird von $M$ erzeugt.
\end{document}
The page size problem is solved by giving the pagesize=auto
option.
Here's the version for T1 encoded fonts, which is recommended for German.
\documentclass[
12pt,
paper=14.5cm:10.5cm,
pagesize=auto,
]{scrartcl}
\areaset{13cm}{9cm}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\renewcommand{\ttdefault}{pcr}
\DeclareFontFamily{T1}{pcr}{%
\fontdimen3\font1.67\fontdimen6\font
\fontdimen4\font1.11\fontdimen6\font
}
\DeclareFontShape{T1}{pcr}{m}{n}{<-> pcrr8t}{}
\DeclareFontShape{T1}{pcr}{m}{sc}{<-> pcrrc8t}{}
\DeclareFontShape{T1}{pcr}{m}{sl}{<-> pcrro8t}{}
\DeclareFontShape{T1}{pcr}{b}{n}{<-> pcrb8t}{}
\DeclareFontShape{T1}{pcr}{b}{sc}{<-> pcrbc8t}{}
\DeclareFontShape{T1}{pcr}{b}{sl}{<-> pcrbo8t}{}
\DeclareFontShape{T1}{pcr}{m}{it}{<->ssub * pcr/m/sl}{}
\DeclareFontShape{T1}{pcr}{bx}{n}{<->ssub * pcr/b/n}{}
\DeclareFontShape{T1}{pcr}{bx}{sc}{<->ssub * pcr/b/sc}{}
\DeclareFontShape{T1}{pcr}{bx}{sl}{<->ssub * pcr/b/sl}{}
\DeclareFontShape{T1}{pcr}{b}{it}{<->ssub * pcr/b/sl}{}
\DeclareFontShape{T1}{pcr}{bx}{it}{<->ssub * pcr/b/it}{}
%---- Kein Zeileneinzug
\parindent0mm
\newcommand{\highlight}[1]{{\color{red}\textbf{#1}}}
\begin{document}
\ttfamily
Sei $M \subseteq G$ eine beliebige Teilmenge einer Gruppe $G$. Mit $\langle M \rangle$ bezeichnen wir
die kleinste Untergruppe von $G$ welche $M$ enthält. $\langle M \rangle $ heit die erzeugte Untergruppe
von $M$ in $G$. Falls $\langle M \rangle = G$ gilt, dann sagen wir: $G$ wird von $M$ erzeugt.
\end{document}
If your verbatim text doesn't contain Cyrillic letters, you can modify the setup macro of fancyvrb
to use the T1 encoding. The problem is that TeX distributions don't feature a Cyrillic Courier compatible font.
Similarly, you can use a similar declaration for listings
.
\documentclass[10pt]{book}
\usepackage[a5paper,left=3cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{courier}
\usepackage{listings}
\usepackage{fancyvrb}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\FV@SetupFont}
{\FV@BaseLineStretch}
{\fontencoding{T1}\FV@BaseLineStretch}
{}{}
\makeatother
\lstset{
basicstyle=\fontencoding{T1}\ttfamily,
columns=fullflexible
}
\begin{document}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\begin{Verbatim}
some verbatim text in Courier
\end{Verbatim}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\begin{lstlisting}
some verbatim text in Courier
\end{lstlisting}
\end{document}
A monospaced font that has coverage for Cyrillic is PTMono; unfortunately, listings
does not behave well with UTF-8 characters (check with listings-utf8
that however requires using \lstinputlisting
).
\documentclass[10pt]{book}
\usepackage[a5paper,left=3cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[scaled=0.9]{PTMono}
\usepackage{fancyvrb}
\begin{document}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\begin{Verbatim}
some дословно text in PTMono
\end{Verbatim}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\end{document}
If you're keen to switch to XeLaTeX/LuaLaTeX, then there's no big problem, if you have an OpenType/TrueType version of Courier on your system that supports Cyrillic; in my case it's called Courier New.
\documentclass[10pt]{book}
\usepackage[a5paper,left=3cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{fontspec}
\usepackage[russian]{babel}
\usepackage{fancyvrb}
\setmainfont{Linux Libertine O} % or whatever
\setmonofont[Scale=MatchLowercase]{Courier New}
\begin{document}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\begin{Verbatim}
some дословно text in Courier
\end{Verbatim}
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
Этот текст на русском языке.
\end{document}
The same as above can be said about lstlisting
. You may also want to look at minted
.
Best Answer
Use the
courier
package. Consequently, the minimal exampleproduces
There is a marginal difference between the output generated via
\texttt{...}
with/without thecourier
package:courier
package:courier
package: