Consider the following example, what is the correct way to use \csname and \endcsname inside \xpatchcmd?
\documentclass{article}
\usepackage{regexpatch}
\begin{document}
\def\foo{foo}
\def\bar{with a macro \foo}
\bar
% \xpatchcmd{\bar}{\foo}{bar}{}{\FAIL}
\xpatchcmd{\bar}{\csname\foo\endcsname}{bar}{}{\FAIL}
\bar
\end{document}
\xpatchcmdare ever expanded. (BTW, at least it should be\csname foo\endcsname, but it does not work either). You need a bit of\expandaftermagic, so I let it to other wizards. Are you sure this is not a "XY" problem? (But you can have a look at https://tex.stackexchange.com/questions/104506/expanding-arguments-before-macro-call, so you can see what I mean by\expandaftermagic...) – Rmano Mar 01 '22 at 08:41\csname foo\endcsnameand\csname\foo\endcsnameto be the same since the content of\foois exactlyfoo. And true, this is a "XY" problem, I'm trying to patch command inside another command which receives certain names of macros as its argument, so I think using\csnamehere can be convenient. – Jinwen Mar 01 '22 at 08:46ospecifier inexpl3without success. I believe anexpl3approach can save us from those terribly many\expandafters. – Jinwen Mar 01 '22 at 08:52\exp_args:Nnonnn– Rmano Mar 01 '22 at 08:58