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#1
andr#1
are used? they look like conditionals - I checked that
#2
and#3
correspond 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#1
and\ifx r#1
are 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}$
\ifx
compares the next two tokens, without expansion. A\strut
is a zero-width character that extends vertically from the allocated character depth to the allocated character height.