If I use ^^J or \iow_newline:, it prints a \Omega instead of a newline. Any idea what I got wrong?
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\printTwiceWithNewline}{v}{
\str_clear_new:N \l_test_str
\str_gput_right:Nx \l_test_str {\tl_to_str:N{#1}^^J\tl_to_str:N{#1}}
\str_gput_right:Nx \l_test_str {\iow_newline:\tl_to_str:N{#1}}
\begin{flushleft}\ttfamily
\l_test_str
\end{flushleft}
}
\ExplSyntaxOff
\begin{document}
\printTwiceWithNewline{Test}
\end{document}


^^Jis for. And this looks very much like an XY-question. – egreg Aug 30 '23 at 13:35\parnot^^J– David Carlisle Aug 30 '23 at 13:36\documentclass{article} \begin{document} ^^J \end{document}you'd get upper case omega as the output. L3 is not really part of the "problem". – Willie Wong Aug 30 '23 at 13:43\parinstead of^^Jwould likely forbid that file from being compiled in python. So do you suggest I should replace all occurrences of^^Jwith\\before printing? If so is there any other characters that might be poorly printed? – tobiasBora Aug 30 '23 at 14:15^^Jwith\parwhen printing the string only? – tobiasBora Aug 30 '23 at 14:19^^Jabove,^^Jis set up in latex to give a line break in\typeoutbut it is never used anywhere else. – David Carlisle Aug 30 '23 at 14:32\l_test_strto contain a string with newlines (e.g. python code) that I should be able to write to some files to compile later. How\l_test_stris created does not really matters (here I just manually add^^Jthat should hopefully write a\ncharacter in the string, but it might come from different sources). Then, I also want to be able to print in LaTeX the python code that I will run: for this I need to be able to print the newlines in\l_test_stras real new lines. – tobiasBora Aug 30 '23 at 14:36\par) so your pdf reader if extracting that as plain text will use\ncharacters. You do not want\ncharacters in the pdf. – David Carlisle Aug 30 '23 at 15:03verbatimenvironment: every line is marked by\par. – David Carlisle Aug 30 '23 at 15:05