summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/polynom/polydemo.tex
blob: 972fc768c766dcbca8ba07ad775806031d05055e (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
%
% This file is copyright 2004 Carsten Heinz.
%
% This file may be distributed and/or modified under the conditions
% of the LaTeX Project Public License, either version 1.3 of this
% license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
\documentclass[12pt]{article}
\pagestyle{empty}

\usepackage{geometry,hyperref,color,polynom}
\geometry{screen}
\hypersetup{pdfpagemode=FullScreen}

%%%%%%%%%%%%%
%
% \tokentotext<csname>{<tokens>}
% converts token sequence into a \texttt-printable form.
%
%%%%%%%%%%%%%
\makeatletter % We'll use three internal LaTeX definitions
\newcommand\tokentotext[2]{%
    \def#1{#2}%
    \edef#1{\expandafter\strip@prefix\meaning#1}%
    \edef#1{\expandafter\zap@space#1 \@empty}}
\makeatother


\newcounter{currentstage}
%%%%%%%%%%%%%
%
% \dopolylongdiv{<page title>}{<loop min>}{<loop max>}{<key=value list for \polyset>}
%
%%%%%%%%%%%%%
\newcommand\dopolylongdiv[4]{%
  \begingroup
    \tokentotext\keyvaluetext{#4}%
    \polyset{#4}%
    \setcounter{currentstage}{#2}\addtocounter{currentstage}{-1}%
    %
    \loop \ifnum \value{currentstage}<#3\relax
        \addtocounter{currentstage}{1}%
        \newpage
        \section*{\strut#1}\section*{\strut\texttt{\keyvaluetext}}%
        \[\polylongdiv[stage=\value{currentstage}]{x^3+x^2-1}{x+2}\]
    \repeat
  \endgroup}
%%%%%%%%%%%%%
%
% \dopolyhornerscheme{<page title>}{<loop min>}{<loop max>}{<key=value list for \polyset>}
%
%%%%%%%%%%%%%
\newcommand\dopolyhornerscheme[4]{% similar to \dopolylongdiv
  \begingroup
    \tokentotext\keyvaluetext{#4}%
    \polyset{#4}%
    \setcounter{currentstage}{#2}\addtocounter{currentstage}{-1}%
    %
    \loop \ifnum \value{currentstage}<#3\relax
        \addtocounter{currentstage}{1}%
        \newpage
        \section*{\strut#1}\section*{\strut\texttt{\keyvaluetext}}%
        \[\polyhornerscheme[x=-2,stage=\value{currentstage}]{x^3+x^2-1}\]
    \repeat
  \endgroup}

%%%%%%%%%%%%%
%
% T H E   D O C U M E N T
%
%%%%%%%%%%%%%
\begin{document}

\LARGE

\dopolylongdiv{Polynomial long division -- Stages 1 to 10}{1}{10}
              {}

\dopolylongdiv{Polynomial long division -- Stages 1 to 11}{1}{11}
              {style=B}

\dopolylongdiv{Polynomial long division -- Stages 1 to 11}{1}{11}
              {style=C}

\dopolylongdiv{Polynomial long division -- Stages 1 to 11}{1}{11}
              {style=D}

\dopolyhornerscheme{Horner's scheme -- Stages 1 to 8}{1}{8}
                   {}

\dopolyhornerscheme{Horner's scheme -- Stages 1 to 8}{1}{8}
                   {tutor=true,resultstyle=\color{blue}}

\dopolyhornerscheme{Horner's scheme -- Rule the result}{8}{8}
                   {resultbottomrule,resultleftrule,resultrightrule}

\dopolyhornerscheme{Horner's scheme -- Stages 1 to 8}{1}{8}
                   {tutor=true,tutorlimit=3}

\dopolyhornerscheme{Horner's scheme: Some more options}{8}{8}
                   {showbase=top,showbasesep=false}

\end{document}