[Tex/LaTex] Change Verbatim Font To PCR

fontsformattingverbatim

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!

Best Answer

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

Related Question