Debian Codegraph @

texmf-dist/source/latex/rjlparshap/rjlpshap.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2004 by Robert J Lee <[email protected]>
4 % --------------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.2
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.2 or later is part of all distributions of LaTeX
14 % version 1999/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{rjlpshap.dtx}
21 %</driver>
22 %<package> \NeedsTeXFormat{LaTeX2e}[1999/12/01]
23 %<package> \ProvidesPackage{rjlpshap}
24 %<*package>
25 [2004/11/05 v1.0 .dtx rjlpshap file]
26 %</package>
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \EnableCrossrefs
31 \CodelineIndex
32 \RecordChanges
33 \usepackage{lipsum}
34 \begin{document}
35 \DocInput{rjlpshap.dtx}
36 \end{document}
37 %</driver>
38 % \fi
39 %
40 % \CheckSum{0}
41 %
42 % \CharacterTable
43 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
44 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
45 % Digits \0\1\2\3\4\5\6\7\8\9
46 % Exclamation \! Double quote \" Hash (number) \#
47 % Dollar \$ Percent \% Ampersand \&
48 % Acute accent \' Left paren \( Right paren \)
49 % Asterisk \* Plus \+ Comma \,
50 % Minus \- Point \. Solidus \/
51 % Colon \: Semicolon \; Less than \<
52 % Equals \= Greater than \> Question mark \?
53 % Commercial at \@ Left bracket \[ Backslash \\
54 % Right bracket \] Circumflex \^ Underscore \_
55 % Grave accent \` Left brace \{ Vertical bar \|
56 % Right brace \} Tilde \~}
57 %
58 %
59 % \changes{v1.0}{2004/11/05}{Initial version}
60 %
61 % \GetFileInfo{rjlpshap.dtx}
62 %
63 % \DoNotIndex{\newcommand,\newenvironment}
64 %
65 %
66 % \title{The \textsf{rjlpshap} class\thanks{This document
67 % corresponds to \textsf{rjlpshap}~\fileversion, dated \filedate.}}
68 % \author{Robert J Lee \\ \texttt{[email protected]}}
69 %
70 % \maketitle
71 %
72 % \section{Introduction}
73 %
74 % This package provides low-level helper macros and environments. It
75 % is intended for authors of \LaTeX\ packages, who wish to
76 % programmatically change the shape of paragraphs. It overcomes several
77 % difficulties with \TeX's \texttt{$\backslash$parshape} register:
78 %
79 % \begin{enumerate}
80 % \item It is not possible to re-use a length register when issuing a
81 % \texttt{$\backslash$parshape} command; this makes it difficult to
82 % calculate the shape of a paragraph in \LaTeX\ using some
83 % algorithms that re-use one or more variables (registers).
84 % \item The number of lines must be known \textit{before} the lengths
85 % of each line, which can lead to difficult calculations.
86 % \item The format of the \texttt{$\backslash$parshape} command is
87 % very strict and evaluated early on by \TeX, and so it doesn't
88 % easily allow for parameter-replacement, making it difficult to use
89 % any calculations at all.
90 % \end{enumerate}
91 %
92 % It differs from the \texttt{shapepar} package, in that it provides
93 % no actual calculations for paragraph shapes. Instead, it provides a
94 % framework by which paragraph shapes can be calculated in a single
95 % run of the document by the author (or package writer).
96 %
97 % The package provides both environments and commands by which the
98 % author can accumulate any number of lengths and then use them in a
99 % \texttt{$\backslash$parshape} command injected into the document,
100 % without the need to re-run \LaTeX.
101 %
102 % \pagebreak[4]
103 % \section{Usage}
104 %
105 % There are two modes of operation: environment mode and command
106 % mode. Environment mode has the advantage that it does not
107 % require the number of lengths to be known in advance, while command
108 % mode provides various options for passing pre-calculated lengths.
109 %
110 % \subsection{Environment Mode}
111 %
112 % Environment mode uses a single environment,
113 % \texttt{parshapecollect}, which starts and ends before the paragraph
114 % of text. The contents of the environment are a \LaTeX\ program,
115 % supplied by the user, that calculates the lengths of each line.
116 %
117 % \DescribeEnv{parshapecollect} The \texttt{parshapecollect}
118 % environment goes at the start of a paragraph, and the entire
119 % environment defines a single \texttt{$\backslash$parshape} command.
120 % Any even number of lengths are collected, and at the end of the
121 % environment, the \texttt{$\backslash$parshape} command is
122 % automatically generated and inserted into the document.
123 %
124 % \DescribeMacro{\parshapelenout} This macro takes one mandatory
125 % parameter, which is the next length in the
126 % \texttt{$\backslash$parshape} command. Note that the parameter is
127 % expanded: the value of the length at the time
128 % \texttt{$\backslash$parshapelenout} is called is the value which is
129 % used --- this means the same length command can be re-used
130 % repeatedly. The value may be a length register, and the same
131 % register may be re-used after changing its contents, for example:
132 %
133 % \begin{quote}
134 % \begin{verbatim}
135 % \newlength{\foo}
136 % \begin{parshapecollect}
137 % \setlength{\foo}{1in}\parshapelenout{\foo}
138 % \setlength{\foo}{3in}\parshapelenout{\foo}
139 % \setlength{\foo}{0.5in}\parshapelenout{\foo}
140 % \setlength{\foo}{3.5in}\parshapelenout{\foo}
141 % \setlength{\foo}{0in}\parshapelenout{\foo}
142 % \setlength{\foo}{4in}\parshapelenout{\foo}
143 % \end{parshapecollect}
144 % \lipsum[1]
145 % \end{verbatim}
146 % Produces:
147 %
148 % \parshape 3 1in 4in 0.5in 4.5in 0in 5in
149 % \lipsum[1]
150 % \end{quote}
151
152 %
153 % \DescribeMacro{\parshapearrlenout} This macro is the same as
154 % \texttt{$\backslash$parshapelenout}, but allows the programmer to
155 % pass the length as the value from an array (see the
156 % \texttt{arrayjob} package). This is intended for situations where
157 % pre-calculated lengths are to be used alongside calculations; to
158 % pass an array of lengths the various command modes may be
159 % easier. The parameters to the macro are the name of the array and
160 % the name of a counter containing the index.
161 %
162 % For example, the above paragraph could have been created
163 % using:
164 % \begin{quote}
165 % \begin{verbatim}
166 % \newarray{foo} \newcounter{ctr}
167 % \begin{parshapecollect}
168 % \foo(1)={1in}\setcounter{ctr}{1}\parshapearrlenout{foo}{ctr}
169 % \foo(2)={3in}\setcounter{ctr}{2}\parshapearrlenout{foo}{ctr}
170 % \foo(3)={0.5in}\setcounter{ctr}{3}\parshapearrlenout{foo}{ctr}
171 % \foo(1)={3.5in}\setcounter{ctr}{1}\parshapearrlenout{foo}{ctr}
172 % \foo(2)={0in}\setcounter{ctr}{2}\parshapearrlenout{foo}{ctr}
173 % \foo(2)={4in}\parshapearrlenout{foo}{ctr}
174 % \end{parshapecollect}
175 % \lipsum[1]
176 % \end{verbatim}
177 % \end{quote}
178 %
179 % \subsection{Command Mode}
180
181 % Command mode enables the author to use calculated shapes by
182 % outputting the $\backslash$parshape command as a single operation at
183 % the end of the calculation.
184
185 % \DescribeMacro{\parshapeary}
186 % This macro takes one parameter, being the name of an array. The
187 % contents of the array are simply expanded and passed directly to
188 % \texttt{$\backslash$parshape} --- the first parameter is the number
189 % of lines, then for each line the left margin and line width are
190 % supplied in subsequent elements.
191 %
192 % For example:
193 % \begin{quote}
194 % \begin{verbatim}
195 % \newcommand{\ltest}{50pt}
196 % \newlength{\test}\setlength{\test}{300pt}
197 % \newarray{sizes}\readarray{sizes}{2&0em&\the\test&\ltest&\test}
198 % \parshapeary{sizes}
199 % \lipsum[1]
200 % \end{verbatim}
201 % produces:
202 %
203 % \parshape 2 0em 300pt 50pt 300pt \lipsum[1]
204 % \end{quote}
205 %
206 %
207 % \DescribeMacro{\parshapearray} This macro takes two parameters. The
208 % first is also the name of an array. The only difference to
209 % \texttt{$\backslash$parshapeary} is that instead of passing the
210 % width of the line, the width of the right margin is passed
211 % instead. This means the macro needs to know the width of the line.
212 %
213 % The second parameter is the length of the line. This is usually
214 % $\backslash$columnwidth, passing any other value will effectively
215 % change the right margin. ($\backslash$columnwidth is often equal to
216 % $\backslash$textwidth, but in multi-column mode,
217 % $\backslash$columnwidth is more likely to be correct, unless you
218 % want to overstrike the text with text in another column --- so
219 % $\backslash$columnwidth is the recommended length to use).
220 %
221 % In a similar vein to the previous example:
222 % \begin{quote}
223 % \begin{verbatim}
224 %\newcommand{\ltest}{50pt}
225 %\newlength{\test}\setlength{\test}{75pt}
226 %\newlength{\cwidth}\setlength{\cwidth}{\columnwidth}
227 %\addtolength{\cwidth}{-50pt}
228 %
229 %\newarray{sizes}\readarray{sizes}{2&0em&\the\test&\ltest&\test}
230 %\parshapearray{sizes}{\cwidth}
231 %\lipsum[1]
232 %
233 % \end{verbatim}
234 % which produces:
235 %
236 % \parshape 2 0.0pt
237 %220.0pt
238 %50.0pt
239 %170.0pt
240 % \lipsum[1]
241 % \end{quote}
242 %
243 % \DescribeMacro{\Parshapearray}
244 % This macro also takes two parameters, and is used to combine
245 % multiple shapes, where the width of the paragraph is not consistent
246 % throughout the paragraph.
247 %
248 % The first parameter is the name of an array, in the same format as
249 % the first parameter to \texttt{$\backslash$parshapeary}.
250 %
251 % The second parameter is the name of a second array. The first
252 % element is the number of lines in this second array, and subsequent
253 % elements are the widths of lines (excluding margins) in that array
254 % --- starting from the first line. As usual, if an insufficient
255 % number of lines are passed, the last line will be re-used.
256 %
257 % The actual width of a line will be the total width excluding margins
258 % (as per the second parameter), minus the left margin (taken from the
259 % first parameter, even indexes), minus the right margin (as per the
260 % first parameter, odd indexes).
261 %
262 % In this way, it is possible to set a shaped paragraph that allows
263 % for non-straight margins or non-rectangular paper --- for example, to
264 % typeset a list item in such a way as to allow for a cut-out on the
265 % page.
266 %
267 % For a larger example, consider that the paper has a sloped shape
268 % that extends 1em wider for every line for the first 15 lines
269 % only. The author wishes to set a text in an quadrilateral, with
270 % margins offset $\frac{1}{8}\verb!"!$ to the right for each line, but
271 % extending equally to follow the width of the paper.
272
273 % \begin{quote}
274 % \begin{verbatim}
275 % \newarray{quad}
276 % \readarray{quad}{17 & 0.000in & 2.000in & 0.125in & 1.875in &
277 % 0.250in & 1.750in & 0.375in & 1.625in & 0.500in & 1.500in &
278 % 0.625in & 1.375in & 0.750in & 1.250in & 0.875in & 1.125in &
279 % 1.000in & 1.000in & 1.125in & 0.875in & 1.250in & 0.750in &
280 % 1.375in & 0.675in & 1.500in & 0.500in & 1.625in & 0.375in &
281 % 1.750in & 0.250in & 1.875in & 0.125in & 2.000in & 0.000in}
282 % \newarray{papershape}
283 % \readarray{papershape}{15& 25em & 26em & 27em & 28em & 29em & 30em & 31em
284 % & 32em & 33em & 34em & 35em & 36em & 37em & 38em & 39em}
285 % \Parshapearray{quad}{papershape} \lipsum[1]
286 % \end{verbatim}
287 % Produces:
288 %
289 % \parshape 17
290 % 0.0pt
291 % 105.46039pt
292 % 9.03374pt
293 % 115.46042pt
294 % 18.06749pt
295 % 125.46043pt
296 % 27.10124pt
297 % 135.46045pt
298 % 36.135pt
299 % 145.46045pt
300 % 45.16875pt
301 % 155.46046pt
302 % 54.2025pt
303 % 165.46048pt
304 % 63.23624pt
305 % 175.46051pt
306 % 72.26999pt
307 % 185.46053pt
308 % 81.30374pt
309 % 195.46054pt
310 % 90.3375pt
311 % 205.46054pt
312 % 99.37125pt
313 % 211.84685pt
314 % 108.405pt
315 % 225.46057pt
316 % 117.43874pt
317 % 235.4606pt
318 % 126.47249pt
319 % 245.46062pt
320 % 135.50624pt
321 % 235.4606pt
322 % 144.54pt
323 % 235.46059pt \lipsum[1]
324 % \end{quote}
325 %
326
327
328 % \section{Prerequisites}
329
330 % This package requires the \texttt{arrayjob} package from
331 % CTAN\footnote{http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=arrayjob}. Arrays
332 % are used as a convenient mechanism to pass values to functions,
333 % although they may not be used in environment mode.
334
335 % \section{Limitations and Possible Improvements}
336
337 % \begin{itemize}
338 % \item Usage of this package can be slow, because two temporary files
339 % are used for each $\backslash$parshape. Theoretically, only one
340 % should be needed and so it should be possible to improve this.
341 % \item There is no support for combining arrays, other than to change
342 % the paper size itself. Extra commands could be provided to
343 % calculate the intersection of two cutouts, or to add margins
344 % together.
345 % \item In a future version, it may be possible to avoid temporary
346 % files completely by using token registers, or
347 % $\backslash$aftergroup, with some form of string processing.
348 % \end{itemize}
349
350 % \section{Package Name}
351
352 % The somewhat obscure name ``rjlpshap'' was chosen following the
353 % guidelines given in \textit{\LaTeXe\ for Class and Package
354 % Writers}\footnote{\texttt{http://www.tex.ac.uk/tex-archive/macros/latex/doc/clsguide.pdf}}~(section~2.7.3,
355 % ``Make it Portable''). The common prefix used by these packages
356 % is~''rjl--'', which was chosen as the author's initials as he is
357 % not writing these packages as part of any organisation.
358
359 % The postfix of ``--pshap'' was chosen as a contraction of
360 % ``parshape'', the \TeX\ command to which this package is a front
361 % end. The name was contracted due to the 5-character length
362 % restriction. It was also considered that that the obvious package
363 % name of ``parshape'' would be best avoided to avoid confusion with
364 % the existing shapepar\footnote{\texttt{http://www.ctan.org/tex-archive/macros/latex/contrib/shapepar/}} package, and also because parshape is a
365 % standard \TeX\ command --- the only requirement that exists is to
366 % avoid the name of a standard package, but avoiding the name of a
367 % standard macro also seems like a good idea as this leaves the name
368 % free for use as a standard package name in the future.
369
370 % \section{Other References}
371
372 % The following references were essential in producing this package:
373
374 % \begin{itemize}
375 % \item The \TeX Book\footnote{ISBN:~978-0201134483}
376 % \item \TeX Live package
377 % contributions\footnote{http://tug.org/texlive/pkgcontrib.html}
378 % \item TDS Guidelines\footnote{http://dante.ctan.org/TDS-guidelines.html}
379 % \end{itemize}
380
381 % \StopEventually{\PrintChanges\PrintIndex}
382 %
383 % \section{Implementation}
384 %
385 % Arrayjob: we need to pass arrays of lengths and length-commands,
386 % so build on the established array handling functionality.
387 % \begin{macrocode}
388 \RequirePackage{arrayjob}
389 % \end{macrocode}
390
391 % Forloop: we need to iterate over the arrays that are passed in
392 % \begin{macrocode}
393 \RequirePackage{forloop}
394 % \end{macrocode}
395 % Internal commands use @ as a letter, not a special character, so
396 % switch catcodes
397 % \begin{macrocode}
398 \makeatletter
399 % \end{macrocode}
400
401
402 % \subsection{Environment mode}
403
404 % \begin{environment}{parshapecollect}
405 % Environment to handle writing the file, cleaning up etc.
406 %
407 % Note the importance of the % at the end of each line here: we're
408 % in horizontal mode so any space characters get expanded and added
409 % into the start of the paragraph. Any spaces here are output before
410 % $\backslash$parshape itself, and so will be visible in the output
411 % page. The $\backslash$ignorespaces is a last line of defence
412 % against any extra spaces inadvertently introduced by the user.
413 %
414 % \begin{macrocode}
415 \newenvironment{parshapecollect}{%
416 \immediate\openout\rjlpshap@writer=\jobname.parshape%
417 \setcounter{rjlpshap@linecount}{0}%
418 \setboolean{rjlpshap@isodd}{false}%
419 \ignorespaces
420 }{%
421 \immediate\closeout\rjlpshap@writer%
422 % \end{macrocode}
423 % Because the environment forms a group, we need to use aftergroup to
424 % delay the $\backslash$parshape command. Otherwise the group will end first and
425 % $\backslash$parshape will be discarded.
426 % \begin{macrocode}
427 \rjlpshap@doparshape%
428 \aftergroup\input\aftergroup{\aftergroup\jobname\aftergroup%
429 .\aftergroup%
430 p\aftergroup%
431 a\aftergroup%
432 r\aftergroup%
433 s\aftergroup%
434 h\aftergroup%
435 a\aftergroup%
436 p\aftergroup%
437 e\aftergroup%
438 t\aftergroup%
439 m\aftergroup%
440 p\aftergroup}\ignorespaces
441 }
442 % \end{macrocode}
443 % \end{environment}
444
445 % \begin{macro}{\rjlpshap@doparshape}
446 % Internal method to handle the final processing of the built
447 % up $\backslash$parshape command. The lengths have been written to
448 % the first temporary file, so write the entire $\backslash$parshape
449 % command to the second one, ready to be input.
450 % \begin{macrocode}
451 \newcommand{\rjlpshap@doparshape}{%
452 \immediate\openout\rjlpshap@finalwriter=\jobname.parshapetmp%
453 \immediate\write\rjlpshap@finalwriter{\noexpand\parshape \arabic{rjlpshap@linecount}}%
454 \openin\rjlpshap@reader=\jobname.parshape%
455 \setboolean{rjlpshap@loop}{true}%
456 \whiledo{\boolean{rjlpshap@loop}}{%
457 \read\rjlpshap@reader to\rjlpshap@temp%
458 % NB: \ifeof matches \loop...\repeat
459 \ifeof\rjlpshap@reader%
460 \setboolean{rjlpshap@loop}{false}%
461 \else
462 \immediate\write\rjlpshap@finalwriter{\rjlpshap@temp }%
463 \fi
464 }%
465 \immediate\closeout\rjlpshap@finalwriter%
466 \immediate\closein\rjlpshap@reader%
467 \let\rjlpshap@temp=\relax%
468 }
469 % \end{macrocode}
470 % \end{macro}
471
472 % \begin{macro}{\parshapelenout}
473 % Used inside a parshapecollect environment, writes length \#1 to
474 % the $\backslash$parshape command file. (If used anywhere else,
475 % it'll just write to the console since the file will not be open).
476 % \begin{macrocode}
477 \newcommand{\parshapelenout}[1]{%
478 \setlength{\rjlpshap@tempwidth}{#1}%
479 \immediate\write\rjlpshap@writer{\the\rjlpshap@tempwidth}%
480 \ifthenelse{\boolean{rjlpshap@isodd}}{%
481 \setboolean{rjlpshap@isodd}{false}%
482 }{%
483 \stepcounter{rjlpshap@linecount}%
484 \setboolean{rjlpshap@isodd}{true}%
485 }%
486 \ignorespaces
487 }
488 % \end{macrocode}
489 % \end{macro}
490
491 % \begin{macro}{\parshapearrlenout}
492 % Used inside a parshapecollect environment, writes a length to the
493 % $\backslash$parshape command file. As $\backslash$parshapelenout,
494 % except that the element is passed as the member of an array.
495 %
496 % Length is taken from array with name \#1, element at index \#2
497 % \begin{macrocode}
498 \newcommand{\parshapearrlenout}[2]{%
499 \testarray{#1}(\arabic{#2})%
500 \parshapelenout{\temp@macro}%
501 \ignorespaces
502 }
503 % \end{macrocode}
504 % \end{macro}
505
506 % \subsection{Command Mode}
507
508 % \begin{macro}{\parshapeary}
509 % As $\backslash$parshape, but takes one argument being an array
510 % name defined in arrayjob form. The array contains the arguments,
511 % starting with the count at index 1, then one length per array
512 % element.
513 % \begin{macrocode}
514 \newcommand{\parshapeary}[1]{%
515 \testarray{#1}(1)%
516 \edef\rjlpshap@max{\temp@macro}%
517 \begin{parshapecollect}%
518 \forloop{rjlpshap@ctr}{1}{\not \value{rjlpshap@ctr} > \rjlpshap@max }{%
519 \setcounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
520 \addtocounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
521 \parshapearrlenout{#1}{rjlpshap@ctr2}%
522 \stepcounter{rjlpshap@ctr2}%
523 \parshapearrlenout{#1}{rjlpshap@ctr2}%
524 }%
525 \end{parshapecollect}%
526 \typeout{parshapeary end}%
527 \ignorespaces
528 }
529 % \end{macrocode}
530 % \end{macro}
531
532
533 % \begin{macro}{\parshapearray}
534 % As $\backslash$parshapeary, but the second parameter is the name
535 % of a single-parameter macro taking a number and returning the
536 % width of the line on that line
537 % \begin{macrocode}
538 \newcommand{\parshapearray}[2]{%
539 \begin{parshapecollect}%
540 \testarray{#1}(1)%
541 \edef\rjlpshap@max{\temp@macro}%
542 \forloop{rjlpshap@ctr}{1}{\not \value{rjlpshap@ctr} > \rjlpshap@max }{%
543 \setcounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
544 \addtocounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
545 \edef\rjlpshap@pos{\arabic{rjlpshap@ctr2}}%
546 \testarray{#1}(\rjlpshap@pos)%
547 \setlength{\rjlpshap@tempwidth}{\temp@macro}%
548 \setlength{\rjlpshap@templinewidth}{#2}%
549 \addtolength{\rjlpshap@templinewidth}{-1\rjlpshap@tempwidth}%
550 \parshapelenout{\rjlpshap@tempwidth}%
551 \stepcounter{rjlpshap@ctr2}%
552 \edef\rjlpshap@pos{\arabic{rjlpshap@ctr2}}%
553 \testarray{#1}(\rjlpshap@pos)%
554 \setlength{\rjlpshap@tempwidth}{\temp@macro}%
555 \addtolength{\rjlpshap@templinewidth}{-1\rjlpshap@tempwidth}%
556 \parshapelenout{\rjlpshap@templinewidth}%
557 }%
558 \end{parshapecollect}%
559 }
560 % \end{macrocode}
561 % \end{macro}
562
563
564 % \begin{macro}{\Parshapearray}
565 % First parameter is as $\backslash$parshapea\{r,rra\}y, but each pair
566 % is left and right margin rather than left margin and text width,
567 % while the second tracks the page width.
568 %
569 % \textit{i.e.}
570 %
571 % The first parameter (an array) is the shape of the paragraph
572 % relative to the page.
573 % \begin{itemize}
574 % \item first element is the number of pairs of lengths in the array
575 % \item subsequent arguments are pairs of lengths, left margin width then
576 % right margin width.
577 % \end{itemize}
578 %
579 % The second parameter is the overall text width. This is given in the
580 % following format:
581 % \begin{itemize}
582 % \item first element is the number lengths
583 % \item subsequent elements are one width per parameter
584 % \end{itemize}
585 % \begin{macrocode}
586 \newcommand{\Parshapearray}[2]{%
587 \testarray{#1}(1)\edef\rjlpshap@maxA{\temp@macro}%
588 \testarray{#2}(1)\edef\rjlpshap@maxB{\temp@macro}%
589 \ifthenelse{\rjlpshap@maxA > \rjlpshap@maxB} {\edef\rjlpshap@max{\rjlpshap@maxA}}{\edef\rjlpshap@max{\rjlpshap@maxB}}%
590 \begin{parshapecollect}%
591 \forloop{rjlpshap@ctr}{1}{\not \value{rjlpshap@ctr} > \rjlpshap@max}{%
592 \ifthenelse{\value{rjlpshap@ctr} > \rjlpshap@maxA}{%
593 \setcounter{rjlpshap@ctr2}{\rjlpshap@maxA}%
594 \addtocounter{rjlpshap@ctr2}{\rjlpshap@maxA}%
595 }{%
596 \setcounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
597 \addtocounter{rjlpshap@ctr2}{\value{rjlpshap@ctr}}%
598 }%
599 % \end{macrocode}
600 % left margin from \#1:
601 % \begin{macrocode}
602 \parshapearrlenout{#1}{rjlpshap@ctr2}%
603 % \end{macrocode}
604 % get the line width
605 % \begin{macrocode}
606 \ifthenelse{\value{rjlpshap@ctr} > \rjlpshap@maxB}{%
607 \edef\rjlpshap@pos{\rjlpshap@maxB}%
608 \setcounter{rjlpshap@ctr3}{\rjlpshap@maxB}%
609 \typeout{A pos=\rjlpshap@pos\space of \rjlpshap@maxB}%
610 \testarray{#2}(\arabic{rjlpshap@ctr3})%
611 \typeout{temp=\temp@macro}%
612 \setlength{\rjlpshap@templinewidth}{\temp@macro}%
613 }{%
614 \stepcounter{rjlpshap@ctr}%
615 \edef\rjlpshap@pos{\arabic{rjlpshap@ctr}}%
616 \typeout{B pos=\rjlpshap@pos}%
617 \addtocounter{rjlpshap@ctr}{-1}%
618 \testarray{#2}(\rjlpshap@pos)%
619 \setlength{\rjlpshap@templinewidth}{\temp@macro}%
620 }%
621 \typeout{width=\the\rjlpshap@templinewidth}%
622 % \end{macrocode}
623 % subtract the left margin from the line width
624 % \begin{macrocode}
625 \addtolength{\rjlpshap@templinewidth}{-1\rjlpshap@tempwidth}%
626 % \end{macrocode}
627 % subtract the right margin from the line width
628 % \begin{macrocode}
629 \stepcounter{rjlpshap@ctr2}%
630 \edef\rjlpshap@pos{\arabic{rjlpshap@ctr2}}%
631 \testarray{#1}(\rjlpshap@pos)%
632 \setlength{\rjlpshap@tempwidth}{\temp@macro}%
633 \addtolength{\rjlpshap@templinewidth}{-1\rjlpshap@tempwidth}%
634 \parshapelenout{\rjlpshap@templinewidth}%
635 }%
636 \end{parshapecollect}%
637 }
638 % \end{macrocode}
639 % \end{macro}
640
641 % \subsection{Internal Definitions}
642
643 % rjlpshap@ctr: outermost loop counter:
644 % \begin{macrocode}
645 \newcounter{rjlpshap@ctr}
646 % \end{macrocode}
647
648 % rjlpshap@ctr2: used for index calculations internally:
649 % \begin{macrocode}
650 \newcounter{rjlpshap@ctr2}
651 % \end{macrocode}
652
653 % rjlpshap@ctr3: used for index calculations internally:
654 % \begin{macrocode}
655 \newcounter{rjlpshap@ctr3}
656 % \end{macrocode}
657
658 % rjlpshap@tempwidth: used as a register to read widths from arrays,
659 % and for calculations
660 % \begin{macrocode}
661 \newlength{\rjlpshap@tempwidth}
662 % \end{macrocode}
663
664 % rjlpshap@templinewidth: used as a register to calculate the line
665 % width when subtracting margins:
666 % \begin{macrocode}
667 \newlength{\rjlpshap@templinewidth}
668 % \end{macrocode}
669
670 % boolean used for breaking out of loops
671 % \begin{macrocode}
672 \newboolean{rjlpshap@loop}
673 % \end{macrocode}
674
675 % boolean used to track if the number of lengths output is odd or even
676 % \begin{macrocode}
677 \newboolean{rjlpshap@isodd}
678 % \end{macrocode}
679
680 % Filehandles needed for reading and writing temporary files
681 % \begin{macrocode}
682 \newwrite\rjlpshap@writer % holds \parshape lengths
683 \newwrite\rjlpshap@finalwriter % holds entire \parshape command
684 \newread\rjlpshap@reader % used to read writer to transfer to finalwriter
685 % \end{macrocode}
686
687 % rjlpshap@linecount: counts the number of lines read in the environment
688 % \begin{macrocode}
689 \newcounter{rjlpshap@linecount}
690 % \end{macrocode}
691
692 % Finally, undo the effect of $\backslash$makeatletter, and make @ be
693 % a special character again.
694 % \begin{macrocode}
695 \makeatother
696 % \end{macrocode}
697
698 % \Finale
699 \endinput