summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/longdivision/longdivision_manual.tex
blob: c4f23a9fbc9119e228420cf8347f707109ddfe41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
\documentclass{ltxdoc}
\def\version{Version 1.1.0}

\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, Cameron McLeman, and Yu-Tsung Tai for emailing me with 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 = 2]{10.0}{7} \quad
\longdivision[1]{10.0}{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]{1}{7} \quad
\longdivision[stage=1]{1}{7} \quad
\longdivision[stage=2]{1}{7} \quad
\longdivision[stage=3]{1}{7} \quad
\longdivision[stage=4]{1}{7} \quad
\longdivision[stage=5]{1}{7} \quad
\longdivision[stage=6]{1}{7}
\end{tcblisting}
\end{key}

\begin{key}{style = \meta{style}}
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 typesetting style by saying |\longdiv_define_style:nn|\marg{style name}\marg{code}. This can use the commands |\longdivdividend| which contains the dividend, |\longdivdivisor| which contains the divisor, |\longdivquotient| which contains the quotient, and |\longdivwork:| which contains the |division work|.  For instance, a simplified version of the |german| style is:
\begin{tcblisting}{}
\longdivdefinestyle{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}}
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}|}| |\longdivisionkeys{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}
\end{document}