I want to declare a series of commands \SA...\SZ as demonstrated here -- I want to avoid the additional \loopS command that is used though. However, merging the two lines (L1 and L2) into one (L3) does not quite work: when I call, e.g., \SA it outputs $\mathcal{Z}$ as, I guess, that is the value that is last stored in the loop variable \X. Is there a fix?
\documentclass{article}
% \def\loopS#1{\expandafter\def\csname S#1\endcsname{\mathcal{#1}}} (L1)
\newcounter{ctr}
\loop
\stepcounter{ctr}
\edef\X{\Alph{ctr}}
%\expandafter\loopS\X (L2)
\expandafter\def\csname S\X\endcsname{\mathcal{\X}} %(L3)
\ifnum\thectr<26
\repeat
\begin{document}
$\SA$
\end{document}