Store text command containing itemize in a variable

The problem is that I have created a variable containing a text with some itemize environment. Now, for some reasons, I want to store the content of it in another variable. But it's not working (see the MWE)

MNWE

\documentclass{article}
\begin{document}
\def\coucou{\begin{itemize}
\item  aa
\item bb
\end{itemize}}
\coucou
\def\aa {zz}
\expandafter\xdef\csname persocmd\aa\endcsname{\coucou} %%Not working
\end{document}

• Please don't use the minimal class. It's not really well designed
– user31729
Nov 25 '15 at 15:51
• Ok I changed it to article
– Guuk
Nov 25 '15 at 15:52
• You can't use \def in an \edef or \xdef
– user31729
Nov 25 '15 at 15:53
• For example \let\anothervariable=\coucou Nov 25 '15 at 17:59

If you want to make a macro equivalent to another one, use \let (with \global if you want so):

\documentclass{article}
\begin{document}

\def\coucou{\begin{itemize}
\item  aa
\item bb
\end{itemize}}

\coucou

\def\aa{zz}
\expandafter\let\csname persocmd\aa\endcsname\coucou

\persocmdzz
\end{document}


If you want a global definition, just add \global:

\global\expandafter\let\csname persocmd\aa\endcsname\coucou


(note that \global triggers expansion of the following token, so it will correctly apply to \let).

Note that the proposed

\expandafter\gdef\csname persocmd\aa\endcsname{\coucou}


will change the meaning also of \persocmdzz if the definition of \coucou changes.

For instance

\expandafter\gdef\csname persocmd\aa\endcsname{\coucou}
\def\coucou{foo}
\persocmdzz


would print “foo” and not the itemized list.

One might force expansion of \coucou with

\expandafter\gdef\csname persocmd\aa\expandafter\endcsname\expandafter{\coucou}


but it's evident that the \let method is much easier.

\expandafter\let\csname persocmd\aa\endcsname\coucou