5

I'd like to use and mdframed environment with verbatim in it. I've read the both documentations, googled but I've found nothing regarding this matter.

MWE below:

\documentclass[10pt]{article}

\usepackage[a4paper,pdftex]{geometry}
\usepackage[headings]{fullpage}

\usepackage[utf8]{inputenc}
\usepackage[magyar]{babel}
\usepackage[T1]{fontenc}

\usepackage{color}
\definecolor{shadecolor}{gray}{0.90}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage{verbatim}

\usepackage[framemethof=tikz,%
innerleftmargin=\parindent,%
linewidth=0pt,%
backgroundcolor=shadecolor,%
skipabove=0.6\baselineskip,%
skipbelow=0.6\baselineskip]{mdframed}


% How to create a new environment that uses mdframed and verbatim?
\newenvironment{magic}
{\begin{mdframed}}
{\end{mdframed}}

\begin{document}

\begin{mdframed} % How to make these
\begin{verbatim} % two into one?
From: [email protected] (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Keywords: 386, preferences
Message-ID: <[email protected]>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki
Lines: 20


Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones.  This has been brewing
since april, and is starting to get ready.  I'd like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system (due to practical reasons)
among other things). 

I've currently ported bash(1.08) and gcc(1.40), and things seem to work.
This implies that I'll get something practical within a few months, and
I'd like to know what features most people would want.  Any suggestions
are welcome, but I won't promise I'll implement them :-)

        Linus ([email protected])

PS.  Yes - it's free of any minix code, and it has a multi-threaded fs.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks, as that's all I have :-(.
\end{verbatim} % How to make these
\end{mdframed} % two into one?

\end{document}

P.S. I don't want to use the listings package, because I can set margins and stuff with mdframed perfectly, and I don't need code highlighting.

1 Answer 1

6

The following works perfectly for me:

\documentclass[10pt]{article}

\usepackage[a4paper,pdftex]{geometry}
\usepackage[headings]{fullpage}

\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}

\usepackage{color}
\definecolor{shadecolor}{gray}{0.90}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage{verbatim}

\usepackage[framemethod=tikz,%
innerleftmargin=\parindent,%
linewidth=0pt,%
backgroundcolor=gray,%
skipabove=0.6\baselineskip,%
skipbelow=0.6\baselineskip]{mdframed}


% How to create a new environment that uses mdframed and verbatim?
\newenvironment{magic}
{\begin{mdframed}}
{\end{mdframed}}

\begin{document}

\begin{mdframed} % How to make these
\begin{verbatim}

\end{verbatim} % How to make these
\end{mdframed} % two into one?
  <snip>
\end{document}

Note that I corrected your typo: framemethof vs framemethod and I changed the color that is being used. The error it gave me: Package pgfbase Error: Unsupported color model '0'. Sorry \end{mdframed}. I doubt that this is related to the combination of mdframed and verbatim. Since I get the same error when I replace the verbatim environment with some text.

Edit: Marco's comment made me realize I had misunderstood the question. I now assume uou are mainly concerned with getting a new environment that works as verbatim inside of mdframed. You can use the construct suggested by Marco in the comment along with creating a new environment for verbatim. The following code:

\newenvironment{myverb}
{\endgraf\verbatim}
{\endverbatim}

\BeforeBeginEnvironment{myverb}{\begin{mdframed}}
\AfterEndEnvironment{myverb}{\end{mdframed}}

In your document you can then use \begin{myverb} ...\end{myverb} to get a verbatim inside of an mdframed environment.

2
  • 5
    Please see the example file mdframed-example-texsx.pdf to see how you can work with \BeforBeginEnvironment (Example 1) Jan 6, 2012 at 12:20
  • 2
    Few minutes ago I uploaded version 1.2 to CTAN. Now you can simple use \surroundwithmdframed{verbatim}. With the files of github you can test it. Jan 8, 2012 at 13:07

You must log in to answer this question.

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