I was puzzled ats \expandafter
, and I started with simple observations. Here're AI-generated explanations.
The command \expandafter
is a low-level TeX primitive that controls the order of macro expansion. Its job is to force the expansion of a token that is not immediately next to it.
In the provided code, \expandafter
is used to ensure that the recursive call \rrep
receives a concrete number as its first argument, rather than an unexpanded macro sequence.
Let's break down the key line from the \rrep
macro:
\expandafter\rrep\expandafter{\number\numexpr#1-1\relax}{\rep{#2}}