MWE:
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\cs_set_eq:NN __examzh_symbols_old_frac:nn \frac
\RenewDocumentCommand { \frac } { m m }
{
__examzh_symbols_old_frac:nn {#1}{#2}
}
\ExplSyntaxOff
$\frac{1}{2}$
\end{document}
I wanted to redefine the \frac for "improvement". But I found that when I wanted to "copy" a \frac by \cs_set_eq:NN, it seemed that \cs_set_eq:NN failed and I didn't know why.
Then I used \NewCommandCopy and it worked:
\documentclass{article}
\begin{document}
\ExplSyntaxOn
% \cs_set_eq:NN __examzh_symbols_old_frac:nn \frac
\NewCommandCopy { \oldfrac } { \frac }
\RenewDocumentCommand { \frac } { m m }
{
% __examzh_symbols_old_frac:nn {#1}{#2}
\oldfrac {#1}{#2}
}
\ExplSyntaxOff
$\frac{1}{2}$
\end{document}
Could you tell me what's wrong with the method of \cs_set_eq:NN?


\fracis a robust command, that means it has an specific internal structure. A simple \let (or \cs_set_eq:NN) can't properly copy this structure. That's why\NewDocumentCopyexists. – Ulrike Fischer Jul 18 '22 at 15:30\NewCommandCopy. :-) FWIW,letltxmacrowould also work here, AFAIK. – frougon Jul 18 '22 at 15:42