# Getting fancyvrb and mdframed to work togegher

I would like to format terminal output as follows:

• white text on black background
• commands written by the user are emphasized (slanted typewriter)

Using a combination of mdframed and fancyvrb I got this to work quite nicely:

\DefineVerbatimEnvironment{termverb}{Verbatim}{commandchars=\\\{\}}

\begin{document}

This is regular text.

\begin{mdframed}[backgroundcolor=black,fontcolor=white]
\begin{termverb}
\shellcommand{./do_something.py}
This is printed text that works properly.
\end{termverb}
\end{mdframed}

Regular text in the middle.

\begin{terminal}
\shellcommand{./do_something.py}
This does not work!
\end{terminal}

Regular text at the end.

\end{document}


Any help would be appreciated. Thanks.

Edit: It turns out this is not really possible with fancyvrb. The working solution was to change to alltt for the verbatim input part. Plain verbatim does not work because I need to get macro expansion inside the verb environment.

• Drop mdframed and use tcolorbox instead. It has loads of options to frame code. – Ulrike Fischer Nov 20 '18 at 12:51
• Can you apply the solution provided in this answer? – Arash Esbati Nov 20 '18 at 18:30

Use the short syntax \command ... \endcommand for the definition.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{mdframed}
\pagestyle{empty}

\DefineVerbatimEnvironment{termverb}{Verbatim}{commandchars=\\\{\}}
\newenvironment{terminal}
{\mdframed[backgroundcolor=black,fontcolor=white] \termverb}
{\endtermverb\endmdframed}
}

\begin{document}

This is regular text.

\begin{terminal}
\shellcommand{./do_something.py}
This is printed text that works properly.
\end{terminal}

Regular text in the middle.

\begin{terminal}
\shellcommand{./do_something.py}
This does not work!
\end{terminal}

Regular text at the end.

\end{document}