\TeX and \LaTeX differently expl3-x-written (exhaustive expansion) to an auxiliary file
You don't want \exp_not:V
, but rather \exp_not:N
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\iow_new:N \g_output_stream
\iow_open:Nn \g_output_stream { \c_sys_jobname_str.sbj }
\iow_now:Nn \g_output_stream { \LaTeX{} }
\iow_now:Nn \g_output_stream { \TeX{} }
\iow_now:Nx \g_output_stream { \exp_not:N \LaTeX{} }
\iow_now:Nx \g_output_stream { \exp_not:N \TeX{} }
\iow_close:N \g_output_stream
\ExplSyntaxOff
\begin{document}
\end{document}
The auxiliary file will have
\LaTeX {}
\TeX {}
\LaTeX {}
\TeX {}
What's the difference? In this case \exp_not:V
does a one step expansion, which is not desired here, because \LaTeX
and \TeX
are not variables, but parameterless functions. Recall that V
stands for variable and is used to get its value, not subject to further expansion.
If we do \show\TeX
, the result is
\TeX=macro:
->T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\@.
On the other hand, the result of \show\LaTeX
is
> \LaTeX=macro:
->\protect \LaTeX .
Now \LaTeX
is defined in latex.ltx
using \DeclareRobustCommand
, and as @egreg has pointed out, \MakeRobust
can protect an existing macro in the same way.
\documentclass{article}
\MakeRobust{\TeX}
\usepackage{xparse}
\ExplSyntaxOn
\iow_new:N \g_output_stream
\iow_open:Nn \g_output_stream { \c_sys_jobname_str.sbj }
\iow_now:Nn \g_output_stream { \LaTeX{} }
\iow_now:Nn \g_output_stream { \TeX{} }
\iow_now:Nx \g_output_stream { \exp_not:V\LaTeX{} }
\iow_now:Nx \g_output_stream { \exp_not:V\TeX{} }
\iow_close:N \g_output_stream
\ExplSyntaxOff
\begin{document}
\end{document}