The answers to this question explain in detail what protection is so I'm not wondering about that. My question is why a certain command definition with expl3
does not give a protected command.
Consider this LaTeX2e example:
\documentclass{article}
\DeclareRobustCommand\foo[1]{#1}
\DeclareRobustCommand\?{??}
\expandafter\DeclareRobustCommand\expandafter\-\expandafter{\-}
\begin{document}
\tableofcontents
% this is <jobname>.toc:
% \contentsline {section}{\numberline {1}\foo {bar}}{1}
% \contentsline {section}{\numberline {2}foo\?}{1}
% \contentsline {section}{\numberline {3}foo\-bar}{1}
\section{\foo{bar}}
\section{foo\?}
\section{foo\-bar}
\end{document}
Everything is working as expected.
However, when I try to do the same with expl3
the \-
is not protected:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new_protected:Npn \foo #1 { #1 } % works
\cs_new_protected:Npn \? { ?? } % works
\exp_args:NNo \cs_set_protected:Npn \- { \- } % does not work
\ExplSyntaxOff
\begin{document}
\tableofcontents
% this is <jobname>.toc:
% \contentsline {section}{\numberline {1}\foo {bar}}{1}
% \contentsline {section}{\numberline {2}foo\?}{1}
% \contentsline {section}{\numberline {3}foo\discretionary {-}{}{}bar}{1}
% \contentsline {section}{\numberline {4}foo\-bar}{1}
\section{\foo{bar}}
\section{foo\?}
\section{foo\-bar}
\section{foo\protect\-bar}
\end{document}
Am I doing something wrong or why does \exp_args:NNo \cs_set_protected:Npn \- { \- }
not leave the desired result? The only command where I could find this behaviour is \-
. Did I not look hard enough or is there something special to \-
?