2

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!

4
  • 2
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jun 12, 2014 at 6:41
  • If you need italics and bold, do you really need verbatim, do you need an italic monospaced font? Jun 12, 2014 at 8:36
  • I want to use italic in a verbatim environment. But in some occasions, I just use bold font to stress something. So the bold is not necessary, but the italic with verbatim is what I need.
    – mystory
    Jun 12, 2014 at 10:08
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers.
    – jub0bs
    Jun 14, 2014 at 20:00

1 Answer 1

1

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)

1
  • what about the gray background?
    – DrBeco
    Nov 7, 2021 at 4:30

You must log in to answer this question.

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