I am new here and the following code is what I am testing. Is it possible to change the typeface of the words from a .txt file? Thank you for any kind help!




\section{Test section}
\subsection{Test section}
\subsubsection{Test section}
\paragraph{Test section}
\setlength{\parindent}{0pt}This document is for testing.

  • It is possible, but it's better if you give some more information. – egreg Jun 23 '13 at 9:05
  • @egreg Here is a more complicated code of mine: – 周明暘 Jun 23 '13 at 9:13
  • This doesn't explain what you'd like the font to be. – egreg Jun 23 '13 at 9:17
  • @egreg Oh yes...sorry. The file "verb.txt" is just a simple txt file. – 周明暘 Jun 23 '13 at 9:22
  • If it is just simple text and you'd like to embed it into the normal text flow, just call \input instead of \verbatiminput. – Henri Menke Jun 23 '13 at 9:23

From the verbatim package documentation (section 2.2 The interfaces, p 4):

Let us start with the simple things. Sometimes it may be necessary to use a special typeface for your verbatim text, or perhaps the usual computer modern typewriter shape in a reduced size. You may select this by redefining the macro \verbatim@font. This macro is executed at the beginning of every verbatim text to select the font shape. Do not use it for other purposes; ...

There is no interface provided to change this, so you can include


in your document preamble and then use \verbatimfont{<font>} to set the font as needed. Here's a small example:

enter image description here

\usepackage{verbatim}% http://ctan.org/pkg/verbatim

\usepackage{filecontents}% http://ctan.org/pkg/filecontents
This is some verbatim text in an external file.





The verbatimbox package was created to put verbatim into boxes. But the convenient optional argument was useful enough where I made "nobox" versions of the environments. verbnobox is, in essence, an unboxed verbatim environment that takes optional arguments that can change the print style.

If you wanted to print a file in verbatim, the nobox version of that is \verbfilenobox[optional arguments]{filename}. This just like a \verbatiminput, but with a convenient optional-argument-mechanism for changing fonts, fontsize, line numbering, etc.



 This \is a &^%$ verbatim in sffamily

 This \is a &^%$ verbatim in itshape


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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