0

Why this does not work when the lines are produced using \newline (instead of ^^J) and \StrSubstitute as follows? Thanks

\documentclass{article}
\usepackage{xstring}

\begin{document}

\def\mystrings{\noindent\StrSubstitute{% B; new; test old; found people; sun; atom; number; life}% {; }{\noexpand\noexpand\noexpand\newline}} \mystrings % B % new % test old % found people % sun % atom % number % life

\newwrite\file \immediate\openout\file=mystrings.txt \immediate\write\file{\mystrings} \closeout\file

\end{document}

Krantz
  • 159
  • \StrSubstitute is not expandable, it won't work in \write. – Ulrike Fischer Oct 28 '23 at 13:45
  • Hi @Ulrike Fischer. Thank you. How can we solve this then? Any thoughts? – Krantz Oct 28 '23 at 13:46
  • in expl3 are expandable commands, or you do the substitution first and only write the result string. – Ulrike Fischer Oct 28 '23 at 13:51
  • xstring commands generally are not expandable, also why use \newline here? that adds some glue and penalties to affect tex's typesetting algorithms but doesn't do anything useful in a \write – David Carlisle Oct 28 '23 at 14:01
  • Hi @ Ulrike Fischer @DavidCarlisle. Thank you. newline was added to replace ; with new line. And that does the job as you can see. The problem was when trying write. – Krantz Oct 28 '23 at 14:09

1 Answers1

1

It's not really clear what you want here but perhaps

\documentclass{article}

\begin{document}

\def\mystrings{ B; new; test old; found people; sun; atom; number; life}%

\newwrite\file \immediate\openout\file=mystrings.txt {\newlinechar=`; \immediate\write\file{\mystrings} } \closeout\file

\end{document}

which produces the file

 B
 new
 test old
 found people
 sun
 atom
 number
 life
David Carlisle
  • 757,742