I want a verbatim environment with gray background color and italics(bold fonts may be used also).
The \lstlisting
can set background but can't set italics. The \mdframed
combined with \alltt
can make both of background color and italics available but will not break lines automatically.
I can't find any other ways to do it.
Hope someone can help me, thanks!
1 Answer
you can change the font used by standard verbatim by redefining \def\verbatim@font{\normalfont\ttfamily}
but mostly verbatim assumes you are going to use monospace font you could use
\maketletter
\def\verbatim@font{\normalfont\ttfamily\itshape}
\makeatother
but monospace italic is fairly horrible to read, so you could switch to
\maketletter
\def\verbatim@font{\normalfont\itshape}
\makeatother
but that doesn't preserve column alignment (so isn't as verbatim as it could be)
In either case use
\usepackage[T1]{fontenc}
as in the default OT1 encoding verbatim only works with tt font (in other OT1 encoded fonts ascii characters such as <
typeset as Spanish inverted punctuation signs)
\documentclass{...}
and ending with\end{document}
.