%
% 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}
