# How to change the font(size) for verbatim in ltxdoc

The MWE shows what I mean. Using class article I can change the verbatim font. Using ltxdoc nothing happens. I looked in doc.sty and ltxdoc.cls but found nothing. Why does the verbatim environment font setting behave differently in ltxdoc anyway?

%\documentclass[a4paper,12pt]{article}
\documentclass[a4paper,12pt]{ltxdoc}
\makeatletter
\newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}%
\makeatother

\verbatimfont{\normalfont\rmfamily\Large}

\begin{document}
This is normal text
\begin{verbatim}
This is verbatim text
\end{verbatim}
\end{document}


You could use the verbatimbox package, which provides an optional argument for doing all sorts of settings, including font size.

%\documentclass[a4paper,12pt]{article}
\documentclass[a4paper,12pt]{ltxdoc}
\usepackage{verbatimbox}
\begin{document}
This is normal text
\begin{verbnobox}[\LARGE]
This is verbatim text
\end{verbnobox}
\end{document}


# \MacroFont

Maybe, you are looking for \MacroFont of package doc (default font size defined by \MacroFont is \small):

\documentclass[a4paper,12pt]{ltxdoc}

\makeatletter
\makeatother

\begin{document}
This is normal text
\begin{verbatim}
This is verbatim text
\end{verbatim}
\end{document}


\MacroFont is used for environments verbatim, verbatim*, macrocode, and macros \PrintMacroName, \PrintDescribeMacro, \PrintDescribeEnv, and \PrintEnvName.

# Patching verbatim

Another solution is to patch environment verbatim. The following example shows it for verbatim and verbatim*:

\documentclass[a4paper,12pt]{ltxdoc}

\usepackage{etoolbox}
\patchcmd\verbatim{\MacroFont}{\MacroFont\Large}{}{%
\errmessage{Cannot patch enviroment verbatim'.}%
}
\expandafter
\patchcmd\csname verbatim*\endcsname{\MacroFont}{\MacroFont\Large}{}{%
\errmessage{Cannot patch environment verbatim*'.}%
}

\begin{document}
This is normal text
\begin{verbatim}
This is verbatim text
\end{verbatim}
\end{document}

• Thank you, Heiko for your answer. Is there no way to change only the font for the verbatim environment? – Jack Apr 7 '18 at 20:09
• Sorry, I saw your 'patching' solution after I wrote my simple work-around. In the meantime I prefer (and implemented) the verbnobox solution. Regards – Jack Apr 8 '18 at 17:17

I found a simple working solution as shown below. Now only the verbatim environment is affected.

\documentclass[a4paper,12pt]{ltxdoc}
\begin{document}
This is normal text
{
\renewcommand{\MacroFont}{\ttfamily\large}

\begin{verbatim}
This is verbatim text
\end{verbatim}
}
\end{document}