How to type a formula as below?
The following solution creates a macro called \bp
-- short for "bottom-aligned plus symbol", I suppose -- which, in turn, is based on the \genfrac
macro of the amsmath
package.
\documentclass{article} % or some other suitable document class
\usepackage{amsmath} % for '\genfrac' macro
\newcommand{\temp}[1]{\genfrac{}{}{0pt}{}{}{#1}}
\newcommand\bp{\mathbin{\temp{+}}} % or: \newcommand\bp{\temp{+}}
\begin{document}
\[
\frac{426}{359} = 1+\frac15\bp\frac12\bp\frac11\bp\frac13\bp\frac11\bp\frac14 \,,
\]
\end{document}
You can do it with a simpler user level syntax.
The command \contfrac
has
- an optional argument to print the value followed by =;
- a mandatory argument for the integer part; if blank nothing is printed;
- a mandatory argument for the sequence of integers in the continued fraction;
- an optional argument to print the value preceded by =.
Of course one has to choose between the leading and the trailing optional argument.
This is to be used in displays only, of course.
\documentclass{article}
\usepackage{amsmath,xparse}
\NewDocumentCommand{\contfrac}{ommo}{%
\sbox0{$\dfrac{1}{1}$}%
\raisebox{-\dimexpr\dp0}{%
\raisebox{\dimexpr\dp0}{%
$\displaystyle\IfValueT{#1}{#1=}\NotBlankT{#2}{#2+{}}$%
}%
\makecontfrac{#3}%
\IfValueT{#4}{%
\raisebox{\dimexpr\dp0}{$\displaystyle{}=#4$}%
}%
}%
}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\NotBlankT}{mm}
{
\tl_if_blank:nF { #1 } { #2 }
}
\NewDocumentCommand{\makecontfrac}{m}
{
\seq_set_from_clist:Nn \l_tmpa_seq { #1 }
\seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq { \__coeus_rfrac:n { ##1 } }
$\displaystyle\seq_use:Nn \l_tmpb_seq { + }$
}
\cs_new_protected:Nn \__coeus_rfrac:n
{
\raisebox{\depth}{$\dfrac{1}{#1}$}
}
\ExplSyntaxOff
\begin{document}
\begin{gather}
\contfrac{}{5,2,1,3,1,4}
\\[2ex]
\contfrac{1}{5,2,1,3,1,4}
\\[2ex]
\contfrac[\frac{426}{359}]{1}{5,2,1,3,1,4}
\\[2ex]
\contfrac{1}{5,2,1,3,1,4}[\frac{426}{359}]
\end{gather}
\end{document}
The idea is to print the result and the integer part raised by the depth of a standard fractions; then all fractions are raised by the same amount, so the + signs are typeset at their regular height.
Finally we lower the whole thing to cover our tracks.