5

I would like to print a special character to an aux file. In particular, I would like to write the line

\@input{file.aux}

So far, I have achieved the best result with

\write\@auxout{\unexpanded{\@input{file.aux}}}

However, this approach produces an additional whitespace before the first bracket.

What is the appropriate way to print special characters like \ or @ to an (aux) file? The possibly related examples provided here and here appear unnecessarily complicated and I am not quite able to implement them for my purpose.

2
  • Welcome to TeX.SX! Please use full documents instead of fragments of code ;-)
    – user31729
    Jul 6, 2015 at 20:19
  • The additional space is not of a concern, because it will be ignored at reading time.
    – egreg
    May 29, 2016 at 8:47

1 Answer 1

4

Use \string\@input{file.aux} to write the stuff literally into the .aux file. As long no further expansion is involved, this is (the best?) way to get TeX commands literally into file output.

The \immediate is not really necessary, I just use it in almost any case, that's the only reason.

\documentclass{article}

\begin{document}

\makeatletter
\immediate\write\@auxout{%
  \string\@input{file.aux}%
}
\makeatother
\end{document}
1
  • Thank you. This works. I would like to confirm that it can also be used as \write\@auxout{\string\@input{file.aux}}. Jul 6, 2015 at 20:19

You must log in to answer this question.

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