I am reading through the definition of \cfrac in AMSMath...
\newcommand{\cfrac}[3][c]{{\displaystyle\frac{%
\strut\ifx r#1\hfill\fi#2\ifx l#1\hfill\fi}{#3}}%
\kern-\nulldelimiterspace}
Can someone explain a bit how this code works? Immediately see the newcommand used to define \cfrac and that it take three arguments. I don't know what [c] means here.
Then onto the main portion. Continued Fractions are presented display style. However,
- can someone explain to me how
l#1andr#1are used? they look like conditionals - I checked that
#2and#3correspond to the numerator and denominator
I can sort of distinguish the important parts
{{\displaystyle
\frac{ \strut
\ifx r#1\hfill\fi
#2
\ifx l#1\hfill\fi}
{#3}}
\kern-\nulldelimiterspace}
Then if I replace #2 with A and #3 with B I get a nice fraction... just like \frac{A}{B}
\ifx is always followed by the backwards-if \fi -- then what are the conditionals r#1 and l#?
and what is the rule of \strut ?
There is discussion of \kern and \nulldelimiterspace in other parts of this site

\newcommand{\cfrac}[3][c]means three arguments, the first of which is optional, defaulting toc, when not provided in square brackets. Indeed,\ifx l#1and\ifx r#1are comparisons of whether left or right alignment has been specified as the optional first argument. Try and compare `$\cfrac[l]{x}{v^2}$$\cfrac[c]{x}{v^2}$
$\cfrac[r]{x}{v^2}$`
– Steven B. Segletes Oct 16 '16 at 19:42\ifxcompares the next two tokens, without expansion. A\strutis a zero-width character that extends vertically from the allocated character depth to the allocated character height. – Steven B. Segletes Oct 16 '16 at 19:45