I'm attempting to use the newfile package and \input to automate some document generation, specifically to generate a test specification's result log from a list of actions and each action's expected results. MWE:
\documentclass{article}
\usepackage{newfile}
\newoutputstream{output}
\openoutputfile{generated.output}{output}
\newcommand{\problematic}[1]{
\expandafter\item Original: #1
% This is the problem:
\addtostream{output}{\arabic{enumi} \alph{enumii}) #1 \\}
% Clue? This results in @par in the output, rather than paragraph break
%\addtostream{output}{\arabic{enumi} \alph{enumii}) #1\par}
}
\begin{document}
\section{Original list}
\begin{enumerate}
\item An action.
\begin{enumerate}
\problematic{Simple result is fine.}
\problematic{This one is troublesome, because:
% Uncomment to break:
%\begin{enumerate}
% \item I'm having trouble
% \item writing this list.
%\end{enumerate}
}
\problematic{This result is also fine, but how to I correctly expand \#1 in addtostream?}
\end{enumerate}
\end{enumerate}
\closeoutputstream{output}
\section{Included content}
\input{generated.output}
\end{document}
\problematic should output an \item and write #1 to a stream for \input later. \expandafter works for the \item, but I'm having issues with the \addtostream. I've tried using \expandafter in various combinations to no avail. As the MWE stands, when the lines below % Uncomment to break are uncommented, compilation fails with:
! Argument of \@mklab has an extra }.
<inserted text>
\par
l.28 }
Ultimately the \problematic macro will write lines in a form suitable for input into a longtable. What is the magical incantation required to get the 1st argument of \problematic to be written to the output stream?
\expandafter\item Originalexpands theObefore\itemwhich in consequence does nothing asOis not expandable. – cgnieder Apr 29 '16 at 11:37#1but rather the opposite:\addtostream{output}{\arabic{enumi} \alph{enumii}) \unexpanded{#1}}(I also think that you don't want or need\\at the end.) – cgnieder Apr 29 '16 at 11:40\item's etc) – cgnieder Apr 29 '16 at 11:43\addtostream{output}{\noexpand\item[\arabic{enumi}\alph{enumii})] \unexpanded{#1}}and\begin{itemize} \input{generated.output} \end{itemize}– cgnieder Apr 29 '16 at 11:50\unexpanded{#1}was the magic I was after (and works in the Fully Broken Example!) If you create an answer, I'll accept it. – aejh Apr 29 '16 at 12:47^^Jwrites a newline to the file. – koppor Apr 19 '17 at 00:17