Text FormattingRenew 'verbatim' Environment for smaller Font Size

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
echeban
Posts: 2
Joined: Wed Dec 07, 2011 1:07 am

Renew 'verbatim' Environment for smaller Font Size

Post by echeban »

How can I renew the environment verbatim so that it typesets in small font?

I attempted something like this, but can't make it work:

Code: Select all

\renewenvironment{verbatim}{\small\begin{verbatim}}{\end{verbatim}\normalsize}
Last edited by localghost on Wed Dec 07, 2011 10:54 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Renew 'verbatim' Environment for smaller Font Size

Post by localghost »

Add these lines to the preamble of your document.

Code: Select all

\makeatletter
\def\verbatim{\small\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
\makeatother
Replace the \small command with the command for the font size of your choice.

For a more flexible handling of verbatim text take a look at packages like fancyvrb, moreverb ore verbatim. For program listings take a look at the listings or minted package.


Best regards and welcome to the board
Thorsten
echeban
Posts: 2
Joined: Wed Dec 07, 2011 1:07 am

Renew 'verbatim' Environment for smaller Font Size

Post by echeban »

Thanks, it works, but not with the package \usepackage{verbatim}, which I need to use to be able to input files verbatim (\verbatiminput{}).

Reading the verbatim documentation, it says to redefine the \verbatim@font macro, which is defined as follows:

Code: Select all

\def\verbatim@font{\normalfont\ttfamily\hyphenchar\font\m@ne\@noligs}
How do I do redefine a macro? I tried inserting this definition in the preamble:

Code: Select all

\def\verbatim@font{\small\ttfamily\hyphenchar\font\m@ne\@noligs}
but it does not work.
Post Reply