Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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: torva...@klaava.Helsinki.FI (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: <1991Aug25.205708.9541@klaava.Helsinki.FI>
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 (torva...@kruuna.helsinki.fi)

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
4  
Please see the example file mdframed-example-texsx.pdf to see how you can work with \BeforBeginEnvironment (Example 1) –  Marco Daniel Jan 6 '12 at 12:20
    
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. –  Marco Daniel Jan 8 '12 at 13:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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