Variations of this question have been asked before, but those answers don't seem to work when used within \NewDocumentEnvironment
from xparse
. For example, see
Write environment body verbatim to a file
The minimal goal is to save the body of the environment verbatim to a file, and replace the body with some other file. Reading in the replacement file is easy, but saving the body is hard.
\documentclass[10pt]{article}
\ExplSyntaxOn
% I'm using xparse because I'm doing messy things with the arguments. That part works.
\NewDocumentEnvironment{intfig} { > { \SplitArgument { 1 } { , } } m o }
{
\group_begin:
\str_set:Nn \l_intfig_fout_str { test.out }
\str_set:Nn \l_intfig_fin_str { test.in }
% Here, I want to save the body to test.out.
% I tried variations with \VerbatimOut and \endVerbatimOut, along
% with elements of the listings package (\lst@BeginWriteFile).
% Reading in the replacement works.
\file_if_exist:nTF { \l_intfig_fin_str } { \input { \l_intfig_fin_str }}{}
\group_end:
}{
}
\ExplSyntaxOff
\begin{document}
\begin{intfig}{junk,14.4pt}[2cm,rubbish]
Send me to an external file, you !#^%?
Don't mess with anything in here either. I want
every space, semi-colon;;; etc.
\end{intfig}
\end{document}
@Phelype says that doing this is currently impossible, and links to some information about the current status.
Is there a way to wrap several lines in an environment so that they are passed to the containing environment as a verbatim body? Something like this
\begin{intfig}{junk,14.4pt}[2cm,rubbish]
\begin{makeintoverbatim}
Send me to an external file, you !#^%?
Don't mess with anything in here either. I want
every space, semi-colon;;; etc.
\end{makeintoverbatim}
\end{intfig}
The idea is that this would pass what is in makeintoverbatim
to \NewDocumentEnvironment
unmolested. If that were possible, then using b
(or b+
) might work when defining the intfig
environment.
ltcmd
(xparse
). Maybe thescontents
package comes close to what you want?