書き込みストリームをブロックせずに \@writefile を使用するにはどうすればよいでしょうか?

書き込みストリームをブロックせずに \@writefile を使用するにはどうすればよいでしょうか?

私の理解では、適切に使用するには、\@writefile次のように書き込みストリームをブロックする必要があります。

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\makeatletter
\newwrite\tf@foo
\openout\tf@foo=\jobname.foo
\newcommand\foo[1]{%
    Writing ``#1'' to \texttt{\jobname.foo}!%
    \protected@write\@auxout{}{\string\@writefile{foo}{#1}}%
    }
\makeatother

\foo{Bar}

\end{document}

.foo(これにより、実際には1 行に が含まれるファイルが作成されますBar。)

書き込みストリームをブロックする方法はありますか?

関連情報