5

Is there a way to set an option of fontsize that would affect the command \verbatiminput ?

MWE:

\documentclass{article}
\usepackage{verbatim}

% NOT WORKING
%\makeatletter
%\newcommand{\verbatimfont}[1]{\renewcommand{\verbatim@font}{\ttfamily#1}}
%\makeatother

\begin{document}
        \verbatiminput{test.txt}
\end{document}

4 Answers 4

5

You can patch \verbatim@input:

\documentclass{article}
\usepackage{verbatim}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\verbatim@input}{\@verbatim}{\scriptsize\@verbatim}{}{}
\makeatother

\begin{document}

Some text before to check the size

\verbatiminput{\jobname.tex}

Some text after to check the size

\end{document}

enter image description here

3

verbatimbox package as an alternative uses an optional argument.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{test.tex}
This is my file
&*!@#$%^
&*()
and other \verbatim stuff
\end{filecontents*}
\usepackage{verbatimbox}
\begin{document}
\verbfilenobox[\LARGE]{test.tex}
\verbfilenobox[\tiny]{test.tex}
\verbfilenobox[\itshape]{test.tex}
\verbfilenobox[\mbox{\scriptsize\theVerbboxLineNo:} ]{test.tex}
\end{document}

enter image description here

3
  • pros: it's compatible with minipage and tikz nodes! cons: a bit slow for loading large files
    – Thomas
    Apr 25, 2018 at 14:43
  • 1
    @Thomas I hope I need not remind you of the anecdote of the old and young bull who come over the top of a hill and spy a field below with a number of pretty cows grazing. This forum is not the appropriate place to relate the anecdote, but I will just say this about that: slow is not always a bad thing. ;^) Apr 25, 2018 at 14:46
  • never heard of it, now I'll have to do some research and reading:) (edit: thanks urban dictionary)
    – Thomas
    Apr 25, 2018 at 15:35
3

You could also use the listings package wich offers the basicstyle option.

See here for more information on the package settings.

\documentclass{article}
\usepackage{filecontents}
\usepackage{listings}
\begin{filecontents*}{test.tex}
This is my file
&*!@#%^
&*()
and other stuff
\end{filecontents*}
\begin{document}
\lstinputlisting[basicstyle=\footnotesize]{test.tex}
\lstinputlisting[basicstyle=\tiny]{test.tex}
\lstinputlisting[basicstyle=\Huge]{test.tex}

\end{document}

enter image description here

0

I somehow figured out an ugly way of doing it, not very satisfying ...

\documentclass{article}
\usepackage{verbatim}

\begin{document}
        {\tiny
        \verbatiminput{test.txt}
        }
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .