Recently I discovered a piece of code (from ucharclasses) using three expansion-related macros \noexpand, \unexpanded and \expandafter:
\def\do#1{\noexpand\setTransitionsFor{#1}{####1}{####2}}
\def\doclass#1{
\begingroup\edef\x{\endgroup
\noexpand\newcommand
\unexpanded\expandafter{\csname setTransitionsFor#1\endcsname}[2]%
{\csname #1Classes\endcsname}}\x}
\ClassGroups
I can find some references about these macros, but I still don't understand what they are doing exactly. I'd like to know why they are necessary in the above piece of code, and why would we ever need four sharps as in ####1 and ####2.
\expandafter: TUGBoat 9(1):57-61, 1988. – John Jun 26 '20 at 20:38\expandafterknows about\csnameand\endcsname. That's a case explicitly listed. But in this piece of code there'sunexpandedbefore\expandafterthat still looks confusing. – Cyker Jun 26 '20 at 20:44\unexpandedis discussed in this thread. – John Jun 26 '20 at 21:37