I am trying to process the name of a command using listofitems, but when I am using \string to convert that command it does not behave the way I think it would behave.
Here is a code to illustrate:
\documentclass[varwidth]{standalone}
\usepackage{xstring}
\usepackage{listofitems}
\makeatletter\newcommand{\currentname}{}
% Process ABC@DEF
\newcommand{\makelistA}[1]{
\setsepchar{@}%
\renewcommand{\currentname}{#1}%
\readlist\currentlist{\currentname}%
\currentname = [\currentlist[1],\currentlist[2]]\newline%
}
\newcommand{\runA}{\makelistA{ABC@DEF}}
% Process the command \ABC@DEF
\newcommand{\ABC@DEF}{}
\newcommand{\makelistB}[1]{
\setsepchar{@}%
\renewcommand{\currentname}{\StrGobbleLeft{\string#1}{1}}%
\readlist\currentlist{\currentname}%
\currentname = [\currentlist[1],\currentlist[2]]\newline%
}
\newcommand{\runB}{\makelistB{\ABC@DEF}}
\makeatother
\begin{document}
\runA % Writes ABC@DEF = [ABC,DEF] as expected
\runB % Writes ABC@DEF = [ABC@DEF,ABC@DEF] and generates errors
\end{document}
The version that process the command fails, and I cannot understand why.
Any explanation? And how to make it work?

\stringis only used to write macros without expanding them, usually to the aux file. I believe what you want is\detokenize. – John Kormylo Oct 28 '22 at 01:36