
Este es el código (estoy intentando crear un entorno textual que guarde todo en un archivo):
\documentclass{article}
\NewDocumentEnvironment{foo}{b}{%
\newwrite\myfile
\immediate\openout\myfile=myfile.txt
\immediate\write\myfile{\detokenize{#1}}
\immediate\closeout\myfile
}{}
\AddToHook{env/foo/before}{\obeylines\obeyspaces}
\begin{document}
\begin{foo}
First \LaTeX
% Second
Third
\end{foo}
\end{document}
Espero este contenido en myfile.txt
:
First \LaTeX
% Second
Third
Sin embargo, obtengo:
^^MFirst \LaTeX ^^MThird^^M
¿Cómo arreglar tanto el símbolo de comentario como ^^M
(espero que esté allí el EOL normal)? Además, el espacio posterior \LaTeX
no debe estar ahí.
Respuesta1
Esta es la misma que tu última pregunta.
\documentclass{article}
\newwrite\myfile
\NewDocumentEnvironment{foo}{b}{%
% no \newwrite\myfile
\immediate\openout\myfile=myfile.txt
\immediate\write\myfile{\detokenize{#1}}%
\immediate\closeout\myfile
}{}
\AddToHook{env/foo/before}{%
\newlinechar=\endlinechar% as before
\catcode`\%=12\relax
\obeylines\obeyspaces}
\begin{document}
\begin{foo}
First \LaTeX
% Second
Third
\end{foo}
\end{document}