\documentclass{ltxdoc}
\def\version{Version 1.2.2}

\let\ifluatex\relax
\usepackage{ifluatex}
\usepackage[a4paper,left=2.25cm,right=2.25cm,top=2.5cm,bottom=2.5cm,nohead]{geometry}
\usepackage{longdivision}

\usepackage{tikz}
\usepackage[documentation]{tcolorbox}
\usepackage{etoolbox}
\usepackage{amssymb}
\usepackage[notmath]{sansmathfonts}

\usepackage{hyperref}
\usepackage{hyperxmp}
\hypersetup{%
        colorlinks=true,
        linkcolor=blue,
        filecolor=blue,
        urlcolor=thered,
        citecolor=blue,
        pdfborder=0 0 0,
}

\makeatletter          % !!!!
\input{pgfmanual.code} % This must be exectuted when catcode of @ is letter
\makeatother           % !!!!

\include{pgfmanual-en-macros} % This must be executed when catcode of @ is other
\makeatletter

\MakeShortVerb{\|}

%\let\pgfmanual@verb@collect@code\pgfmanual@verb@collect
\patchcmd\pgfmanual@verb@collect{\pgfmanualprettyprintpgfkeys}{\pgfmanualprettyprintcode}{}{\error}
%\let\pgfmanual@verb@code\pgfmanual@verb


\patchcmd\extractkey{\hfill(\extrakeytext no value)}{}{}{\error}
\patchcmd\extractkey{\def\mykey}{\gdef\mykey}{}{\error}
\patchcmd\extractkeyequal{\hfill(\extrakeytext no default)}{}{}{\error}
\patchcmd\extractkeyequal{\def\mykey}{\gdef\mykey}{}{\error}
\patchcmd\extractinitial{no default, }{}{}{\error}
\patchcmd\extractinitial{\def\mykey}{\gdef\mykey}{}{\error}
\patchcmd\extractdefault{\def\mykey}{\gdef\mykey}{}{\error}
\patchcmd\extractdefault{#2}{{\hskip2pt}#2}{}{\error}
\patchcmd\extractequalinitial{\def\mykey}{\gdef\mykey}{}{\error}
\let\extractkey@\extractkey
\apptocmd\extractkey@{\egroup}{}{\error}
\def\extractkey{\bgroup\@ifnextchar*{\def\decompose####1\nil{}\relax\extractkey@\@gobble}{\extractkey@}}

% Redefine decompose not to do all that fancy crap -- just print as is. Maybe we should get rid of surrounding spaces here and where we do the ref?
\def\decompose#1/\nil{%
    %\index{#1@\protect\texttt{#1} key}%
    %\index{\mypath#1@\protect\texttt{#1}}%
    %\pgfmanualpdflabel{#1}{}%
}

\hypersetup{
    pdftitle={The Long Division Package},
    pdfauthor={Hood Chatham},
    pdfsubject={A package for typesetting long division},
    pdfkeywords={long division,math,teaching},
    pdflicenseurl={http://www.latex-project.org/lppl/}
}

\def\today{\the\year/\the\month/\the\day}

\def\@maketitle{%
 \null\vskip 2em
  \begin{center}\let\footnote\thanks\sffamily
    {\huge \@title\par}\vskip 1.5em
    {\large \parbox{.33\textwidth}{\centering\@author}%
            \parbox{.33\textwidth}{\centering\@date}}%
  \vskip2.5em\rule{\textwidth}{.4pt}%
  \end{center}\par\vskip1.5em}
\def\abstractname{}
\def\mailtoHC{\href % some PDF viewers don't like spaces:
    {mailto:<hood@mit.edu>\%20Hood\%20Chatham?subject=[spectralsequences\%20package]}
    {\texttt{hood@mit.edu}}}
\makeatother

\tcbset{
    texexp/.style={
        skin = enhanced,
        colframe=red!50!yellow!50!black,
        colback=red!50!yellow!5!white,
        coltitle=red!50!yellow!3!white,
        segmentation style = solid,
        fonttitle=\small\sffamily\bfseries,
        fontupper=\small,
        fontlower=\small},
    texexp
}
\newtcblisting{texexp}[1]{texexp,#1}
\def\longdivname{\textsc{\textsf{\textmd{longdivision}}}}
\begin{document}
\title{\longdivname}
\author{Hood Chatham\\\mailtoHC}
\date{\version\\\today}
 \maketitle

The \longdivname\ package defines two main commands: |\longdivision| and |\intlongdivision|. The usage for both is |\longdivision[|\meta{options}|]|\marg{dividend}\marg{divisor}. The difference is that |\longdivision| divides until the remainders repeat or the quotient has too many digits to fit the page, whereas |\intlongdivision| does integer division and leaves the remainder. The command |\longdivisionkeys|\marg{options} is also defined to set default options. At most 20 division steps worth of work will be displayed and at most 60 digits worth of division output will be produced. Thanks to Mike Jenck, Ben McKay, Cameron McLeman, Phelype Oleinik, Maximilian Schmidt,	and Yu-Tsung Tai for bug reports and feature requests.

Here is an example usage:

\begin{tcblisting}{sidebyside}
\longdivision{100}{22}
\quad
\intlongdivision{100}{22}
\end{tcblisting}

These commands have several key-value options:

\begin{key}{max extra digits = \meta{nonnegative integer}}
This key determines the maximum amount of ``extra'' zeroes to add to the end of the dividend in the process of division -- if the quotient has more digits before it repeats, the division will just stop. This is only an option for |\longdivision|, the command |\intlongdivision|\marg{dividend}\marg{divisor} is equivalent to |\longdivision[max extra digits=0]|\marg{dividend}\marg{divisor}. For brevity, this option has the short form where just the value is provided: |\longdivision[2]|\marg{dividend}\marg{divisor} is the same as |\longdivision[max extra digits=2]|\marg{dividend}\marg{divisor}.

\begin{tcblisting}{}
\longdivision[max extra digits = 1]{14.1}{7} \quad
\longdivision[2]{14.1}{7}
\end{tcblisting}
\end{key}


\begin{key}{stage = \meta{nonnegative integer}}
This controls how many steps worth of division to do. Thanks to Cam McLeman for suggesting this feature.
\begin{tcblisting}{}
\longdivision[stage=0]{5.3}{37} \quad
\longdivision[stage=1]{5.3}{37} \quad
\longdivision[stage=2]{5.3}{37} \quad
\longdivision[stage=3]{5.3}{37} \quad
\longdivision[stage=4]{5.3}{37}
\end{tcblisting}
\end{key}

\begin{key}{style = \meta{style} (initially standard)}
Control the style for typesetting the result of long division. The options are |default|, |standard|, |tikz|, or |german|. The option |default| is the same as |tikz| if \tikzname\ is loaded and otherwise is the same as |standard|. You probably should load \tikzname\ because the \tikzname\ version looks significantly better. If you use this option, you'll probably want to set the style once and for all in your preamble with |\longdivisionkeys{style=|\meta{style}|}|.
\begin{tcblisting}{}
\intlongdivision[style = tikz    ]{100.0}{13} \quad
\intlongdivision[style = standard]{100.0}{13} \quad
\intlongdivision[style = german  ]{100.0}{13}
\end{tcblisting}
You can define your own style with |\longdivisiondefinestyle|\marg{style name}\marg{code}.
In the |\marg{code}| you can use the commands |\longdivdivisor| which contains the divisor, |\longdivdividend| which contains the dividend,
|\longdivquotient| which contains the quotient, |\longdivwork| which contains the division work
and |\longdivremainder| which contains the remainder.
For instance, a simplified version of the |german| style is:
\begin{tcblisting}{}
\longdivisiondefinestyle{my style}{%
     \begin{tabular}{@{}l@{}}
    \longdivdividend  : \, \longdivdivisor \,  = \longdivquotient \\
    \longdivwork
    \end{tabular}
}
\longdivision[style = my style]{2}{3}
\end{tcblisting}
Send me an email if you cannot figure out how to make a style to your liking.
\end{key}

\begin{key}{repeating decimal style = \meta{style} (initially overline)}
Control the way that repeating decimals are typeset. The options are |overline|, |dots|, |dots all|, |parentheses|, or |none|. The default is |overline|. The |parentheses| style creates ugly spacing problems and the |dots| style is insufficiently visible, so the |overline| style is the best. If you use this option, you'll probably want to set the style once and for all in your preamble with |\longdivisionkeys{recurring decimal style=|\meta{style}|}|. Like the |style| key, this is designed to be extensible. However, the process of creating new |repeating decimal style|s is a bit involved. Send me an email if you want a new |repeating decimal style|.
\begin{tcblisting}{}
\longdivision[repeating decimal style = overline   ]{5.3}{37} \quad
\longdivision[repeating decimal style = dots       ]{5.3}{37} \quad
\longdivision[repeating decimal style = dots all   ]{5.3}{37} \quad
\longdivision[repeating decimal style = parentheses]{5.3}{37} \quad
\longdivision[repeating decimal style = none       ]{5.3}{37}
\end{tcblisting}
\end{key}


\begin{key}{decimal separator = \meta{separator character} (initially .)}
Control the character used to indicated the decimal point. Most people want this to be a period or a comma. The default is a period. Note that this changes the decimal separator BOTH in the input and in the output. If you set the decimal separator to a comma and then use a period in the input, it will throw an error (though this could be inconvenient for people -- if this behavior causes you trouble, email me and I can fix it).
If you want to use the comma decimal separator, I recommend saying |\longdivisionkeys{decimal separator = {,}}| in your preamble.
\begin{tcblisting}{}
\longdivision[decimal separator = {.}]{2.1}{3} \quad
\longdivision[decimal separator = {,}]{2,1}{3}
\end{tcblisting}
\end{key}

\begin{key}{digit separator = \meta{separator character} (initially none)}
Control the character used to separate groups of digits in the output.
By default digit groups have length 3, but that can be configured with the |digit group length| key.
%The digit separator will also be deleted from input strings.
If value is empty, then no separator is used.
Most people want this to be a period or a comma.
Note that this changes the decimal separator BOTH in the input and in the output. If you set the decimal separator to a comma and then use a period in the input, it will throw an error.
\begin{tcblisting}{}
\longdivisionkeys{digit group length = 2}
\longdivision[digit separator = {,}]{5}{7} \quad
\longdivision[digit separator = {.}, decimal separator = {,}]{5}{7}
\longdivision[digit separator = { }]{5}{7}
\longdivision[digit separator = {_}]{5}{7}
\end{tcblisting}
\end{key}

\begin{key}{digit group length = \meta{integer} (initially 3)}
Specify how often to include a digit separator. Does nothing without the |digit separator| key.
\begin{tcblisting}{}
\longdivision[digit group length = 2, digit separator = {,}]{5}{7} \quad
\longdivision[digit group length = 3, digit separator = { }]{5}{7} \quad
\longdivision[digit group length = 4, digit separator = {_}]{5}{7}
\end{tcblisting}
\end{key}

\begin{key}{separators in work = \meta{bool} (initially true)}
Specifies whether to include the decimal and digit separators in division work. When this is false, |\longdivision| will leave a space instead so that the digits are aligned correctly. \begin{tcblisting}{}
\longdivision[separators in work = true ]{14.1}{3} \quad
\longdivision[separators in work = false]{14.1}{3}
\end{tcblisting}
\end{key}

\begin{key}{german division sign = \meta{division sign} (initially :)}
\begin{tcblisting}{}
\longdivisionkeys{style = german}
\longdivision[german division sign = $\,\div\,$ ]{14.1}{3} \quad
\longdivision[german division sign = :          ]{14.1}{3}
\end{tcblisting}
\end{key}

\end{document}
