3

I would like to define an environment that puts verbatim text using the spverbatim package into a frame defined by the mdframed package. Here's my (naive) approach:

\documentclass{scrreprt}
\usepackage{mdframed}
\usepackage{spverbatim}
\usepackage{color}
\definecolor{lightblue}{RGB}{240,248,255}

\newmdenv
[
backgroundcolor=lightblue,
hidealllines=true,
frametitlerule=false,
frametitle=,
]{notesx}

\newenvironment{notes}
{\begin{notesx}\begin{spverbatim}}
{\end{spverbatim}\end{notesx}}

\begin{document}

% works
\begin{notesx}
\begin{spverbatim}
Test 1
Test 2
\end{spverbatim}
\end{notesx}

% does not work
\begin{notes}
Test 1
Test 2
\end{notes}


\end{document}

When using the defined environment notes I get the following error:

Runaway argument?
\end{document}
! File ended while scanning use of \@xverbatim.

Using the environment notesx with added spverbatim environment works fine.

EDIT: Using surroundwithmdframed works but when setting this for a custom defined environment \newenvironment{notes}{\begin{spverbatim}}{\end{spverbatim}} instead of spverbatim to have a nicer name it does not work: ! File ended while scanning use of \@xverbatim.

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user31729 Sep 1 '14 at 11:03
  • spverbatim is like verbatim and wants to “see” the string \end{spverbatim} for being able to end. – egreg Sep 1 '14 at 11:22
  • Using surroundwithmdframed works but when setting this for a custom defined environment \newenvironment{notes}{\begin{spverbatim}}{\end{spverbatim}} instead of spverbatim to have a nicer name it does not work: ! File ended while scanning use of \@xverbatim. @egreg What would be a possible solution for this issue? – problemzebra Sep 1 '14 at 11:28
  • @problemzebra You should update your question with this information. – Andrew Swann Sep 1 '14 at 12:57
2

You can use the same idea as spverbatim as I did in Redefine verbatim environment

With the verbatim package you can define a new environment to which apply \surroundwithmdframed.

\documentclass{article}
\usepackage{verbatim,mdframed,ragged2e}
\usepackage{color}

\definecolor{lightblue}{RGB}{240,248,255}

\surroundwithmdframed[
  backgroundcolor=lightblue,
  hidealllines=true,
  frametitlerule=false,
  frametitle=,
]{notes}

\makeatletter
\def\notes{\def\@xobeysp{\mbox{}\space}\emergencystretch=\textwidth\RaggedRight\verbatim}
\let\endnotes\endverbatim
\makeatother

\begin{document}

\begin{notes}
Something breakable but otherwise typeset @#verbatim#} with special characters accessible
Test 1
Test 2
\end{notes}

\end{document}

enter image description here

|improve this answer|||||
  • Your proposed solution works (the compiled PDF looks fine) but pdflatex shows the following error message: ! Undefined control sequence. \notes ...ergencystretch =\textwidth \RaggedRight – problemzebra Sep 1 '14 at 13:21
  • @problemzebra Sorry, I forgot to load ragged2e – egreg Sep 1 '14 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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