How can I lower the last term of a continued fraction when it follows a diagonal row of dots?
2 Answers
Here's how I'm inputting continued fractions. The dots must be input with a \cfrac prefix, so \cfracdots for the effect shown below, \cfraccdots for centered dots, \cfracldots for low dots or \cfracddots for standard diagonal dots.
\documentclass{article}
\usepackage{xparse,amsmath}
\ExplSyntaxOn
\NewDocumentCommand{\cfracdots}{ }
{
\rule{0pt}{1.5\baselineskip}
\raisebox{.5\baselineskip}{\enspace$\ddots$\enspace}
}
\NewDocumentCommand{\cfraccdots}{}{\cdots}
\NewDocumentCommand{\cfracddots}{}{\ddots}
\NewDocumentCommand{\cfracldots}{}{\ldots}
\NewDocumentCommand{\xcontfrac}{ s O{c} >{\SplitArgument{1}{;}}m }
{
\IfBooleanTF{#1}
{ \cfrac_inline:nn #3 }
{ \cfrac_map:nnn { #2 } #3 }
}
\cs_new:Npn \cfrac_inline:nn #1 #2
{
\IfNoValueTF { #2 }
{
\tl_use:N \c_cfrac_message_tl
\xcontfrac*{;#1}
}
{
\group_begin:
\cs_set_eq:NN \cfracdots \dots
[\, \tl_if_empty:nTF { #1 } { 0 } { #1 } ; #2 \,]
\group_end:
}
}
\tl_const:Nn \c_cfrac_lbrace_tl { \if_true: { \else: } \fi: }
\tl_const:Nn \c_cfrac_rbrace_tl { \if_false: { \else: } \fi: }
\tl_const:Nn \c_cfrac_strut_tl { \vrule width 0pt depth .3\baselineskip }
\tl_new:N \l_cfrac_left_tl
\tl_new:N \l_cfrac_right_tl
\msg_new:nnn { cfrac } { wrong-syntax }
{
Wrong~syntax~for~\token_to_str:N \xcontfrac,~
assuming~0~in~the~integer~part,~on~line~\msg_line_number:.
}
\cs_new:Npn \cfrac_map:nnn #1 #2 #3
{
\tl_clear:N \l_cfrac_left_tl \tl_clear:N \l_cfrac_right_tl
\IfNoValueTF { #3 }
{
\msg_warning:nn { cfrac } { wrong-syntax }
\xcontfrac[#1]{;#2}
}
{
\tl_if_empty:nTF { #2 }
{ \cfrac_map_aux:nn { #1 } { \exp_not:N \use_none:n , #3 } }
{ \cfrac_map_aux:nn { #1 } { #2 , #3 } }
}
}
\cs_new:Npn \cfrac_map_aux:nn #1 #2
{
\clist_map_inline:nn { #2 }
{
\tl_put_right:Nn \l_cfrac_left_tl { \cfrac_begin:nn { #1 } { ##1 } }
\tl_put_right:Nn \l_cfrac_right_tl { \exp_not:N \c_cfrac_rbrace_tl }
}
\tl_set:Nx \l_cfrac_left_tl
{ \l_cfrac_left_tl \c_cfrac_strut_tl \l_cfrac_right_tl }
\tl_set:Nx \l_cfrac_left_tl { \l_cfrac_left_tl }
\exp_after:wN \use_none:nnnnnn \l_cfrac_left_tl
}
\cs_new:Npn \cfrac_begin:nn #1 #2
{
\exp_not:n
{ + \exp_not:N \cfrac[#1] { 1 } \c_cfrac_lbrace_tl \exp_not:N \mathstrut #2 }
}
\ExplSyntaxOff
\begin{document}
\[
x=\xcontfrac*{;a_1,a_2,\cfracdots,a_n}=
\xcontfrac{;a_1,a_2,\cfracdots,a_n}
\]
\end{document}
As you can see, the same input can be used to typeset the continued fraction in in-line form or expanded, just adding the *. This allows to avoid counting braces and indenting the input.
The integer part can be omitted if zero; it won't be typeset in the expanded form (but the semicolon is mandatory).

- 1,121,712
I'm answering my own question here, in the hope that other people might find this useful. The question is similar, but not identical, to the one here, which asks how to precede the last term in a continued fraction with a diagonal ellipsis. I'm interested in lowering the final term, which comes after the ellipsis, very slightly, so that it looks as though the ellipsis is pointing towards it.
To do this, simply use raisebox:
\begin{equation}
x=
\cfrac{1}{a_1+
\cfrac{1}{a_2+
\cfrac{1}{\ddots \raisebox{-2mm}{$+\cfrac{1}{a_n}$}}}}
\end{equation}
- 3,075
-
2Just better put the measure in
exinstead ofmm, to make it more scale-invariant. – yo' Feb 04 '12 at 15:25 -
4Better to go
${}+\cfracon that last line, otherwise the+gets prefix spacing intended for+1rather than infix spacing intended for1 + 2– David Carlisle Feb 04 '12 at 16:05
msgmodule for complaining about input – Joseph Wright Feb 04 '12 at 17:02