[texhax] plain TeX: separate items by comma in \write environment

Philip Taylor (RHUoL) P.Taylor at Rhul.Ac.Uk
Fri Apr 27 21:47:44 CEST 2018



Rodolfo Medina wrote:
> Now, what I want is to avoid duplicate
> entries: i.e., when two or more identical entries are present, just one be
> written down.  Please, how can I achieve that...?
Oh, that's an easy one :-)

\input eplain

\newwrite \standout
\openout \standout = temp.txt

\newtoks \temptoks

\def \write #1#2%
     {%
         \if \relax \the \temptoks  \relax
             \temptoks  = {#2}%
         \else
             \ifcsname dict:#2\endcsname
             \else
                 \temptoks  = \expandafter {\the \temptoks , #2}%
         \fi
         \fi
      \expandafter \let \csname dict:#2\endcsname = \relax
     }

\def \donewriting #1{\primitive \write #1 {\the \temptoks}\closeout #1}

\write \standout {Now}
\write \standout {Now}
\write \standout {is}
\write \standout {is}
\write \standout {is}
\write \standout {the}
\write \standout {time}
\write \standout {for}
\write \standout {all}
\write \standout {all}
\write \standout {good}
\write \standout {men}
\write \standout {etc.}
\write \standout {etc.}

\donewriting \standout
\leavevmode \vfill \eject
\input temp.txt

\end


More information about the texhax mailing list