Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a document using LaTeX, and I would like to use the PCR font inside of a verbatim block. This question is almost identical to mine, but when I try to apply it to use PCR, I can't get it to work.

This is what I am trying:

% From the question I linked above:
\makeatletter
\newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}%
\makeatother

...

\verbatimfont{pcr}
\begin{verbatim}
This should be in pcr.
\end{verbatim}

It simply outputs:

pcrThis should be in pcr.

It works fine with \verbatimfont{\scshape}, but I can't get it to work with an actual custom font. Do I need to make my own \pcr command to achieve this?

Thanks in advance!

share|improve this question

2 Answers 2

up vote 3 down vote accepted

pcr is the family name, it is used with \fontfamily, e.g.:

\documentclass{article}

\makeatletter
\newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}%
\makeatother

\begin{document}
\verbatimfont{\fontfamily{pcr}\selectfont}
\begin{verbatim}
This should be in pcr.
\end{verbatim}
\end{document}

Or

\documentclass{article}

\makeatletter
\newcommand{\verbatimfontfamily}[1]{%
  \def\verbatim@font{\fontfamily{#1}\selectfont}%
}%
\makeatother

\begin{document}
\verbatimfontfamily{pcr}
\begin{verbatim}
This should be in pcr.
\end{verbatim}
\end{document}

Or with a \pcr command:

\documentclass{article}

\makeatletter
\newcommand{\verbatimfont}[1]{%
  \def\verbatim@font{#1}%
}%
\makeatother

\newcommand*{\pcr}{\fontfamily{pcr}\selectfont}

\begin{document}
\verbatimfont{\pcr}
\begin{verbatim}
This should be in pcr.
\end{verbatim}
\end{document}

Result

share|improve this answer
    
Ah! Thanks. That worked magnificently. It says I can accept the answer in 10 minutes. :D I like that modification to the original command, too. –  Jonn Apr 21 at 13:22

Verbatim environments and macros in the verbatimbox package accept optional arguments that can change the font, font size, etc.

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}  
\begin{verbnobox}[\scriptsize]
Testing scriptsize cmtt verbatim
\end{verbnobox}
\begin{verbnobox}[\fontfamily{pcr}\selectfont]
Testing pcr verbatim
\end{verbnobox}
\end{document} 

enter image description here

share|improve this answer
    
Thanks! I'll have to look into that package. I've seen it around, but I haven't tried it. –  Jonn Apr 21 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.