I want to create a control sequence using expl3 to write file content while obeying whitespace. So far I have the following MWE which does write to file, but ignores whitespace.
\documentclass[]{article}
\usepackage{expl3}
\ExplSyntaxOn
\iow_new:N \g_mwe_stream
\cs_new:Nn \write_whitespace:n {
\iow_open:Nn \g_mwe_stream { mwe.txt }
\iow_now:Nn \g_mwe_stream { #1 }
\iow_close:N \g_mwe_stream
}
\write_whitespace:n {
abc def
123 456
}
\ExplSyntaxOff
\begin{document}
\end{document}
The MWE creates the file mwe.txt which contains
abcdef123456
instead of the desired
abc def
123 456
I know I can use ~ and ^^J to manually create spaces and line breaks, but I want to avoid this. In LaTeX2 there is the \obeyspaces and \obeylines macros, but I have not found equivalents for LaTeX3.
expl
code environment is not really for 'data' (beyond short strings such as error messages). You could of course manually\char_set_catcode_space:n { `\~ }
or similar, but normally I'd use a function that reads the argument outside of the code environment.