10

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!

\documentclass[a4paper]{article}
\usepackage{titling}
\newcommand{\subtitle}[1]{%
  \posttitle{%
    \par\end{center}
    \vskip5em
    \begin{center}\LARGE#1\end{center}
    \vskip5em}%
}

\usepackage{palatino}
\usepackage[utf8x]{inputenc}
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{indentfirst}
\usepackage{lipsum}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{booktabs,multirow} 
\usepackage{amsmath,amssymb}
\usepackage{xcolor}
\usepackage{cite}

\begin{document}

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

\end{document}
6
  • It is possible, but it's better if you give some more information.
    – egreg
    Jun 23, 2013 at 9:05
  • @egreg Here is a more complicated code of mine:
    – 周明暘
    Jun 23, 2013 at 9:13
  • This doesn't explain what you'd like the font to be.
    – egreg
    Jun 23, 2013 at 9:17
  • @egreg Oh yes...sorry. The file "verb.txt" is just a simple txt file.
    – 周明暘
    Jun 23, 2013 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. Jun 23, 2013 at 9:23

2 Answers 2

10

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

\makeatletter
\newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}%
\makeatother

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

enter image description here

\documentclass{article}
\usepackage{verbatim}% http://ctan.org/pkg/verbatim
\makeatletter
\newcommand{\verbatimfont}[1]{\def\verbatim@font{#1}}%
\makeatother

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

\begin{document}
\verbatiminput{file.tex}

\verbatimfont{\itshape\ttfamily}
\verbatiminput{file.tex}

\verbatimfont{\scshape}
\verbatiminput{file.tex}

\end{document}
1
4

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.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{verbatimbox}

\begin{document}

\begin{verbnobox}[\sffamily]
 This \is a &^%$ verbatim in sffamily
\end{verbnobox}

\begin{verbnobox}[\itshape]
 This \is a &^%$ verbatim in itshape
\end{verbnobox}


\end{document}

enter image description here

You must log in to answer this question.

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