I would like to write a programme code to a file, so that it can be later on executed. The language requires to keep line breaks.
\begin{myCode}
one
two
three
\end{myCode}
In my macro I have following
\obeylines
which produces this output:
one^^Mtwo^^Mthree
Is there a simple way how to replace ^^M
by a line ending character that would by recognized by a Unix system? I understood that verbatim
environment processes text line by line, but in this case it's probably not necessary.
Update:
Here's the minimal working code:
\documentclass{minimal}
\usepackage{environ}
\newwrite\myOutput
\makeatletter
\def\my@writeToFile#1{
\immediate\openout\myOutput=output.txt%
\immediate\write\myOutput{#1}
\immediate\closeout\myOutput
}
\newenvironment{myCode} {
\obeylines
\Collect@Body\my@writeToFile %macro from the environ package
}{%
}
\makeatother
\begin{document}
\begin{myCode}
one
two
three
\end{myCode}
\end{document}
Best Answer
will make it put unix line end control J at the ends instead of control M,