3

One of my current tasks involves composing an auxiliary file with extra commands to be loaded at a separate compilation. Here's an MWE:

\documentclass{memoir}
\newwrite\testaux
\immediate\openout\testaux=\jobname.myaux
\begin{document}
    \makeatletter
    \immediate\write\testaux{\noexpand\dont@want@spaces@after@this words}
    \immediate\write\testaux{\unexpanded{\dont@want@spaces@after@this@either}words}
    \makeatother
    Here is a body.
\end{document}

This produces a .myaux file with these contents:

   \dont@want@spaces@after@this words
   \dont@want@spaces@after@this@either words

I do not understand why both e-TeX macros put a space after their "expansion." What do I do to write this?

   \dont@want@spaces@after@thiswords
   \dont@want@spaces@after@this@eitherwords
4
  • use \string the space is there so that the token will be read back as it is written, if tex did not add a space the tokenization when read back is completely different Commented Jun 24, 2015 at 21:23
  • @DavidCarlisle, \string works ... answer? Commented Jun 24, 2015 at 21:24
  • TeX doesn't bother whether the command after \noexpand is defined, so you can simply type \immediate\write\testaux{\noexpand\dont@want@spaces@after@thiswords} The space is added exactly for preventing wrong interpretation when the file is read back in.
    – egreg
    Commented Jun 24, 2015 at 21:47
  • @egreg yes I wondered about giving that answer, but I assumed in the real case the OP was building the csname to read back from parts and wanted to avoid spaces. If the whole csname can be given initially then that's clearer (although adds a space at the end of course) Commented Jun 24, 2015 at 21:51

1 Answer 1

5
\documentclass{memoir}
\newwrite\testaux
\immediate\openout\testaux=\jobname.myaux
\begin{document}
    \makeatletter
    \immediate\write\testaux{\string\dont@want@spaces@after@this words}
    \immediate\write\testaux{\string\dont@want@spaces@after@this@either words}
    \makeatother
    Here is a body.
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .