1

I would like to write a text file from a LaTeX document with the following format:

A,C,D,B

where A, C, D and B are to be written into the text file from different places of the LaTeX document. Thus, I cannot at once write

A,C,D,B

but

A,

and then

C,

and so on.

Could you please help me?

Thanks in advance,

Paul

3

You can accumulate in a token register and write them all together

\documentclass{article}

\newtoks\mywritetoks
\newwrite\mywritefile
\def\mywrite#1{%
\expandafter\ifx\expandafter\vadjust\the\mywritetoks\vadjust
\global\mywritetoks{#1}%
\else
\global\mywritetoks\expandafter{\the\mywritetoks,#1}%
\fi
}

\begin{document}

\mywrite{A}

\mywrite{C}
\mywrite{D}
\mywrite{B}

\immediate\openout\mywritefile=\jobname.zzz
\immediate\write\mywritefile{\the\mywritetoks}
\immediate\closeout\mywritefile
\end{document}

Produces

A,C,D,B

in \jobname.zzz

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.