%\iffalse
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Renditions.sty package,            2010-1-29         %%
%% Copyright (C) 1999-2002  D. P. Story                 %%
%%   dpstory@uakron.edu                                 %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% History: Noel Vaillant began developing a better renditions.sty
%%   based on my earlier published renditions.sty. Many thanks
%%   to him for starting me off.
%%---------------------------------------------------------
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
%<package>\ProvidesPackage{rendition}
%<package> [2010/01/29 v0.1 rendition: Package for creating multiple renditions from the same source (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage{amsmath}
\usepackage[colorlinks,hyperindex]{hyperref}
\usepackage{calc}
%\pdfstringdefDisableCommands{\let\\\textbackslash}
%\EnableCrossrefs \CodelineIndex
\begin{document}
\def\CMD#1{\textbackslash#1}
  \GetFileInfo{renditions.sty}
  \title{The \textsf{rendition} Package\texorpdfstring{\\[1ex]}{: }Creating multiple renditions (versions)\texorpdfstring{\\[1ex]}{}
  from the same source file}
  \author{D. P. Story\\
    Email: \texttt{dpstory@uakron.edu}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \let\Email\texttt
  \DocInput{renditions.dtx}
  \PrintIndex
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
% \StopEventually{}
%
% \DoNotIndex{\def,\edef,\gdef,\xdef,\global,\long,\let}
% \DoNotIndex{\expandafter,\string,\the,\ifx,\else,\fi}
% \DoNotIndex{\csname,\endcsname,\relax,\begingroup,\endgroup}
% \DoNotIndex{\DeclareTextCommand,\DeclareTextCompositeCommand}
% \DoNotIndex{\space,\@empty,\special}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% \section{The \textsf{renditions} Package}
% This is a short package sets up comment environments, called \emph{renditions}. These
% renditions can be included or excluded according to the value of the
% \texttt{rendition} option. The basic options of this package are \texttt{max} and \texttt{rendition}
%\begin{verbatim}
%   \usepackage[max=4,rendition=3]{renditions}
%\end{verbatim}
% In the above example, \texttt{max=4} declares that there are 4 renditions in the
% document, the option \texttt{rendition=3} causes the package to include
% \texttt{rendition3}, and to exclude all the others \texttt{rendition1}, \texttt{rendition2}, and \texttt{rendition4}.
%
%The \textsf{renditions} package is a stand-alone package, but it was designed for use with the \textsf{AeB Builder} utility.
%
%Below is an example of a document that uses the \textsf{renditions} package.
%
%\bigskip\noindent\begin{minipage}[t]{.4\linewidth-5pt}
%\begin{verbatim}
%\documentclass{article}
%\usepackage[%
%    max=4,
%    rendition=3
%]{renditions}
%\end{verbatim}
%\verb!%\rendition{2}!
%\begin{verbatim}
%\parindent0pt\parskip6pt
%
%\begin{document}
%This is a test file for
%renditions.
%
%\begin{rendition1}
%Rendition 1
%\end{rendition1}
%
%\begin{rendition2}
%Rendition 2
%\end{rendition2}
%
%\begin{rendition3}
%Rendition 3
%\end{rendition3}
%
%\begin{rendition4}
%Rendition 4
%\end{rendition4}
%
%\end{document}
%\end{verbatim}
%\end{minipage}\hfill
%\begin{minipage}[t]{.6\linewidth-5pt}\parskip\medskipamount
%There are two options for the \textsf{renditions} package: \texttt{max} and \texttt{rendition}. The value of \texttt{max} sets the maximum number of renditions in the document; the value of the \texttt{rendition} key determines which of the renditions is to be typeset. You can also select the rendition using the \cs{rendition} command, as illustrated to the left. (The \cs{rendition} command in the preamble would override the value of the \texttt{rendition} key.)
%
%The various renditions are defined with the \texttt{rendition<n>} environment.
%These environments are just comment environments created by the \textsf{comments} %package, and they are selectively included or excluded depending on the value of %the rendition defined by either the \texttt{rendition} key or the \cs{rendition} command.
%
%The \textsf{rendition} package does modular arithmetic in the case when $\text{rendition} > %\text{max}$. For example, if \texttt{max=4}, and \texttt{rendition=6}, then the rendition %displayed is \texttt{rendition=2}.
%
%There is a third way of setting the value of the rendition parameter, and that is %through the \texttt{rendition.cfg} file. If you create a file with the code
%\begin{verbatim}
%    \ExecuteOptionsX{rendition=3}
%\end{verbatim}
%Then \texttt{rendition=3} is used.
%\end{minipage}
%
%\paragraph*{Default values.}The default value of \texttt{max}, if it is not specified is %3, and the default value of \texttt{rendition} if it is not specified is 1.
%
% There should not be a \texttt{rendition<n>} environment with a number, \texttt{<n>}, greater than that specified by \texttt{max}; however,
% if the value of \texttt{rendition} is greater than \texttt{max}, modular arithmetic
% is performed, and the rendition numbered \texttt{rendition} Mod \texttt{max} is used.
%
%\paragraph*{History.} The core of this package was originally developed
% for my online testing system TAOAS (The {Acro\negthinspace\TeX} Online
% Assessment System). In that system, the \texttt{rendition.cfg} approach was used
% to select a rendition to be used.
%
%\section{The Main Code}
% We use xkeyval to create the two options \texttt{max} and \texttt{rendition}.
%    \begin{macrocode}
\RequirePackage{xkeyval}
%    \end{macrocode}
%    \begin{macro}{max}
% The maximum number of renditions present in this file. The value of max
% must be a positive integer, no checking takes place. The default number is
% 3.
%    \begin{macro}{rendition}
% The number of the rendition what you want to use for this run of the latex
% compiler. The default number is 1.
%    \begin{macrocode}
\DeclareOptionX{max}{\def\ren@numberOf{#1}}
\def\ren@numberOf{3}
\DeclareOptionX{rendition}{\def\thisrendition{#1}}
\def\thisrendition{1}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
% Input the configuration file, if it exists. This file normally contains
% the line of {\LaTeX} code \verb!\ExecuteOptions{rendition=<n>}!
%    \begin{macrocode}
\InputIfFileExists{rendition.cfg}{}{}
%    \end{macrocode}
% Process the options.
%    \begin{macrocode}
\ProcessOptionsX
%    \end{macrocode}
% The comment package is required.
%    \begin{macrocode}
\RequirePackage{comment}
%    \end{macrocode}
% Based on the value of \texttt{max}, we create the requested number
% of rendition environments: \texttt{rendition1}, \texttt{rendition2},\dots,
% \texttt{rendition<max>}.
%    \begin{macrocode}
\let\save@message\message\let\message\@gobble
\@tempcnta=0
\@whilenum\@tempcnta<\ren@numberOf\do{%
    \@tempcntb=\@tempcnta\advance\@tempcntb1
    \edef\temp@exp{\noexpand\excludecomment{rendition\the\@tempcntb}}%
    \temp@exp
    \expandafter\let\csname Afterver\the\@tempcntb Comment\endcsname\relax
    \advance\@tempcnta1
}\let\message\save@message
%    \end{macrocode}
% We include the selected version at the beginning of the document.
%    \begin{macrocode}
\AtBeginDocument{\includecomment{rendition\thisrendition}}
%    \end{macrocode}
%    \begin{macro}{\rendition}
% A convenience macro for setting the current renditions. This
% command defines the command \cs{thisrendition}, which expands
% to the selected rendition number. If the value of \cs{thisredition}
% is greater than \texttt{max} (\cs{ren@numberOf}), modular arithmetic
% is performed, and \cs{thisrendition} is redefined.
%    \begin{macrocode}
\def\rendition#1{\def\thisrendition{#1}%
    \ifnum\thisrendition>\ren@numberOf
        \@tempcnta=\thisrendition
        \@tempcntb=\@tempcnta
        \advance\@tempcnta-1 \divide\@tempcnta\ren@numberOf
             \multiply\@tempcnta\ren@numberOf
             \advance\@tempcntb-\@tempcnta
        \edef\thisrendition{\the\@tempcntb}%
        \typeout{Modular arithmetic applied: ren=\thisrendition}%
    \fi
}
\@onlypreamble{\rendition}
%    \end{macrocode}
% We execute \cs{rendition} for the selected rendition.
%    \begin{macrocode}
\expandafter\rendition\expandafter{\thisrendition}
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%  \Finale
\endinput