I am trying to define an environment that calls an external command to draw pdfs based on the contents of the environment, and include the output.
Now I also want to be able to pass on the width and scale options to the \includegraphics
macro inside the environment end function, but I cannot get it to pass the arguments in such a way that \includegraphics
it still understands.
The small example below ends with the following error:
Package keyval Error: scale=1 undefined.
Similarly, if I try to pass width=0.5\textwidth
to the environment, it breaks with:
! Missing \endcsname inserted.
<to be read again>
\textwidth
l.32 \end{haslpicture}
Small example (in this case cupsfilter is the external command)
\documentclass{minimal}
\usepackage{environ}
\usepackage{graphicx}
\newwrite\myOutput
\makeatletter
\def\hasl@writeToFile#1{
\immediate\openout\myOutput=\[email protected]%
\immediate\write\myOutput{#1}%
\immediate\closeout\myOutput%
}
\newenvironment{haslpicture}[2][scale=1]{%
\def\hasl@filename{#2}%
\def\hasl@arguments{#1}%
\newlinechar`\^^M%
\obeylines%
\message{Optional argument: #1}
\Collect@Body\hasl@writeToFile% %macro from the environ package
}{%
\immediate\write18{cupsfilter \[email protected] > \[email protected]}%
\includegraphics[\hasl@arguments]{\[email protected]}
}
\makeatother
\begin{document}
\begin{haslpicture}[scale=1]{xoutput}
one
two
three
\end{haslpicture}
\end{document}