# How to format K notation for continued fractions

Over here is a recent paper on continued fractions, and I was wondering how I could format Gauss' K notation in this fashion. Here is a picture to demonstrate what I mean:

I am unsure how to format the alligned position of the + signs and ellipsis without aligning them with the vinculums of the fractions a(k)/b(k).

To format the size, font, indices, etc of the K notation, I tried doing: \operatornamewithlimits{\Large{\Bigg\mathcal{K}}}}_{m=1}^\infty
or
\operatorname*{\Large{\Bigg\mathcal{K}}}}\limits_{m=1}^\infty
and experimented with \large, \big, \bigg, with or without.

It seems that the size is right, but the indices are... way off. Can somebody help me, please? I have searched for some related posts (e.g. here), but amidst my search, I could not find the appropriate format I am looking for, as depicted above.

My thoughts: I think I need to install a package (e.g. amsmath) that can enhance typesetting and other facilities. I am writing a paper on Overleaf - does Overleaf come wit this package?

I am not new to TeX, but I believe this is either my first or second post. If I am doing something wrong, or failing to follow the guidelines, please let me know asap, and I will try to amend my question/post accordingly.

• Don't you need the amsmath package to use \operatornamewithlimits or \operatorname regardless? – bclzyjhr Apr 26 '20 at 9:01
• You can download the source at arxiv.org/format/1909.13597 and will find that the author uses gist.github.com/moewew/0141c642d3b2bf95dd8dcba1b537c6ee. I'm not sure if that's the "best solution", but it may be a start (I would certainly use \newcommand instead of \def). (To answer your question about Overleaf: Overleaf has all packages installed that come with a normal TeX live installation. amsmath is definitely one of those. You can just say \usepackage{amsmath} in the preamble and are good to go.) – moewe Apr 26 '20 at 9:01
• Very related (with a definition of \contFracOpe that looks familiar) tex.stackexchange.com/q/73195/35864. Also interesting: tex.stackexchange.com/q/23432/35864 – moewe Apr 26 '20 at 9:04
• For one the \mathrm in the code of \contFracOpe seems unnecessary. – moewe Apr 26 '20 at 9:08
• @Mr Pie, I have a feeling I'm missing something here because the answer you linked to seems fairly complex, but perhaps you could write \DeclareMathOperator*{\Kay}{\vcenter{\hbox{\huge$$\mathcal{K}$$}}} and \newcommand{\bottom}[1]{\begin{array}{c}{}\\#1\end{array}} in your preamble, and then in your document write $\Kay_{m=1}^{\infty} \bigg(\frac{a_m}{b_m}\bigg) :=\frac{a_1}{b_1}\bottom{+} \frac{a_2}{b_2} \bottom{+} \frac{a_3}{b_3} \bottom{+}\bottom{\cdots}$. – bclzyjhr Apr 26 '20 at 9:28

You can download the source of the arXiv paper at https://arxiv.org/format/1909.13597 (choose Download source to download the .tex file).

The paper uses

\def\contFracOpe{%
\operatornamewithlimits{%
\mathchoice{% * Display style
\vcenter{\hbox{\huge $\mathcal{K}$}}%
}{%           * Text style
\vcenter{\hbox{\Large $\mathcal{K}$}}%
}{%           * Script style
\mathrm{\mathcal{K}}%
}{%           * Script script style
\mathrm{\mathcal{K}}%
}
}
}


That definition seems to come from projetmbc's answer to How to typeset a continued fraction in the following format? which in term refers to user2478's answer to How to create my own math operator with limits?.

I usually prefer \newcommand over \def for commands in the preamble and the \mathrm's are unnecessary, so I would probably make that definition read

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}

\newcommand\ContFracOp{%
\operatornamewithlimits{%
\mathchoice
{\vcenter{\hbox{\huge $\mathcal{K}$}}}
{\vcenter{\hbox{\Large $\mathcal{K}$}}}
{\mathcal{K}}
{\mathcal{K}}}}

\begin{document}
$\ContFracOp\dots\ContFracOp_{k=1}^m x_k e^{\ContFracOp_{k=1}^m x_k}$

$\ContFracOp\dots\ContFracOp_{k=1}^m x_k e^{\ContFracOp_{k=1}^m x_k}$
\end{document}


An alternative would be to base \ContFracOp on egreg's answer that makes use of graphicx's \resizebox to scale the symbol to the same size as \sum.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\makeatletter
\DeclareRobustCommand\bigop[2][1]{%
\mathop{\vphantom{\sum}\mathpalette\bigop@{{#1}{#2}}}\slimits@
}
\newcommand{\bigop@}[2]{\bigop@@#1#2}
\newcommand{\bigop@@}[3]{%
\vcenter{%
\sbox\z@{$#1\sum$}%
\hbox{\resizebox{\ifx#1\displaystyle#2\fi\dimexpr\ht\z@+\dp\z@}{!}{$\m@th#3$}}%
}%
}
\makeatother

\newcommand{\ContFracOp}{\DOTSB\bigop[.96]{\mathcal{K}}}

\begin{document}
$\ContFracOp\dots\ContFracOp_{k=1}^m x_k e^{\ContFracOp_{k=1}^m x_k}$

$\ContFracOp\dots\ContFracOp_{k=1}^m x_k e^{\ContFracOp_{k=1}^m x_k}$
\end{document}


I found the magic number .96 in the optional argument to \bigop in the definition of \ContFracOp by trial and error. It helps manually correct the scaling of the symbol to match the height of \sum as closely as possible.

• Wasn't sure which to answer to accept, thus I went for the most-voted. Congratulations! $\Large\color{green}{\checkmark}$ :) – Mr Pie May 8 '20 at 4:23

A simplification of moewe's answer. As a bonus, also the alternative notation for continued fractions.

\documentclass{article}
\usepackage{amsmath,graphicx}

\makeatletter
\DeclareRobustCommand{\gaussk}{\DOTSB\gaussk@\slimits@}
\newcommand{\gaussk@}{\mathop{\vphantom{\sum}\mathpalette\bigcal@{K}}}

\newcommand{\bigcal@}[2]{%
\vcenter{\m@th
\sbox\z@{$#1\sum$}%
\dimen@=\dimexpr\ht\z@+\dp\z@
\hbox{\resizebox{!}{0.8\dimen@}{$\mathcal{K}$}}%
}%
}
\newcommand{\cfracplus}{\mathbin{\cfracplus@}}
\newcommand{\cfracplus@}{%
\sbox\z@{$\dfrac{1}{1}$}%
\sbox\tw@{$+$}%
\raisebox{\dimexpr\dp\tw@-\dp\z@\relax}{$+$}%
}
\newcommand{\cfracdots}{\mathord{\cfracdots@}}
\newcommand{\cfracdots@}{%
\sbox\z@{$\dfrac{1}{1}$}%
\sbox\tw@{$+$}%
\raisebox{\dimexpr\dp\tw@-\dp\z@\relax}{$\cdots$}%
}
\makeatother

\begin{document}

$e^n=\sum_{k=0}^{n-1}\frac{n^k}{k!}+\frac{n^{n-1}}{(n-1)!}\biggl( 1+n+\gaussk_{m=1}^{\infty}\Bigl(\frac{-n(m+n-1)}{m+2n-1}\Bigr)\biggr)$

$\gaussk_{m=1}^{\infty}\Bigl(\frac{a_m}{b_m}\Bigr)= \frac{a_1}{b_1}\cfracplus \frac{a_2}{b_2}\cfracplus \frac{a_3}{b_3}\cfracplus\cfracdots$

$\sum_{n=1}^{\infty}\gaussk_{n=1}^\infty \quad \textstyle \sum_{n=1}^{\infty}\gaussk_{n=1}^\infty \quad \scriptstyle \sum_{n=1}^{\infty}\gaussk_{n=1}^\infty$

\end{document}


An elementary solution, not as general, based on \genfrac and package scalerel:

\documentclass{article}
\usepackage{scalerel}
\usepackage{mathtools, amssymb}
$\bigKont_{m = 1}^{\infty}\Bigl(\frac{a_m}{b_m}\Bigr)\coloneqq \frac{a_1}{b_1}\cadd \frac{a_2}{b_2}\cadd \frac{a_3}{b_3}\cadd\Cdots$%