8

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} 

worksbasically

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 } ? 

1 Answer 1

5

enter image description here

The name of the file and a command to run are saved globally with \xdef\d@tn@me and \xdef\r@ncmd, and two token registers + \edef\d@r@ncmd are used to reduce the number of \expandafter commands.

\documentclass{article} \usepackage{graphicx} \usepackage{xcolor} \RequirePackage{listings} \usepackage{fancyvrb} \makeatletter \newenvironment{colenv}[1]% {\xdef\d@tn@me{#1}% \xdef\r@ncmd{dot -Tpdf -o #1.pdf #1.dot}% \typeout{Writing file #1}\VerbatimOut{#1.dot}% } {\endVerbatimOut % \toks0{\immediate\write18}% \expandafter\toks\expandafter1\expandafter{\r@ncmd}% \edef\d@r@ncmd{\the\toks0{\the\toks1}}\d@r@ncmd % \lstinputlisting{\d@[email protected]}% \includegraphics{\d@[email protected]}% } \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} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.