Based on Write environment body verbatim to a file I try to write the content of a environment verbatim to a file, call an external tool (in my case the awesome Graphviz) and include the source code plus the generated graphics.
The following actually works, but displays a empty listings at the top:
\documentclass{article} \usepackage{graphicx,xcolor} \makeatletter \RequirePackage{listings} \lst@RequireAspects{writefile} \lstnewenvironment{colenv}[1]{% \lst@BeginWriteFile{#1.dot}% }{% \lst@EndWriteFile% closes output file \immediate\write18{dot -Tpdf -o #1.pdf #1.dot} \lstinputlisting{#1.dot} \includegraphics{#1.pdf} } \makeatother \definecolor{hellgelb}{rgb}{1,1,0.8} \lstset{% frame=single, % numbers=left, % backgroundcolor=\color{hellgelb}, % } \begin{document} \begin{colenv}{abc}{0.5}{0.5} digraph G { node [shape=box,style=filled, color=".6 .3 1.0"]; edge[arrowhead="none"]; a [label = "12344445"]; b [label = "67890"]; a -> b; } \end{colenv} \end{document}
Using the first solution in the above mentioned question does not work either since the value of #1 lost in the environment definition:
\documentclass{article} \usepackage{graphicx} \usepackage{xcolor} \makeatletter \RequirePackage{listings} \usepackage{fancyvrb} \newenvironment{colenv}[1] {\typeout{Writing file #1}\VerbatimOut{#1.dot}} {\endVerbatimOut % % Here it does not work \immediate\write18{dot -Tpdf -o #1.pdf #1.dot}% \lstinputlisting{#1.dot}% \includegraphics{#1.pdf}% } \makeatother \definecolor{hellgelb}{rgb}{1,1,0.8} \lstset{% frame=single, % numbers=left, % backgroundcolor=\color{hellgelb}, % } \begin{document} Test! \begin{colenv}{abc} digraph G { node [shape=box,style=filled, color=".6 .3 1.0"]; edge[arrowhead="none"]; a [label = "12344445"]; b [label = "67890"]; a -> b; } \end{colenv} % Here it works... %\immediate\write18{dot -Tpdf -o abc.pdf abc.dot}% %\lstinputlisting{abc.dot}% %\includegraphics{abc.pdf}% \end{document} results in
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix <2008/02/07> (tvz)) ! Illegal parameter number in definition of \endcolenv. <to be read again> 1 l.17 } ? 