summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/renditions/renditions.dtx
blob: e5ec36393a06f8be3786d052d4371a4cf0211389 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
%\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