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=\\\{\}}
\newcommand{\shellcommand}[1]{\textbf{\$} {\fontfamily{cmtt}\fontshape{sl}\selectfont{#1}}}
\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}
Now I'd like to create a custom environment for this. However I can't get that to work. No matter which combination of commands, environments and verbatim alternates I use, it will always lead to a parse error. Removing mdframed or verbatim works, but both of them at the same time do not. This is the closest I got, it produces the correct output but requires pressing enter about 10 times when running pdflatex to ignore the errors:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{mdframed}
\pagestyle{empty}
\DefineVerbatimEnvironment{termverb}{Verbatim}{commandchars=\\\{\}}
\newenvironment{terminal}
{\begin{mdframed}[backgroundcolor=black,fontcolor=white]
\begin{termverb}}
{\end{termverb}
\end{mdframed}}
\newcommand{\shellcommand}[1]{\textbf{\$} {\fontfamily{cmtt}\fontshape{sl}\selectfont{#1}}}
\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.