In the MWE below, I wonder why does the pcr
(Courier) font align in both escaped and unescaped versions and for whatever column setting of {listing}
- while the cmtt
(Computer Modern Teletype) aligns escaped and unescaped only for fullflexible
columns. The MWE is basically the same code repeated for different fonts (I would have stored it in a macro, but I'd get "Text dropped after begin of listing..." then):
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor} % \pagecolor
\pagecolor{yellow!15}
\setlength{\fboxsep}{0pt}
\begin{document}
\renewcommand{\ttdefault}{pcr}
Here entering a sample paragraph with \texttt{some} words entered in
\texttt{typewriter font}, which should also be \texttt{monospaced} - or rather,
\texttt{fixed width}. It can be quite useful for showing \texttt{variables}.
\noindent\begin{minipage}[t]{.325\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize\ttfamily,
caption={[short] Some instructions here; the font here is \texttt{\ttdefault}.},
escapechar=!,
showlines=true,
label=lst:ex1a,
columns=fixed,
frame=tlrb]
080484c4 <list>:
!\fbox{\hspace{-\fboxrule}\texttt{80484c4:\fbox{ }cmd one}\linebreak}!
80484c7: cmd two
80484ca: cmd three, four
80484cf: cmd five
80484d6: cmd six, seven
80484dd: cmd more than enough
80484e0: cmd not_even_joking
\end{lstlisting}
\end{minipage}
\hspace{1cm}
\noindent\begin{minipage}[t]{.325\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize\ttfamily,
caption={[short] Some instructions here; the font here is \texttt{\ttdefault}.},
escapechar=!,
showlines=true,
label=lst:ex1b,
columns=fullflexible,
frame=tlrb]
080484c4 <list>:
!\fbox{\hspace{-\fboxrule}\texttt{80484c4:\fbox{ }cmd one}\linebreak}!
80484c7: cmd two
80484ca: cmd three, four
80484cf: cmd five
80484d6: cmd six, seven
80484dd: cmd more than enough
80484e0: cmd not_even_joking
\end{lstlisting}
\end{minipage}
\renewcommand{\ttdefault}{cmtt}
Here entering a sample paragraph with \texttt{some} words entered in
\texttt{typewriter font}, which should also be \texttt{monospaced} - or rather,
\texttt{fixed width}. It can be quite useful for showing \texttt{variables}.
\noindent\begin{minipage}[t]{.325\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize\ttfamily,
caption={[short] Some instructions here; the font here is \texttt{\ttdefault}.},
escapechar=!,
showlines=true,
label=lst:ex2a,
columns=fixed,
frame=tlrb]
080484c4 <list>:
!\fbox{\hspace{-\fboxrule}\texttt{80484c4:\fbox{ }cmd one}\linebreak}!
80484c7: cmd two
80484ca: cmd three, four
80484cf: cmd five
80484d6: cmd six, seven
80484dd: cmd more than enough
80484e0: cmd not_even_joking
\end{lstlisting}
\end{minipage}
\hspace{1cm}
\noindent\begin{minipage}[t]{.325\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize\ttfamily,
caption={[short] Some instructions here; the font here is \texttt{\ttdefault}.},
escapechar=!,
showlines=true,
label=lst:ex2b,
columns=fullflexible,
frame=tlrb]
080484c4 <list>:
!\fbox{\hspace{-\fboxrule}\texttt{80484c4:\fbox{ }cmd one}\linebreak}!
80484c7: cmd two
80484ca: cmd three, four
80484cf: cmd five
80484d6: cmd six, seven
80484dd: cmd more than enough
80484e0: cmd not_even_joking
\end{lstlisting}
\end{minipage}
\end{document}
... and the output is this:
Now this is the weird thing for me: for fixed columns, the escaped and unescaped listing text has completely different spacing between characters (compare the 80484c
part in Listing 3) for the font cmtt
, specifically; this doesn't happen for pcr
.
So the conclusion I'm making from this, is that apparently pcr
is a "real" fixed width font, and cmtt
is "simply" a "typewriter" font, but a proportional one? But for one, cmtt
doesn't look all that proportional to me - and even if it was, it should align for columns=fixed
, shouldn't it?
So my questions are:
- is there a (simple) way to determine in Latex if a font is really fixed-width? (e.g. I'd like to type something like
\iffontfixedwidth{cmtt}\typeout{yes}\else\typeout{no}\fi
) - Could I somehow get
cmtt
to behave the same aspcr
does in{listing}
(that is, have the same alignment/spacing between letters, regardless of escaped/unescaped orcolumns=
setting)?
basewidth=0.51em,
option of{lstlisting}
- that seems to fix the behavior ofcmtt
-- but then messes up the behavior ofpcr
(in escaped vs unescaped incolumns=fixed
)! So that's not the answer...cmtt
is definitely a fixed-width font. this can be checked by looking at the width values in the.tfm
file --tftopl cmtt10
. the width of every character is reported as(CHARWD R 0.524996)
. so something else is going on here.