Consider the following MCE:
\documentclass{article}
\newcommand{\mynewcommand}{foo}
\NewDocumentCommand{\MyNewDocumentCommand}{}{bar}
\ExplSyntaxOn
\iow_term:x {mynewcommand=\mynewcommand}
\iow_term:x {MyNewDocumentCommand=\MyNewDocumentCommand}
\ExplSyntaxOff
\begin{document}
\begin{itemize}
\item \verb|\mynewcommand|=\mynewcommand
\item \verb|\MyNewDocumentCommand|=\MyNewDocumentCommand
\end{itemize}
\end{document}
When it is compiled, what it is displayed:
in the resulting PDF is expected:
• \mynewcommand=foo • \MyNewDocumentCommand=barin the terminal is expected for
\mynewcommandbut is unexpected for\MyNewDocumentCommand:mynewcommand=foo MyNewDocumentCommand=\MyNewDocumentCommand
Why, in the terminal, the ⟨code⟩ of \NewDocumentCommand{⟨cmd⟩}{⟨arg spec⟩}{⟨code⟩} isn't displayed, whereas the ⟨code⟩ of \newcommand{⟨cmd⟩}[⟨num⟩][⟨default⟩]{⟨code⟩} is displayed?
\newcommand{\mynewcommand}[1][]{foo}you will see why\protectedis used here – David Carlisle May 09 '23 at 13:16⟨code⟩to be displayed? – Denis Bitouzé May 09 '23 at 13:18\ShowCommand– David Carlisle May 09 '23 at 13:19\ShowCommandnot inside\iow_term:x). – Denis Bitouzé May 09 '23 at 13:23\NewExpandableDocumentCommand. But in other cases, this isn't a good idea. So it depends on what you do and want. – cabohah May 09 '23 at 13:51