Debian Codegraph @

texmf-dist/source/latex/wrapfig2/wrapfig2.dtx

raw
1 % \iffalse
2 % !TEX encoding = UTF-8 Unicode
3 % Remember to use \StopEventually{}, otherwise no Check Sum
4 %<*internal>
5 \begingroup
6 \input docstrip.tex
7 \keepsilent
8 \preamble
9
10 Copyright (C) 1991-2004 by Donald Arseneau ([email protected])
11 Copyright (C) 2021-2025 by Claudio Beccari ([email protected])
12 License information appended
13
14 \endpreamble
15
16 \postamble
17
18 Distributable under the LaTeX Project Public License,
19 version 1.3c or higher (your choice). The latest version of
20 this license is at: http://www.latex-project.org/lppl.txt
21
22 This work is "maintained"
23
24 This work consists of file wrapfig2.dtx, and the derived
25 files wrapfig2.sty and wrapfig2.pdf, plus this file README.txt.
26
27 \endpostamble
28 \askforoverwritefalse
29
30 \generate{\file{wrapfig2.sty}{\from{wrapfig2.dtx}{package}}}
31
32 \def\tmpa{plain}
33 \ifx\tmpa\fmtname\endgroup\expandafter\bye\fi
34 \endgroup
35 %</internal>
36 % \fi
37 %
38 % \iffalse
39 %<*package>
40 %<package>\NeedsTeXFormat{LaTeX2e}[2019/01/01]
41 %</package>
42 %<*driver>
43 \ProvidesFile{wrapfig2.dtx}%
44 %</driver>
45 %<+package>\ProvidesPackage{wrapfig2}%
46 %^^A<+readme>File README.txt for package wrapfig2
47 %<*package|readme>
48 [2025-03-01 v.7.0.2 Wrap text around figures, tables, framed text blocks]
49 %</package|readme>
50 %<*driver>
51 %
52 \documentclass{ltxdoc}\errorcontextlines=100
53 \hfuzz 10pt
54 \usepackage[greek.ancient, english]{babel}
55 \usepackage[utf8]{inputenc}% for vintage exec.s
56 \usepackage[T1]{fontenc}
57 \usepackage{lmodern}
58 \usepackage{mflogo}
59 \usepackage{multicol,fancyvrb,verbatim,microtype,graphicx}
60 \usepackage{amsmath,kantlipsum,wrapfig2,xspace}
61 %
62 \GetFileInfo{wrapfig2.dtx}
63 \title{The \textsf{wrapfig2} package}
64 \author{Claudio Beccari\qquad E-mail: \texttt{claudio.beccari at gmail.com}}
65 \date{Version \fileversion~--~Last revised \filedate.}
66 %
67 \providecommand*\diff{\mathop{}\!\mathrm{d}}
68 \providecommand*\ped[1]{\ensuremath{_{\mathrm{#1}}}}
69 \renewcommand\meta[1]{{\normalfont\textlangle\textit{#1}\textrangle}}
70 \renewcommand\marg[1]{\texttt{\{\meta{#1}\}}}
71 \providecommand\opz{}
72 \renewcommand\opz[1]{{\normalfont\texttt{\itshape#1}}}
73 \providecommand\Marg{}
74 \renewcommand\Marg[1]{\texttt{\{#1\}}}
75 \providecommand\oarg{}
76 \renewcommand\oarg[1]{\texttt{[\meta{#1}]}}
77 \providecommand\Oarg{}
78 \renewcommand\Oarg[1]{\texttt{[#1]}}
79 \providecommand\aarg{}
80 \renewcommand*\aarg[1]{\texttt{<\meta{#1}>}}
81 \providecommand\Aarg{}
82 \renewcommand\Aarg[1]{\texttt{<#1>}}
83 \providecommand\barg{}
84 \renewcommand\barg[1]{\texttt{\string|\meta{#1}\string|}}
85 \providecommand\Barg{}
86 \renewcommand\Barg[1]{\texttt{\string|#1\string|}}
87 \providecommand\parg{}
88 \renewcommand\parg[1]{\texttt{(\meta{#1})}}
89 \providecommand\Parg{}
90 \renewcommand\Parg[1]{\texttt{(#1)}}
91 \providecommand\eTeX{}
92 \renewcommand\eTeX{\lower0.5ex\hbox{$\varepsilon\!$}\TeX}
93 \providecommand\pack{}
94 \renewcommand\pack[1]{{\normalfont\texttt{#1}}}
95 \providecommand\class{}
96 \renewcommand\class[1]{{\normalfont\texttt{#1}}}
97 \providecommand\env{}
98 \renewcommand\env[1]{\meta{\textsf{\slshape#1}}}\let\amb\env
99 \providecommand\Env{}
100 \renewcommand\Env[1]{\textsf{\slshape#1}}\let\Amb\Env
101 \providecommand\opt{}
102 \renewcommand\opt[1]{\textsl{\meta{#1}}}
103 \providecommand*\Bambiente[1]{\texttt{\char92begin\{#1\}}}
104 \providecommand*\Eambiente[1]{\texttt{\char92end\{#1\}}}
105 \let\Bamb\Bambiente \let\Benv\Bamb
106 \let\Eamb\Eambiente \let\Eenv\Eamb
107
108 \ProvideDocumentCommand\goodpagebreak{O{4}}{%
109 \dimen10=#1\baselineskip
110 \dimen8=\dimexpr\pagegoal-\pagetotal\relax
111 \ifdim\dimen8 < \dimen10 \newpage\fi}
112
113
114
115 \makeatletter
116
117 \AfterEndPreamble{%
118 \apptocmd{\TeX}{{}\xspace}{}{}
119 \apptocmd{\LaTeX}{{}\xspace}{}{}}
120
121 \DeclareRobustCommand\LaTeXe{%
122 \LaTeX\@killglue\kern0.15em2$_{\textstyle \varepsilon}${}\xspace}
123 \DeclareRobustCommand\LaTeXccix{%
124 \LaTeX\@killglue\nobreakspace2.09{}\xspace}
125 \DeclareRobustCommand\LaTeXiii{\LaTeX\@killglue\kern0.15em3{}\xspace}
126 \DeclareRobustCommand*\pdfLaTeX{pdf\/\LaTeX}
127 \DeclareRobustCommand*\LuaLaTeX{Lua\LaTeX}
128 \DeclareRobustCommand*\XeLaTeX{%
129 X\ifdim\fontdimen1\font=0pt\kern-0.15em\fi
130 \lower.5ex\hbox{\rotatebox[origin=c]{180}{E}}%
131 \ifdim\fontdimen1\font=0pt\kern-0.15em\else\kern-0.275em\fi
132 \LaTeX}
133
134 \providecommand\setfontsize{}
135 \RenewDocumentCommand\setfontsize{O{1.2} m}{%
136 \fontsize{#2}{\fpeval{#1*#2}}\selectfont}
137
138 \providecommand\hz{\hskip0pt}
139
140 \newenvironment{ttsintassi}{\begin{lrbox}{0}
141 \minipage{\dimexpr\linewidth-2\fboxrule-2\fboxsep}\ttfamily\obeylines}%
142 {\endminipage\end{lrbox}\center\fbox{\box0}\endcenter}
143
144
145 %
146 \begin{document}\errorcontextlines=100
147 \maketitle
148 \columnseprule=0.4pt
149 \begin{multicols}{2}
150 \tableofcontents
151 \end{multicols}
152 \DocInput{wrapfig2.dtx}
153
154 \end{document}
155 %</driver>
156 % \fi
157 %
158 % \begin{abstract}
159 % This package \pack{wrapfig2} is a fork that extends Donald
160 % Arseneau's package \pack{wrapfig} (version 3.6, dated 2003) by
161 % adding some \LaTeXiii definitions that accept a final optional
162 % star; its presence changes the meaning of the first optional
163 % argument so that it becomes a correction to the number of
164 % lines that must be indented in order to receive the wrapped
165 % object.
166 %
167 % A new environment is added to the original \Env{wrapfigure}
168 % and \Env{wraptable}, namely \Env{wraptext}; it may be used to
169 % wrap a small framed text block on a possibly coloured
170 % background; the philosophy of this new environment is
171 % similar to that of the other two environments, but the syntax
172 % was different with version~4 of this package, and is very
173 % similar with version 5.0; a further important enhancement is
174 % implemented in versions~6 and~7. Fall back options are
175 % available for backwards compatibility.
176 %
177 % This version 7 is a new implementation of the \Env{wraptext}
178 % environment, in the sense that it does not make use of the
179 % \pack{curve2e} package so as to avoid some interferences with
180 % other user selected packages.
181 % \end{abstract}
182 %
183 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 %
185 % {\color{red}\paragraph{Caution} This package requires a fairly
186 % recent \LaTeX kernel, otherwise it won't work; any \LaTeX
187 % kernel dated at least 2019 is~OK.
188 %
189 % Read carefully this document, because the are several pieces
190 % of information concerning other packages that may be
191 % incompatible with this \pack{wrapfig2} version. Special
192 % warnings are typeset in red as this one.}
193 %
194 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 %
196 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 % \section{Introduction}
198 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 %
200 % The purpose of this package is manyfold. On one side it tries
201 % to upgrade the original software by Donald Arseneau by
202 % using some parts of the \LaTeXiii modern language. On another
203 % it creates a new environment, with the same philosophy
204 % of the original Arseneau's ones, such that users
205 % can emphasise short blocks of wrapped text by framing them
206 % while typesetting the text on a coloured background.
207 %
208 % The original software had some idiosyncrasies; Donald Arseneau
209 % described them in the documentation of his package; we must
210 % admit that such idiosyncrasies might have been just slightly
211 % reduced; but in any case, in order to avoid such peculiar
212 % anomalies, it is sufficient to wrap the inserted object with a
213 % reasonable number of lines, i.e. with reasonably long
214 % paragraphs.
215 %
216 % The above implies that no wrapped object code should be
217 % specified in the source file close the end of a paragraph,
218 % unless it is followed by other paragraphs; again, no object
219 % code should be inserted within any list; nor even close to the
220 % end or to the beginning of a section. Arseneau's code is
221 % capable of specifying the wrapping number of lines such that
222 % two or more paragraphs can be indented so as to wrap a longish
223 % insertion, but it is wise to avoid such risky situations.
224 % Moreover, if the inserted object has a numbered caption, the
225 % number might not result in the correct sequence with the
226 % normal corresponding floating objects.
227 %
228 % Therefore the usefulness of the wrapping procedure depends
229 % very much on the users' ability to move around their code
230 % until a suitable position is found. Certainly a good place is
231 % within a longish paragraph especially at the beginning of a
232 % section; or at the beginning of a chapter that starts with
233 % plain text, in particular just at the beginning of the chapter
234 % first paragraph.
235 %
236 % The code of this package does very little, if anything, to
237 % correct such idiosyncrasies. They are caused by the
238 % limitations of the \cs{ShipOut} \LaTeXe kernel macro, and very
239 % little we were able to do in addition to what Arseneau already
240 % did.
241 %
242 % Another purpose of this package is to add another optional
243 % argument so that the \meta{number of indented lines} argument
244 % does not mean the total number, but the correction number to
245 % add-to or subtract-from the value computed by the default
246 % algorhythm devised by Arseneau.
247 %
248 % We assume that most users first use the software to insert an
249 % object to be wrapped by the surrounding text without
250 % specifying any value with the specific optional argument; then
251 % they evaluate the result, and if the space below the wrapped
252 % object is too large, or if such space is too small they count
253 % the necessary number of lines and specify it to be processed
254 % during another document compilation.
255 % When the object to be wrapped is tall, it is very easy to
256 % miscount the necessary number of lines, while is is very easy
257 % to evaluate the necessary small correction to the computed
258 % value.
259 %
260 % A further purpose of this package is to define a new
261 % environment, \Env{wraptext}, to wrap a framed text block
262 % typeset on a possibly coloured background.
263 % On \texttt{tex.stackexchange} a solution was suggested
264 % to a user who was asking for such an arrangement; the solution
265 % resorted to a specific use of the \Env{wrapfigure} environment
266 % and used the \Env{tcolorbox} environment.
267 %
268 % We thought that an \emph{ad hoc} solution would be a better
269 % one, since the parameters to be used for a figure have nothing
270 % or little to do with a text, therefore most of them would be
271 % useless with a wrapped text. Nevertheless the \meta{location}
272 % of the wrapped text and the optional correction of the
273 % indented lines number would still be necessary. We added also
274 % the possibility of optionally specifying the measure of the
275 % wrapped text, even if it should not be too different from a
276 % half of the wrapping text measure. In facts, with a value too
277 % different from \texttt{0.5\cs{linewidth}} either the wrapped
278 % text has problems with inter word spacing and hyphenation
279 % because of the small measure, or, on the opposite, the
280 % indented lines of the wrapping text would have similar
281 % problems.
282 %
283 % Notice that the first implementation of this package,
284 % version~4, achieved the desired result but there were two
285 % drawbacks: $(a)$ the syntax was rather different from that of
286 % the other environments, and $(b)$ any possible caption was
287 % typeset within the same framing environment. In version~5 both
288 % drawbacks were eliminated, but since the environment syntax is
289 % different, in oder to assure backwards compatibility a package
290 % option was defined in order to fall back to the previous
291 % version~4 behaviour; nevertheless we discourage this solution,
292 % and invite uers to use the most recent version. In version 6
293 % the \Env{wraptext} environment was further enhanced so as to
294 % accept several \texttt{key=value} settings concerning the text
295 % appearance, the colours, and other details relative to the
296 % wrapping process. Again another fall back option was defined
297 % in order to use the same functionalities of version~5; again
298 % we discourage using any fall back solution. This version~7
299 % does not use anymore the \pack{curve2e} functionalities, but
300 % resorts to package \pack{pict2e}; the code is simpler and
301 % several dozen lines shorter.
302 %
303 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % \section{Environment syntax}
305 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 %
307 % The new syntax for \Env{wrapfigure} and \Env{wraptable} is
308 % backwards compatible with the original one: just a final
309 % optional star is added to the original list of arguments.
310 %
311 % The optional star is available only for the standard
312 % \Env{wrapfigure} and \Env{wraptable} environments because the
313 % backwards compatibility requires the first four optional and
314 % mandatory arguments to be maintained identical. When the
315 % optional star is specified, the \meta{indented lines number}
316 % is interpreted as the correction to the computed value.
317 %
318 % Notice the different syntax in versions~4, 5, 6 and~7 of the
319 % \Env{wraptext} syntax.
320 %
321 % \begin{ttsintassi}\setfontsize{8.00}
322 %\Bambiente{wrapfigure}\oarg{indented lines number}\marg{location}\oarg{overhang}\oarg{width}\meta{$\star$}
323 %\qquad\meta{figure}
324 %\Eambiente{wrapfigure}
325 %~
326 %\Bambiente{wraptable}\oarg{indented lines number}\marg{location}\oarg{overhang}\oarg{width}\meta{$\star$}
327 %\qquad\meta{table}
328 %\Eambiente{wraptable}
329 %~
330 %\textnormal{\color{red}Package option \opt{WFold} required for backwards compatibility with version 4.*}.
331 %~
332 %\Bambiente{wraptext}\oarg{location}\barg{width}\aarg{indented line number correction}\parg{caption label}
333 %\qquad\meta{text to frame}
334 %\Eambiente{wraptext}
335 %~
336 %\textnormal{\color{red}Package option \opt{WFfive} required for backwards compatibility with version 5.*}.
337 %~
338 %\Bambiente{wraptext}\oarg{indented lines number correction} \marg{location} \oarg{overhang} \marg{width}
339 %\qquad \meta{optional colour settings}
340 %\qquad\cs{includeframedtext}\oarg{insertion measure}\marg{text to frame}\oarg{\meta{frame thickness},\meta{frame separation}}\oarg{radius}
341 %\Eambiente{wraptext}
342 %~
343 %\textnormal{\color{red} No package option required for versions~6.* and~7.*}.
344 %~
345 %\Bambiente{wraptext}\oarg{indented lines number correction}\marg{location}\oarg{overhang}\marg{width}
346 %\cs{includeframedtext}\oarg{insertion measure}\marg{text to frame}\oarg{key=value settings}\oarg{radius}
347 %\Eambiente{wraptext}
348 % \end{ttsintassi}
349 % \noindent
350 %\textcolor{red}{Please notice that the \Env{wraptext}
351 % environment does not require any optional star, because the
352 % specified indented lines number is always interpreted as its
353 % \emph{correction, not its absolute value}; this difference is
354 % clearly marked in the above syntax medallion. If users
355 % specified the star in similitude with the other two
356 % environments, with versions~5.* to~7.* the unnecessary
357 % star produces a strongly emphasised warning message visible in
358 % the editor console and in the \texttt{.log} file. With the old
359 % version~4.* the unnecessary star is printed as part of the
360 % text to be framed.
361 %\newline
362 % Please notice also that all three \Env{wraptext} syntaxes,
363 % thanks to differently delimited optional arguments with
364 % peculiar default values, become very similar when such
365 % optional arguments are reduced to a minimum; only the
366 % \meta{location} argument is delimited by brackets with the old
367 % version and with braces with the newer ones.}
368 %
369 % It may be useful to compare the \cs{includeframedtext} macro,
370 % used to insert a framed test into a \Env{wraptext}
371 % environment, with \cs{includegraphics}, used to insert an
372 % external image into a \Env{figure} environment. Their
373 % functions are similar even if they refer to different objects
374 % to include. Their codes are obviously very different and the
375 % latter is much more complex than the former. The solution for
376 % a framed text used by version~4 was inspired by the
377 % information found on \texttt{tex.stackexchange} that used the
378 % very elaborate \Env{tcolorbox} environment; version~5 used
379 % instead a much simpler command \cs{framedbox} based on the
380 % \pack{curve2e} package macro \cs{Curve}. Version 6.* admits
381 % many settings, not just the \meta{frame thickness} and the
382 % space around the framed text, but several others ones
383 % collectively indicated with \meta{settings}; such settings
384 % refer to colours, dimensions, styles, and so on, relative to
385 % the text and to the frame; moreover they are set by
386 % means of the \texttt{key=value} syntax. Version~7.* does not
387 % use any more the \pack{curve2e} macro \cs{Curve},
388 % but it uses the simpler low level macros defined in package
389 % \pack{pict2e}. The syntax is the same as with version~6.* but
390 % the inner workings are much different and faster to execute.
391 % As it can be seen, the logic, not the code, behind these
392 % different macros are very similar.
393 %
394 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 %\section{Examples}
396 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 % We display some examples by using fake objects and suitably
398 % long paragraphs; some fake-language long-paragraphs are
399 % obtained by means of the \pack{kantlipsum} package
400 % functionalities; they are typeset with an italic font in order
401 % to distinguish their text from the normal one.
402 %
403 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 % \subsection{A wrapped figure}
405 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 %
407 %
408 %\begin{wrapfigure}{r}{50mm}
409 %\centering\unitlength=1mm
410 %\begin{picture}(40,30)
411 %\polyline(0,0)(0,30)(40,0)(0,0)(40,30)(0,30)
412 %\Line(40,0)(40,30)
413 %\end{picture}
414 %\caption{A rectangle with its diagonals}\label{fig:figure}
415 %\end{wrapfigure}
416 %{\itshape \kant[1]}
417 % The code used to type figure~\ref{fig:figure} is the following:
418 %
419 %\begin{flushleft}\ttfamily\obeylines%
420 %\noindent\Bambiente{wrapfigure}\Marg{r}\Marg{50mm}
421 %\cs{centering}\cs{unitlength}=1mm
422 %\Bambiente{picture}\texttt{(40,30)}
423 %\cs{polyline}\texttt{(0,0)(0,30)(40,0)(0,0)(40,30)(0,30)}
424 %\cs{Line}\texttt{(40,0)(40,30)}
425 %\Eambiente{picture}
426 %\cs{caption}\Marg{A rectangle with its diagonals}\cs{label}\Marg{fig:figure}
427 %\Eambiente{wrapfigure}
428 %\Marg{\cs{itshape} \cs{kant}\Oarg{1}}
429 %\end{flushleft}
430 %
431 % No asterisk was used because the package succeeded to
432 % correctly compute the necessary number of indented lines.
433 %
434 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % \subsection{A wrapped table}
436 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 %\begin{wraptable}[-1]{l}*
438 %\centering
439 % \begin{tabular}{cc}
440 % \hline
441 % First & Second\\
442 % Third & Fourth\\
443 % \hline
444 %\end{tabular}
445 %\caption{A small table}\label{tab:small-table}
446 %\end{wraptable}
447 %{\itshape \kant[2]}
448 %
449 % The wrapped small table~\ref{tab:small-table} has been typeset
450 % by means of the following code.
451 %\begin{flushleft}\ttfamily\obeylines
452 %\Bambiente{wraptable}\Oarg{-1}\Marg{l}*
453 %\quad\cs{centering}
454 %\quad\Bambiente{tabular}\Marg{cc}
455 %\qquad\cs{hline}
456 %\qquad First \& Second\string \\
457 %\qquad Third \& Fourth\string \\
458 %\qquad\cs{hline}
459 %\quad\Eambiente{tabular}
460 %\quad\cs{caption}\Marg{A small table}
461 %\Eambiente{wraptable}
462 %\Marg{\cs{itshape} \cs{kant}\Oarg{2}}
463 %\end{flushleft}
464 % Notice the absence of the braced width value; as said below,
465 % this braced value is optional, and the software autonomously
466 % computes the width of the wrapped object. This feature may be
467 % useful in many instances, although a smart use of this width
468 % parameter might yield better looking results.
469 %
470 % Wrapping a small table is a little more difficult than
471 % wrapping a figure, because the width of the inserted object is
472 % not exactly known in advance, and it is difficult to estimate;
473 % therefore it might be necessary to execute several trial
474 % compilations. In any case a \cs{centering} command might help
475 % to center the table within the indention of the wrapping text.
476 % Nevertheless the software can compute the object width if a
477 % zero value is specified, or if the \meta{width} parameter is
478 % completely omitted together with its braces; this second
479 % possibility is a feature of this package, that uses a
480 % \LaTeXiii property by which even a braced argument can be
481 % treated as an optional argument with a predefined default
482 % value; see below more details about such feature.
483 %
484 % On the opposite if the user estimates that the table with its
485 % caption might use 5~lines, and specified such a value as the
486 % first (optional) argument to the environment, and no asterisk
487 % is specified, the result is shown in
488 % table~\ref{tab:wrong-wrapped-table}, but it is a very
489 % poor one, with the last caption line overlapping the wrapping
490 % text.
491 %
492 %\begin{wraptable}[5]{l}
493 %\centering
494 % \begin{tabular}{cc}
495 % \hline
496 % First & Second\\
497 % Third & Fourth\\
498 % \hline
499 %\end{tabular}
500 %\caption{A small table}\label{tab:wrong-wrapped-table}
501 %\end{wraptable}
502 %{\itshape \kant[2]}
503 %
504 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505 % \subsection{A wrapped text}
506 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
507 %
508 % \begin{wraptext}{l}
509 % \includeframedtext{Text, text, text, text, text, text, text, text, text, text, text.}
510 % \end{wraptext}
511 % {\itshape \kant[3]}
512 %
513 % The above example was typeset with this simple code:
514 %\begin{flushleft}\obeylines
515 % \Bamb{wraptext}\Marg{l}
516 % \cs{includeframedtext}\Marg{\ttfamily Text, text, text, text, text, text, text, text, text, text, text.}
517 % \Eamb{wraptext}
518 % \Marg{\cs{itshape} \cs{kant}[3]}
519 %\end{flushleft}
520 %
521 % The result is the same as that obtainable with version~4 of
522 % this package, but the \meta{location} argument specification
523 % is braced instead of bracketed.
524 %
525 % Remember, though, what was previously remarked about using an
526 % unnecessary optional star with the \Env{wraptext} environment;
527 % with this package versions~5 to~7 the unnecessary star
528 % produces a warning message, while with version~4 it prints the
529 % star as if it was part of the text to be wrapped.
530 %
531 % If a caption is specified, version~4 would print it within the
532 % framed box, while versions~5,~6, and~7 print a visible warning
533 % message and in the \texttt{.log} file.
534 %
535 % \begin{wraptext}{r}{0.5\linewidth}\centering
536 % \includeframedtext{Text, text, text, text, text, text, text, text, text, text, text.}
537 %\caption{A wrapped text}%
538 % \end{wraptext}
539 % {\itshape \kant[3]}
540 %
541 % With version~5 users have the possibility of choosing the
542 % colours for all three elements of the framed text; if within
543 % the \Env{wraptext} environment and before using
544 % \cs{includeframedtext} the colours are set different from the
545 % default light grey for the background, black for the text,
546 % and almost black for the frame:
547 % \begin{ttsintassi}
548 %\cs{SetWFfrm}\marg{frame colour}
549 %\cs{SetWFbgd}\marg{background colour}
550 %\cs{SetWFtxt}\marg{text colour}
551 % \end{ttsintassi}
552 % Such commands, in versions~6 and~7, are already taken care by
553 % the relevant \texttt{key=value} options, while with version~5
554 % these are user commands. See figure~\ref{fig:framed text}
555 % typeset with various version~7 options.
556 %
557 %\begin{figure}
558 %\makebox[\textwidth]{\includeframedtext{Text}[insertionwidth=0.45\linewidth]
559 %\hfill
560 %\includeframedtext{Text}[insertionwidth=0.45\linewidth,fboxrule=1mm]}\\[2ex]
561 %^^A
562 %\makebox[\textwidth]{\includeframedtext{Text}[insertionwidth=0.45\linewidth,textcolor=red,fboxrule=2pt]
563 %\hfill
564 %\includeframedtext{Text}[insertionwidth=0.45\linewidth,fontstyle=\Large]}\\[2ex]
565 %^^A
566 %\makebox[\textwidth]{\includeframedtext{Text}[insertionwidth=0.45\linewidth,backgroundcolor=yellow]
567 %\hfill
568 %\includeframedtext{Text}[insertionwidth=0.45\linewidth, framecolor=blue, backgroundcolor=yellow, fboxrule=1mm]}\\[2ex]
569 %^^A
570 % \makebox[\textwidth]{\includeframedtext{Text}[insertionwidth=0.5\linewidth, fboxrule=0pt, backgroundcolor=cyan, textcolor=white, fontstyle=\Huge\bfseries]}
571 %\caption{Some framed text boxes with different dimensional
572 % parameters, different font size, and different colours}\label{fig:framed text}
573 %\end{figure}
574 %
575 % Figure~\ref{fig:framed text} used the following code, where it
576 % is evident that the \cs{includeframedtext} command is
577 % available even outside the \Env{wraptext} environment.
578 %\begin{flushleft}\ttfamily\obeylines
579 %\Bambiente{figure}
580 %\cs{makebox}[\cs{textwidth}]\Marg{\cs{includeframedtext}\Marg{Text}\%
581 %\qquad [insertionwidth=0.45\cs{linewidth}]
582 %\quad\cs{hfill}
583 %\quad\cs{includeframedtext}\Marg{Text}\%
584 %\quad [insertionwidth=0.45\cs{linewidth},fboxrule=3pt]}\cs{\char92}[2ex]
585 %\%
586 %\cs{makebox}[\cs{textwidth}]\Marg{\cs{includeframedtext}\Marg{Text}\%
587 %\quad [insertionwidth=0.45\cs{linewidth},textcolor=red,fboxrule=2pt]
588 %\quad\cs{hfill}
589 %\quad\cs{includeframedtext}\Marg{Text}\%
590 %\qquad[insertionwidth=0.45\cs{linewidth},fontstyle=\cs{Large}]}\cs{\char92}[2ex]
591 %\%
592 %\cs{makebox}[\cs{textwidth}]{\cs{includeframedtext}\Marg{Text}\%
593 %\quad[insertionwidth=0.45\cs{linewidth}, backgroundcolor=yellow]
594 %\quad\cs{hfill}
595 %\quad\cs{includeframedtext}\Marg{Text}\%
596 %\qquad[insertionwidth=0.45\cs{linewidth},framecolor=blue,
597 %\qquad backgroundcolor=yellow,fboxrule=1mm]}\cs{\char92}[2ex]
598 %\%
599 % \cs{makebox}[\cs{textwidth}]{\cs{includeframedtext}\Marg{Text}\%
600 %\quad [insertionwidth=0.5\cs{linewidth}, fboxrule=0pt,
601 %\qquad backgroundcolor=cyan,textcolor=white,fontstyle=\cs{Huge}\cs{bfseries}]}
602 %\cs{caption}\Marg{Some framed text boxes ... different colours}
603 %\cs{label}\Marg{fig:framed text}
604 %\Eambiente{figure}
605 %\end{flushleft}
606 %
607 % As it is possible to notice from figure~\ref{fig:framed text},
608 % versions~6 and~7 add another facility; the colours and
609 % dimensions of the elements of the wrapped objects are inserted
610 % as \textit{key=value} options to the \cs{includeframedtext}
611 % third argument \meta{settings}; its default value is “empty”;
612 % users can introduce as many options as they desire, among the
613 % valid ones; if an option is misspelled or its value is not
614 % coherent with its nature, either the option is ignored, or an
615 % error is raised. The valid options are the following ones;
616 % they are listed in alphabetical order, because the options
617 % described with the \texttt{key=value} syntax do not require
618 % either a specific order or their presence; users can therefore
619 % specify from zero to nine options.
620 %\begin{description}
621 %^^A
622 %\item{\ttfamily backgroundcolor}
623 % sets the background colour among those defined by the default
624 % set provided by package \pack{xcolor}. The default colour is
625 % light grey.
626 %^^A
627 % \item{\ttfamily fboxrule}
628 % sets the thickness of the frame; a zero value
629 % is allowed, otherwise it should not be smaller than
630 % \texttt{0.4pt}; on the opposite it should not be set too large
631 % and \texttt{1mm} appears as a thick enough frame around the
632 % wrapped text.
633 %^^A
634 % \item{\ttfamily fboxsep}
635 % sets the distance of the frame from the wrapped text; by
636 % default it is set to \texttt{1ex}; also in this case it is
637 % better to avoid exaggerations. Notice that the default value
638 % depends on the wrapped text font x-height.
639 %^^A
640 %\item{\ttfamily fontstyle}
641 % sets any available \emph{declaration} that changes the
642 % characteristics of a font: size, series, shape; it is possible
643 % to use also the \cs{usefont} command with all its four
644 % arguments, even the font encoding. This \pack{wrapfig2} has
645 % available also the \cs{setfontsize} command that can select
646 % any size with any font that has available at least a stepwise
647 % continuous size set; for example the Latin Modern fonts have a
648 % stepwise continuous size set, while Computer Modern have
649 % available only a discrete size set.
650 %^^A
651 %\item{\ttfamily framecolor}
652 % sets the color of the frame; the colours available are those
653 % available with package \pack{xcolor} to which no options have
654 % been specified; see its documentation and in case load
655 %\pack{xcolor} with the desired options before this package
656 % \pack{wrapfig2}. The default colour is a very dark grey.
657 %^^A
658 %\item{\ttfamily insertionwidth}
659 % sets the insertion width; as it was previously specified, if
660 % this width is too small or too large it will be automatically
661 % reassigned a value within the allowed range.
662 %^^A
663 %\item{\ttfamily radius}
664 % sets the optional radius of the frame rounded “corners”; if it
665 % is not specified, such radius is equal to the default value of
666 % \cs{fboxsep}. Although it is possible to use it, we suggest to
667 % abide from using it.
668 %^^A
669 % \item{\ttfamily scalefactor}
670 % sets the value that establishes a reasonable range of the
671 % insertion width; users can specify any value in the range
672 % $xy_0 = y\ped{min} \leq y \leq y\ped{max} = y_0/x$, where
673 % $y_0$ is the default value, and $x$ is the scaling factor that
674 % by default equals $0.8$; this means that if $y_0$ equals half
675 % the current measure, the inserted wrapped text produces an
676 % indentation of the wrapping lines approximately between 60\%
677 % and 40\% the current measure; the wrapped text should never
678 % have a too short measure and the wrapping indented lines never
679 % have a too short measure. If users specify a different value
680 % to this key, they might get problems with inter word spacing
681 % and with hyphenation.
682 %^^A
683 %\item{\ttfamily textcolor}
684 % sets the text colour among those available with the default
685 % set provided by package \pack{xcolor}. The default colour is
686 % black.
687 %^^A
688 %\end{description}
689 %
690 % These versions~6 and~7 have a more flexible way compared to
691 % version~5 to specify the details relative to the framed text,
692 % but they are relevant only for the \cs{includeframedtext}
693 % command; the syntax for the \Env{wraptext} environment opening
694 % command is identical. As it was previously shown, the syntax
695 % of environment \Env{wraptext} for versions~7,~6, and~5 is
696 % practically identical to the one used for both other
697 % environments; actually, as it can be seen below in the code
698 % description of versions~7, 6 and~5, it has a fairly longer
699 % definition; it is required by the necessity of avoiding the
700 % \cs{caption} changes foreseen in package{wrapfig} when
701 % \pack{float} is used to define another floating object, but in
702 % effects the new definition of the \Env{wraptext} environment
703 % uses the same \cs{wrapfloat} and \cs{endwrapfloat} commands.
704 %
705 % In all three cases the \meta{width} parameter is a
706 % \emph{braced optional argument}; for the \Env{wraptext}
707 % environment its preset value is half the column width, that in
708 % one column typesetting mode coincides with the text width. The
709 % wrapped text is typeset in justified mode within a \cs{parbox}
710 % argument; the measure of this text box should not be too small
711 % (unless the text is less than one line long) otherwise the
712 % inter word spacing might be too large; at the same time the
713 % measure of the mini paragraph cannot be too large, otherwise
714 % the indented wrapping lines, generally justified, might get a
715 % bad word spacing. As it was already explained, it is
716 % recommended to avoid specifying the optional \meta{widh}
717 % outside the range of 40\% to 60\% the column width. Actually
718 % specifying \texttt{0.2\cs{textwidth}} or
719 % \texttt{0.4\cs{columnwidth}} when typesetting in two column
720 % mode produces approximately the same result, because
721 % \cs{columnwidth} is a little less than half the
722 % \cs{textwidth}. In any case versions~7 to~5 of \Env{wrapfig2}
723 % reset any specified width outside the above range to the
724 % nearest range bound.
725 %
726 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 % \section{Remarks}
728 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
729 %
730 % The syntax of the original environments \amb{wrapfigure} and
731 % \amb{wraptable} has not been changed, except for a last
732 % optional star. The fact that the last \emph{braced argument is
733 % optional} does not change the backward compatibility with the
734 % original environments.
735 %
736 % Therefore the optional \meta{line number} argument maintains
737 % its meaning, unless the optional star is specified; in such a
738 % case that number assumes the meaning of a correction to the
739 % computed number of the indented lines.
740 %
741 % The mandatory \meta{location} maintains its meaning and the
742 % legal values are \texttt{l} (left), \texttt{r} (right),
743 % \texttt{L} (floating left), \texttt{R} (floating right),
744 % \texttt{i} (inner margin), \texttt{o} (outer margin),
745 % \texttt{I} (floating inner margin), \texttt{O} (floating outer
746 % margin).
747 %
748 % We tested all of them, but as a (possibly questionable)
749 % personal choice we prefer to place the wrapped object at the
750 % left of the text, without floating it and irrespective of the
751 % folio parity.
752 %
753 %\begin{wraptext}{l}{0.5\textwidth}%
754 %\includegraphics[width=\hsize]{stele-todi-small}
755 %\caption{The Todi stela written in Gallic and Latin.
756 % Gregorian Etruscan Museum in Rome.}\label{txt:todi-stela}
757 %\end{wraptext}
758 %{\itshape\kant[4]}
759 %
760 % As in the previous examples, we prefer to specify the wrapping
761 % environment just before a sufficiently long paragraph. Should
762 % the paragraph be too short to completely wrap the object, all
763 % the environments are capable of counting the number of used
764 % indented lines and to apply the remaining number (and the
765 % \cs{overhang} amount) to the following paragraph(s); in these
766 % circumstances it might be necessary to recourse to the
767 % optional star in order to correct the indention, since the
768 % mechanism does not consider the inter paragraph spacing that
769 % \LaTeX introduces only at ship~out time.
770 %
771 % We avoid also to enter the wrapping environment before
772 % paragraphs that are close to a page break; this action would
773 % tickle the idiosyncrasies of the software, and requires moving
774 % the wrapping environment some paragraphs before or after the
775 % preferred one; but this can be done only while reviewing the
776 % document, because any change in the previous source text might
777 % change the situation if this adjustment is done while still
778 % editing the document.
779 %
780 % Some of these idiosyncrasies might be avoided if the wrapped
781 % objects are allowed to float. Even Arseneau's \pack{wrapfig}
782 % allowed this feature, but according to our experience floating
783 % objects may solve the problems produced when they are in the
784 % chosen position, but they may create other problems; for
785 % example, if the chosen position falls close the the end of a
786 % page, and after that position a list starts; if the object
787 % floats to the beginning of the next page, and the list is
788 % still being processed, other errors emerge. For this reason
789 % floating wrapped objects are not so safe, and the best
790 % solution would be to chose their best position “by hand”.
791 %
792 % Juan Luis Varona Malumbres, whom we thank very much, noticed
793 % that if the space left at the bottom of a page is scarse, it
794 % may be that a section title falls alone at the bottom of the
795 % page and the wrapping environment with its wrapping text gets
796 % typeset on the next page; this of course is not acceptable. We
797 % found the place to correct and versions~7 and~6 more often
798 % than not do not exhibit any more this “feature”. Unfortunately
799 % in some rare cases this “feature” pops up again; a
800 % \cs{newpage} command before the section title solves the
801 % problem. This rare feature could be avoided if the sectioning
802 % commands are redefined; but this would imply modifications to
803 % a large number of redefinitions due to the large varieties of
804 % classes and packages that redefine such sectioning commands.
805 %
806 % With the standard environments the optional parameter
807 % \meta{overhang} does exactly what its name implies: the
808 % wrapped object protrudes into the adjacent margin exactly by
809 % the specified amount. This parameter is not available for the
810 % \Env{wraptext} environment, or better, it is still available
811 % in versions~7, 6 and~5, but we recommend to abide from using
812 % it; we believe that a wrapped text logically pairs the
813 % wrapping text; of course this is just a personal opinion.
814 %
815 % The \meta{width} parameter has been already sufficiently
816 % described; we just remember that for \Env{wraptext} this
817 % parameter is optional and its default value amounts to half
818 % the current measure; this insertion width can be specified but
819 % it should not be too different from its default value $y_0$,
820 % set to 50\% of the current measure. For the standard
821 % environments this parameter value appears to be mandatory;
822 % actually it really is a braced optional argument only for the
823 % redefined environments \env{wrapfigure} and \env{wraptable}.
824 %
825 % Matter of facts, for the \Env{wraptext} environment we defined
826 % a command in order to specify a factor $x$ so as to avoid
827 % getting the object width outside the range
828 % $xy_0 \leq y \leq y_0/x$, where $y_0$ is the preset default
829 % width; if the authors specified a value outside this range,
830 % the above environment automatically resets the insertion width
831 % $y$ to the nearest bound. Of course authors have the
832 % possibility to change the preset $x$ value, if they redefine
833 % the \cs{WF } macro, but such resetting is strongly
834 % discouraged; the default value is~$0.8$.
835 %
836 %\begin{wraptext}{l}
837 %\includeframedtext{^^A
838 % \foreignlanguage{greek}{Κα᾽γὼ σὲ πατάξας διαλύσω τὸ κρανὶον}}
839 % \caption{A sample text in Greek}\label{txt:greek}
840 %\end{wraptext}
841 %{\itshape\kant[7]}
842 %
843 % If optional parameters are not used and the mandatory ones are
844 % reduced to a minimum (remember the \meta{width}, in spite of
845 % being braced is optional) the three environments produce the
846 % same results; the difference, in spite of the nature of the
847 % wrapped object differs only with the environment name.
848 % Text~\ref{txt:todi-stela} displays an \emph{image} that
849 % contains some text; it is reasonable to insert it with the
850 % \Env{wrapfigure} environment, but it is not absurd to insert
851 % it with the \Env{wraptext} one, as we did with
852 % text~\ref{txt:todi-stela}.
853 %
854 % The wrapped text may be written also in a foreign language,
855 % even if it uses a different alphabet. Evidently this language
856 % should be specified in the preamble of the author's document,
857 % either when using \pack{babel} or \pack{polyglossia}. The
858 % example text~\ref{txt:greek} was typeset with the following
859 % code:
860 %\begin{flushleft}\ttfamily\obeylines
861 %\Bamb{wraptext}\Marg{l}
862 %\cs{includeframedtext}\Marg{\%
863 %\qquad\cs{foreignlanguage}\Marg{greek}\Marg{\foreignlanguage{greek}{Κα᾽γὼ σὲ πατάξας διαλύσω τὸ κρανὶον}}}
864 %\cs{caption}\Marg{A sample text in Greek}\cs{label}\Marg{txt:greek}
865 %\Eamb{wraptext}
866 %\end{flushleft}
867 %
868 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % \section{Other floating objects}
870 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
871 % Pictures and textual arrays may be floated by means of the
872 % standard \amb{figure} and \amb{table} environments. But other
873 % floating objects may be defined by means of other packages,
874 % such as \pack{float}, or classes, such as \class{memoir}.
875 % Besides floating, the main difference is the name of the
876 % caption “label”: Figure, Table, Algorithm, Example, and so on,
877 % in addition to the lists of such objects.
878 %
879 % If floating is not necessary, this package (as well as the
880 % original one) allows to use the underlying environment
881 % \Env{wrapfloat} that uses the same syntax as \Env{wrapfigure}
882 % plus the mandatory name of the new object: even a figure
883 % might be introduced without using \amb{wrapfigure}, by using
884 % instead:
885 %\begin{flushleft}\setfontsize{9.275}\ttfamily\obeylines
886 %\Benv{wrapfloat}\Marg{figure}\oarg{line number}\marg{placement}\oarg{overhang}\marg{width}\meta{$\star$}
887 %\quad\qquad\meta{image}
888 %\Eenv{wrapfloat}
889 %\end{flushleft}
890 % Another \meta{object} might be wrapped by using:
891 %\begin{flushleft}\ttfamily\obeylines
892 %\Benv{wrapfloat}\marg{object name}\oarg{line number}\marg{location}\%
893 %\quad \oarg{overhang}\marg{width}\meta{$\star$}
894 %\qquad\qquad\meta{object}
895 %\Eenv{wrapfloat}
896 %\end{flushleft}
897 %
898 % By reading the documentation of the original \pack{wrapfig}
899 % package, it may be assumed that, if the floating
900 % \meta{location} codes have to be used, another floating object
901 % with the desired \meta{object name} has to be previously
902 % defined by means of the functionalities of other packages or
903 % classes. But, if the non floating \meta{location} codes
904 % are used, the presence of another \meta{floating object}
905 % environment appears to be unnecessary.
906 %
907 % This is actually possible by “cheating” a little bit: it can
908 % be actually wrapped any \meta{object} by using the
909 % \Env{wrapfigure} environment, while assigning a different name
910 % to the caption label; something similar to typeset a small
911 % figure within a non floating environment. The obvious draw
912 % back is that the caption is numbered as a figure.
913 %
914 % In order to avoid such drawbacks and to have a real floating
915 % \meta{other object} environment it is necessary to procede by
916 % defining a new real floating environment with that name. To do
917 % this task, \pack{wrapfig2} versions~5,~6, and~7 use the
918 % \pack{float} package.
919 %
920 % As it is possible to verify by reading the section where the
921 % code is documented, the operation is not that simple because
922 % \pack{float} redefines several internal macros that are
923 % incompatible with both \pack{wrapfig} and \pack{wrapfig2}.
924 % This is why, even with \pack{wrapfig2} in versions~5--7, that
925 % load the \pack{float} package, the code for this environment
926 % redefines the \cs{caption} command so that Arseneau had to
927 % define some adjusting macros in order to deal with something
928 % different from what it was with the \LaTeXe kernel. We did not
929 % modify what Arseneau defined, although it did not work
930 % correctly with the new \Env{text} floating environment.
931 % Therefore we reinstated the \LaTeXe kernel relevant
932 % definitions.
933 %
934 % It is possible that such resetting of the original definition
935 % is necessary also with floating objects defined by other
936 % means, for example by using the functionalities of the
937 % \class{memoir} class. We admit we did not test this package
938 % functionality with class \class{memoir};
939 % \textcolor{red}{feedback on this compatibility issue
940 % is very welcome}.
941 %
942 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
943 % \section*{Acknowledgements}
944 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
945 %
946 % We gratefully thank Donald Arseneau who gave the \TeX
947 % community the original \Env{wrapfig} package. For what
948 % concerns wrapped text, we did not use Arseneau's \pack{framed}
949 % package, because we wanted a frame with rounded corners.
950 % Nevertheless, while developing our package, we experimented
951 % also with his package that yields good results but with the
952 % ordinary right angle frame corners.
953 %
954 % Thanks to Heinrich Fleck who submitted to our attention the
955 % \texttt{tex.stackexchange} message where the problem of
956 % wrapping text was presented possibly for the first time. The
957 % solution presented in \texttt{tex.stackexchange} appears to be
958 % oversimple, almost trivial; especially it does not solve the
959 % problem of a caption if one is desired to describe that
960 % wrapped text. Moreover the solution of
961 % \texttt{tex.stackexchange} used in a very simple way the
962 % \Env{tcolorbox} environment, that behind the scenes uses a
963 % very heavy set of multifunctional macros that offer
964 % functionalities that are not required for this problem.
965 %
966 % Warm thanks also to Juan Luis Varona % Malumbres for his
967 % precious feedback and his suggestions.
968 %
969 % Herbert Voß spotted the necessity to follow a
970 % specific loading order if the \pack{amsmath}
971 % needs to be used; he was so kind to send us a
972 % bug notice together with a minimum working example.
973 % Thanks to Bruno Pagani who pinpointed the exact
974 % point that conflicted with \pack{wrapfig2} so
975 % that I could fix this conflict. Bruno Pagani
976 % discovered also that package \pack{amstext} is
977 % the source of this conflict and that this
978 % package is loaded not only by \pack{amsmath}
979 % but also by other packages such as, for example,
980 % by \pack{siunitx}.
981 %
982 % Many thanks to Ulrike Fisher who found a loading
983 % order problem reported on
984 % \texttt{tex.stackexchange} because a conflict with
985 % package \pack{circledsteps}, that should be loaded
986 % before \pack{wrapfig2}. Thanks a lot Ulrike.
987 %
988 % Thanks to Marei, who spotted a sneaky error that I
989 % never found in my tests; he even pointed out the
990 % line number where such error was present. Thanks a
991 % lot Marei.
992 %
993 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 % \CheckSum{1381}
995 % \StopEventually{}
996 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997 %
998 %\iffalse
999 %<*package>
1000 %\fi
1001 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002 % \section{The code}
1003 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004 %
1005 % Here we describe and comment the code of this package;
1006 % essentially only the initial parts need some comments;
1007 % because the final ones are almost identical to Arseneau's
1008 % original code.
1009 %
1010 % The usual specification of the format name and date, and the
1011 % identification of this specific package have been already
1012 % specified by the \texttt{.dtx} file.
1013 %
1014 % First of all we check if certain packages have already been
1015 % loaded; some of these packages, such as \pack{wrapfig}, that
1016 % might have been previously directly loaded, or might have been
1017 % loaded by other packages, are incompatible with this package
1018 % \pack{wrapfig2}. such packages, as \pack{caption} or
1019 % \pack{subcaption}, redefine some internals that we did not
1020 % want to replace so as to avoid other possible
1021 % incompatibilities. We first check if a specific macro with the
1022 % \texttt{WF} prefix has already been defined; if so, this
1023 % package \emph{loading} is aborted with a very visible error
1024 % message. In contrast the \emph{job} is not aborted, because
1025 % the presence of the original \pack{wrapfig} package might
1026 % still be sufficient; evidently there will be many errors if
1027 % some new user commands or environments are used.
1028 %
1029 %{\color{red}\paragraph{Caution} Besides the evident error
1030 % message, that might be neglected by the user, the job may
1031 % continue but it may produce several errors difficult to
1032 % interpret. Please, in these cases read the \texttt{.log} file
1033 % and look for error messages; there you are going to discover
1034 % what has gone wrong with your way of using this package.}
1035 %
1036 % \begin{macrocode}
1037 \ifcsname c@WF@wrappedlines\endcsname
1038 \PackageError{wrapfig2}{
1039 \MessageBreak
1040 **************************************************\MessageBreak
1041 Package `wrapfig' has already been loaded perhaps \MessageBreak
1042 by other packages, for example caption or subcaption.\MessageBreak
1043 Such packages are incompatible with wrapfig2 \MessageBreak
1044 Loading of`wrapfig2' is aborted \MessageBreak
1045 **************************************************\MessageBreak
1046 }{You might type X <return> and might get along without\MessageBreak
1047 this package if you don't use the new environment \MessageBreak
1048 `wraptext' and the new commands; otherwise you get \MessageBreak
1049 errors about such environment not being defined; \MessageBreak
1050 you must kill your job!}
1051 \expandafter\endinput\fi
1052
1053 % \end{macrocode}
1054 %
1055 % We keep the original definition of the
1056 % \cs{WF@warning} and the original definition of
1057 % the \opt{verbose} option; but we add the new
1058 % \opt{WFold} and \opt{WFfive} options in order to
1059 % fall back to the functionalities of the previous
1060 % version~4 or~5, at least for what concerns the
1061 % \Env{wraptext} environment.
1062 %
1063 %
1064 % \begin{macrocode}
1065 \def\WF@warning{\PackageWarning{wrapfig2}}
1066 \DeclareOption{verbose}{\def\WF@info{\PackageInfo{wrapfig2}}}
1067 \newif\ifWFnew \let\ifWFnew\iftrue
1068 \newif\ifWFfive \let\ifWFfive\iffalse
1069 \DeclareOption{WFold}{\let\ifWFnew\iffalse}
1070 \DeclareOption{WFfive}{\let\ifWFnew\iffalse\let\ifWFfive\iftrue}
1071 \ProcessOptions
1072
1073 % \end{macrocode}
1074 %
1075 % We load the \pack{etoolbox} package, in order to have
1076 % available its powerful macros.
1077 %
1078 % If it was not previously loaded, we load the \pack{xfp}
1079 % package, that allows us to perform precise calculations.
1080 %
1081 % Loading the \pack{xparse} package is necessary in order to use
1082 % one of its rare features that did not migrate to the \LaTeX
1083 % kernel. From the \LaTeX News Letter dated October 2020:
1084 %\begin{quote}
1085 % Most, but not all, of the argument types defined by
1086 % \pack{xparse} are now supported at the kernel level. In
1087 % particular, the types \texttt{g/G}, \texttt{l} and \texttt{u}
1088 % are not provided by the kernel code; these are
1089 % \emph{deprecated} but still available by explicitly loading
1090 % \pack{xparse}. All other argument types are now available
1091 % directly within the \LaTeXe kernel.
1092 %\end{quote}
1093 % The availability of these \emph{deprecated} types eases the
1094 % treatment of the backwards compatibility of this software with
1095 % the original \pack{wrapfig} and \pack{wraptable}
1096 % functionality. It deals with the mandatory \meta{width}
1097 % argument of the \Env{wrapfigure}, \Env{wraptable}, the new
1098 % \Env{wraptext}, and \Env{wrapfloat} environments, where it was
1099 % possible to specify a zero value. Now it is possible to omit
1100 % it completely because it is a \emph{braced optional argument}
1101 % with a \texttt{0pt} default value.
1102 %
1103 %
1104 % \begin{macrocode}
1105 \@ifpackageloaded{xparse}{}{\RequirePackage{xparse}}
1106 \@ifpackageloaded{xfp}{}{\RequirePackage{xfp}}
1107 \@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}}
1108 \@ifpackageloaded{float}{}{\RequirePackage{float}}
1109 \@ifpackageloaded{color}{}%
1110 {\@ifpackageloaded{xcolor}{}%
1111 {\RequirePackage{xcolor}}%
1112 }
1113 \@ifpackageloaded{pict2e}{}{\RequirePackage{pict2e}}
1114 \@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}
1115
1116 % \end{macrocode}
1117 % Notice that we loaded the \pack{xcolor} package without any
1118 % option in order to avoid option clash errors, and users who
1119 % want to use \pack{xcolor} with options should load it
1120 % \emph{before} this package \pack{wrapfig2}, versions~5--7.
1121 % {\color{red}Users are warned to pay attention to avoid loading
1122 % the \pack{color} package: they should never load it
1123 % before or after loading \pack{wrapfig2}; if they do, they
1124 % receive various warning or error messages because
1125 % \pack{xcolor} redefines some \pack{color} internal commands;
1126 % everything is explained in the \pack{xcolor} documentation.}
1127 %
1128 % In order to avoid conflicts with \pack{amstext}
1129 % and its |\text| command, we have to save its
1130 % definition before actually executing any part of
1131 % this package, and restore its value at the end
1132 % of this package; see the second part of this
1133 % procedure at the very end of this package.
1134 % \begin{macrocode}
1135 \ifcsdef{text}{\let\amsTextText\text}{}
1136
1137 % \end{macrocode}
1138 %
1139 % In order to define the new floating object \texttt{text} we
1140 % have to load the package \pack{float}, but only if versions~6
1141 % or later are used; in other words, only if the \cs{ifWFnew}
1142 % switch is \texttt{true}.
1143 %
1144 % If the \cs{chapter} command is or is not defined we have to
1145 % load the \pack{float} package with different options; for
1146 % example, if we are using the \class{article} class, the
1147 % \cs{chapter} command is undefined, and the last option might
1148 % become \opt{section} (although in the standard \class{article}
1149 % class, no floating object counter belongs to any other counter
1150 % reset list) so as to have the floating \Env{text} environment
1151 % correctly reset the right counter with the right label before
1152 % the object number.
1153 % \begin{macrocode}
1154 \ifboolexpr{ bool{WFfive} or bool{WFnew} }%
1155 {\floatstyle{plain}%
1156 \ifcsname chapter\endcsname
1157 \newfloat{text}{tbp}{lotx}[chapter]%
1158 \else
1159 \newfloat{text}{tbp}{lotx}%
1160 \fi
1161 \floatname{text}{Text}% redefine to localise in other languages
1162 \let\WF@text@caption\float@caption
1163 }{}
1164
1165 % \end{macrocode}
1166 %
1167 % If the users wanted to add the \texttt{text} counter to some
1168 % sectioning command counter reset list, they might use the
1169 % \cs{counterwithin} command now available with the recent
1170 % updates of the \LaTeX kernel; see the \LaTeX newsletter~28 for
1171 % details (terminal command: \texttt{texdoc ltnews28}). Its
1172 % syntax is the following:
1173 %\begin{ttsintassi}
1174 %\cs{counterwithin}\marg{counter}\marg{main counter reset list}
1175 %\end{ttsintassi}
1176 %
1177 % Next we define some dimensions, boxes, token registers,
1178 % \TeX counters, and alias names, plus some color and macro
1179 % definitions. The \cs{WF@correctlines@switch} \TeX numeric
1180 % register (not a \LaTeX counter) is going to be used as a
1181 % boolean switch: if its value is zero, il means “false”,
1182 % otherwise it is “true”; in the other definitions below, it
1183 % will be set only to 0 or 1, depending on the
1184 % presence of the optional star.
1185 % \begin{macrocode}
1186 \newdimen\wrapoverhang \wrapoverhang\z@
1187 \newdimen\WF@size
1188 \newcount\c@WF@wrappedlines
1189 \newbox\WF@box
1190 \newbox\NWF@box
1191 \newtoks\WF@everypar
1192 \newif\ifWF@float
1193 \newcount\WF@correctlines@switch
1194 \let\@@parshape\parshape
1195 \let\WF@@everypar\everypar
1196
1197 \newlength\WFfrthick
1198 \newlength\WFfrgap
1199 \newlength\WFfrwidth
1200 \newlength\WFfrheight
1201 \newdimen\insertwidth
1202 \newlength\WFXR \newlength\WFYD
1203 \newlength\WFXL \newlength\WFYU
1204 \newdimen\radius
1205 \newdimen\WFinsertwidthL
1206 \newdimen\WFinsertwidthH
1207
1208 \definecolor{WFbackground}{rgb}{0.95,0.95,0.95}
1209 \definecolor{WFframe}{rgb}{0.1,0.1,0.1}
1210 \colorlet{WFtext}{black}
1211 \def\SetWFbgd#1{\colorlet{WFbackground}{#1}}
1212 \def\SetWFfrm#1{\colorlet{WFframe}{#1}}
1213 \def\SetWFtxt#1{\colorlet{WFtext}{#1}}
1214
1215
1216 \def\WFsplitdimens#1,#2!{\fboxrule=#1\relax\fboxsep=#2\relax}
1217
1218 \providecommand\setfontsize{}
1219 \RenewDocumentCommand\setfontsize{O{1.2} m}{%
1220 \fontsize{#2}{\fpeval{#1*#2}}\selectfont}
1221
1222 \def\WFscalefactor{0.8}%
1223 \newcommand*\WFscalewidth{%
1224 \WFinsertwidthL=\fpeval{\WFscalefactor*0.5\linewidth}\p@
1225 \WFinsertwidthH=\fpeval{0.5\linewidth/\WFscalefactor}\p@
1226 \ifdim\insertwidth<\WFinsertwidthL
1227 \insertwidth=\WFinsertwidthL
1228 \else
1229 \ifdim\insertwidth>\WFinsertwidthH
1230 \insertwidth=\WFinsertwidthH
1231 \fi
1232 \fi
1233 }%
1234
1235 % \end{macrocode}
1236 % We define several options that use the \texttt{key=value}
1237 % syntax. Above we have already loaded the \pack{xkeyval}
1238 % package that offers also some ‘X’ labeled macros that mimic
1239 % the corresponding \LaTeXe kernel macros, but that are
1240 % necessary for using the \pack{xkeyval} internal macros. We
1241 % chose the \texttt{wraptext} option family name, because such
1242 % options are to be used mostly within the
1243 % \cs{includeframedtext} macro.
1244 % The \cs{ExecuteOptionX} used here stands for a general
1245 % initialisation of the listed options, but it will be used also
1246 % within the \cs{includeframedtext} command in order to set the
1247 % specified options for the specific use of this command.
1248 % \begin{macrocode}
1249 \DeclareOptionX<wraptext>{scalefactor}[0.8]{\def\WFscalefactor{#1}}
1250 \DeclareOptionX<wraptext>{fboxrule}[1pt]{\fboxrule=#1}
1251 \DeclareOptionX<wraptext>{fboxsep}[1ex]{\fboxsep=#1}
1252 \DeclareOptionX<wraptext>{framecolor}[WFframe]{\SetWFfrm{#1}}
1253 \DeclareOptionX<wraptext>{backgroundcolor}[WFbackground]{\SetWFbgd{#1}}
1254 \DeclareOptionX<wraptext>{textcolor}[WFtext]{\SetWFtxt{#1}}
1255 \DeclareOptionX<wraptext>{fontstyle}[\normalfont]{#1}
1256 \DeclareOptionX<wraptext>{radius}[\fboxsep]{\radius=#1}
1257 \DeclareOptionX<wraptext>{insertionwidth}[0.5\linewidth]{\insertwidth=#1}
1258 \DeclareOptionX*{\PackageWarning{wrapfig2}%
1259 {`\CurrentOption' ignored}}
1260
1261 \ExecuteOptionsX<wraptext>{scalefactor, fboxrule, fboxsep,
1262 framecolor, backgroundcolor, textcolor, fontstyle, radius,
1263 insertionwidth}
1264
1265 \ProcessOptionsX*
1266
1267 % \end{macrocode}
1268 %
1269 % {\color{red}Should the format file be not so up to date, a
1270 % multitude of errors would be produced, and the user should
1271 % take care to load the \pack{xparse} and \pack{xfp} packages
1272 % before loading \pack{wrapfig2}.
1273 % Notice that most of the \pack{xparse} package functionalities
1274 % are already included in the format file at the date required
1275 % for this file. The \pack{xparse} package has been available
1276 % since about 2018; should the users have available a definitely
1277 % older \TeX system installation, either they upgrade it, or
1278 % they must avoid using this \pack{wrapfig2} package and should
1279 % use the original \pack{wrapfig} one; if they need to wrap
1280 % text, they should resort to some ingenious, not so trivial
1281 % tricks to do it.}
1282 %
1283 % Originally version~4 used the \pack{tcolorbox} package to
1284 % frame the wrapped text; we thought that loading that package
1285 % was too heavy on memory, even if the modern computers have
1286 % large working memories. But in order to maintain and track
1287 % possible errors the traced \texttt{.log} file would become too
1288 % large to be of any help; therefore in oder to draw a framed
1289 % box with rounded corners we thought it would be much simpler
1290 % to load the \pack{curve2e} package, just a second level
1291 % extension of the original \Env{picture} environment defined in
1292 % the \LaTeXe kernel; only some 30 lines of code are sufficient
1293 % to replace the extremely powerful \pack{tcolorbox}
1294 % functionalities otherwise required to frame wrapped text with
1295 % this \pack{wrapfig2} package.
1296 %
1297 % We were informed that \pack{curve2e} was incompatible with
1298 % some other packages, in particular its commands were not
1299 % compatible with the recent modification of the \Env{picture}
1300 % environment, that since 2019 is capable to use absolute
1301 % dimensional data, without reference to \cs{unitlength}
1302 % multipliers. Therefore we decided to avoid loading
1303 % \pack{curve2e} and used \pack{pict2e} internal low level
1304 % commands that are already upgraded to receive absolute
1305 % dimensioned parameters. Of course we had to redefine several
1306 % internal commands of \pack{wrapfig2}. Here we describe in
1307 % details such new macros.
1308 %
1309 % The definitions of the \Env{wrapfigure} and \Env{wraptable}
1310 % environments are very simple by means of the underlaying
1311 % \Env{wrapfloat} environments.
1312 % \begin{macrocode}
1313 \NewDocumentEnvironment{wrapfigure}{o m o G{0pt}}%
1314 {\wrapfloat{figure}[#1]{#2}[#3]{#4}}%
1315 {\endwrapfloat}
1316
1317 \NewDocumentEnvironment{wraptable}{o m o G{0pt}}%
1318 {\wrapfloat{table}[#1]{#2}[#3]{#4}}%
1319 {\endwrapfloat}
1320
1321 % \end{macrocode}
1322 %
1323 % Notice that the argument type descriptor \texttt{s} for the
1324 % optional star is not present in these definitions; if a star
1325 % is being used, it will be read by successive macros or
1326 % environments.
1327 %
1328 % In order to include the text to be wrapped the floating object
1329 % \Env{text} has already been defined, but we need a suitable
1330 % command to insert it with its frame into the \Env{wraptext}
1331 % environment body. Here is the code of some extra macros and of
1332 % the \Env{wraptext} environment.
1333 %
1334 % We start with redefining \cs{includeframedtext} valid for
1335 % versions~6 and~7, that accepts \texttt{key=value} options, and
1336 % give up the alternative definitions for older versions.
1337 % \begin{macrocode}
1338 \ifboolexpr{ bool{WFfive} or bool{WFnew} }%
1339 {\NewDocumentCommand\includeframedtext{%
1340 O{\insertwidth} m O{} o}{%
1341 \bgroup
1342 \ExecuteOptionsX<wraptext>{#3}% executes possible options
1343 \insertwidth=#1\WFscalewidth
1344 \framedbox{\insertwidth}{\fboxrule}{\fboxsep}[\radius]{#2}\egroup}
1345 }{}
1346
1347 % \end{macrocode}
1348 %
1349 % Their simple syntax is the following
1350 %\begin{ttsintassi}
1351 %\cs{includeframedtext}\oarg{text width}\marg{text}\oarg{key=value settings}\oarg{radius}
1352 %\end{ttsintassi}
1353 %
1354 % The optional \meta{text width} is the (possibly scaled) width
1355 % computed by the \Env{wraptext} environment; but if authors
1356 % use this command outside the \Env{wraptext} environment, they
1357 % should specify a width; in any case the default value is half
1358 % the current measure \cs{linewidth}.
1359 %
1360 % The \meta{text} is the unformatted text to be wrapped; it will
1361 % be boxed and framed by the service macro \cs{framedbox}.
1362 %
1363 % The \meta{key-value settings} contains a comma separated list
1364 % of zero to nine settings with the syntax \texttt{key=value}
1365 % that are going to be used by both the \cs{includeframedtext}
1366 % and \cs{framedbox}.
1367 %
1368 % The last optional argument \meta{radius} (usable, but
1369 % actually useless because it can be set with a \emph{key=value}
1370 % option) is the curvature radius of the rounded frame corners;
1371 % its default value is going to be set to \cs{fboxsep}: in this
1372 % version its value is specified with the setting
1373 % \texttt{radius=\meta{dimension}} among the other
1374 % \meta{key=value settings}; the default value is certainly the
1375 % best one, but users can specify a different value, of course
1376 % not too different from the default one. See some examples in
1377 % figure~\ref{fig:framed text}.
1378 %
1379 % The definition of \cs{framedbox} is reduced to very simple
1380 % settings (initially the \meta{text} is typeset within a
1381 % \cs{parbox} of reduced measure: in facts the specified
1382 % insertion width is diminished with the sum of twice the frame
1383 % thickness and the frame gap; in this way the box dimensions
1384 % are going to be used by \cs{Frame} to compute the centres of
1385 % the corner arcs so as to draw the curved corners box needed to
1386 % use the \cs{arc} \pack{pict2e} macro; the actual macro that
1387 % draws the background and the frame is \cs{Frame};
1388 % nevertheless. it is \cs{framedbox} that decides to draw only
1389 % the background or also the box frame.
1390 %
1391 % The coloured background and the coloured frame have the same
1392 % contour; but the former is filled, while the latter is
1393 % stroked; we have to draw the same curve two times; first the
1394 % coloured background, then the superimposed frame
1395 %
1396 % This coloured framed curved corners rectangle is at the center
1397 % of the coordinate system of a \Env{picture} environment, and
1398 % has the correct dimensions to receive the boxed text; it is
1399 % trivial to center the text by means of a zero dimensioned box,
1400 % typical of the \Env{picture} environment.
1401 %
1402 % The code of this simple code is the following.
1403 % \begin{macrocode}
1404 \NewDocumentCommand\framedbox{m m m O{#3} m}{\bgroup
1405 %
1406 \dimen0=\dimexpr#1-(#2+#3)*2\relax
1407 \setbox0\hbox{\parbox{\dimen0}{\color{WFtext}#5}}%
1408 %
1409 \WFfrthick=#2\relax
1410 \WFXR=\dimexpr\wd0/2\relax \WFXL=-\WFXR%
1411 \WFYU=\dimexpr(\ht0+\dp0)/2\relax \WFYD=-\WFYU%
1412 \dimen4=#1\relax \dimen6=\dimexpr\ht0+\dp0+(#2+#3)*2\relax
1413 \dimen8=#4
1414 %
1415 {\begin{picture}(\dimen4,\dimen6)(-0.5\dimen4,-0.5\dimen6)
1416 \Frame*{\dimen4}{\dimen6}{\dimen8}%
1417 \ifdim\WFfrthick>0pt\Frame{\dimen4}{\dimen6}{\dimen8}\fi
1418 \put(0mm,0mm){\makebox(0,0){\box0}}%
1419 %
1420 \end{picture}}%
1421 \egroup\ignorespaces}
1422
1423 \NewDocumentCommand\Frame{s m m m}{%
1424 \bgroup
1425 \WFXR=\dimexpr#2/2\relax \WFXL=-\WFXR%
1426 \WFYU=\dimexpr#3/2\relax \WFYD=-\WFYU%
1427 \IfBooleanTF{#1}{\linethickness{0pt}\color{WFbackground}}%
1428 {\linethickness{\WFfrthick}\color{WFframe}}%
1429 %
1430 \moveto(\WFXR,\WFYD+#4)%
1431 \circlearc{\WFXR-#4}{\WFYU-#4}{#4}{0}{90}%
1432 \circlearc{\WFXL+#4}{\WFYU-#4}{#4}{90}{180}%
1433 \circlearc{\WFXL+#4}{\WFYD+#4}{#4}{180}{270}%
1434 \circlearc{\WFXR-#4}{\WFYD+#4}{#4}{270}{360}%
1435 \closepath
1436 \IfBooleanTF{#1}{\fillpath}{\strokepath}%
1437 %
1438 \egroup\ignorespaces}
1439
1440 % \end{macrocode}
1441 % The syntax of \cs{framedbox} is the following.
1442 %\begin{ttsintassi}\setfontsize{8.5}\obeylines
1443 %\cs{framedbox}\marg{frame width}\marg{frame thickness}\marg{frame separation}\oarg{corner radius}\marg{text to be wrapped}
1444 %\end{ttsintassi}¬
1445 %
1446 % The default value of the \meta{corner radius} is assigned so
1447 % as to equal argument number~3, that is the \meta{frame
1448 % separation} and both have a default value of \texttt{1ex};
1449 % therefore they vary with the current font size. See
1450 % figure~\ref{fig:framed text}. The frame thickness is given a
1451 % default value of \texttt{1pt} if the command is used within
1452 % the body of the \cs{includeframedtext}; but if this command
1453 % received a different value the frame may be thicker, or even
1454 % vanish; we discourage values higher than \texttt{3pt} (about
1455 % \texttt{1mm}) and lower than \texttt{1pt} unless it is zero.
1456 %
1457 % The \cs{Frame} command syntax is the following
1458 %\begin{ttsintassi}\setfontsize{8.5}\obeylines
1459 %\cs{Frame}\meta{$\star$}\marg{frame width}\marg{frame height}\marg{corner radius}
1460 %\end{ttsintassi}
1461 %
1462 %\begin{wrapfigure}{i}{45mm}
1463 %\includegraphics[width=45mm]{LAPDFcolori}
1464 %\caption{Reduced size of Detlef Reimers's colour wheel}
1465 %\label{fig:colour-wheel}
1466 %\end{wrapfigure}
1467 % The optional $\star$ decides to avoid stroking; therefore the
1468 % macro just fills the contour with the background color;
1469 % without the $\star$ the contour is stroked with the frame
1470 % width and color. \cs{box0}, that contains the now formatted
1471 % text with the text color, shall be superimposed on the center
1472 % of the frame; of course it is the user's duty to select the
1473 % various colours so that they are contrasting; no white over
1474 % yellow, for example; but yellow over blue is OK; It is
1475 % convenient to give a look to the colour circle the single page
1476 % documentation of \pack{colors} by Detlef Reimers:
1477 % \texttt{texdoc colors}; figure~\ref{fig:colour-wheel}. Trace
1478 % a diameter on the circular drawing, and the colours at both
1479 % intersections with the wheel circumference are certainly
1480 % contrasting; of course users can work also with colours that
1481 % differ in density, typically white vs.~black.
1482 %
1483 % The definition of the \Env{wraptext} environment is more
1484 % detailed than that of \Env{wrapfigure} and \Env{wraptable},
1485 % because most of the computations must be done on the
1486 % actual text to be wrapped, that does not have a specific
1487 % width; moreover the inserted text must not be too wide, nor
1488 % too slim in order to avoid problems with its justification or
1489 % the justification of the wrapping lines. The framed box width
1490 % is preset to 50\% of the normal text measure, but it can be
1491 % optionally specified to a different value (not too different
1492 % from 50\%); as with the other wrapping environments,
1493 % with versions~7 to~5 the inserted material width is a
1494 % \emph{braced optional argument}; with versions 6.0 and~7 the
1495 % default value of the \opz{radius} option is equal to
1496 % \cs{fboxsep}.
1497 %
1498 % For what concerns \Env{wraptext}, the opening statement
1499 % argument description list does not contain any descriptor for
1500 % an optional star. There is no need because the computation of
1501 % the insertion block height is pretty precise and at most the
1502 % user might desire one line more or less depending on the
1503 % measure of the whole formatted text, and that of the inserted
1504 % block and/or the measure of the indented wrapping lines;
1505 % sometimes it might be necessary to get rid of the space below
1506 % the inserted block when it gets typeset at the bottom of a
1507 % page. The star is not needed because for this environment
1508 % the optional first argument is always interpreted as the
1509 % indented lines number \emph{correction}; nevertheless if users
1510 % specify the optional star, as they are used to with the other
1511 % environments, such star produces a visible warning message
1512 % that reminds the user about its uselessness.
1513 %
1514 % It is true that some of the input parameters specified to the
1515 % opening command of any environment with \LaTeXiii are
1516 % available also to the closing commands; see the last paragraph
1517 % of section~2 in the \pack{xparse} documentation.
1518 %^^A
1519 % But the following definition uses the separate opening and
1520 % closing macros of the \Env{wrapfloat} environment; such
1521 % procedure breaks this second availability of the input
1522 % parameters, therefore it is necessary to save them into local
1523 % macros or count registers (remember that assignments to \TeX
1524 % count registers are \emph{local}, while assignment to \LaTeX\
1525 % named counters, through the \cs{setcounter} macro and its
1526 % siblings, are \emph{global}) so that we can use their values
1527 % within the closing commands.
1528 %
1529 % The \cs{NWF@box} box register has been allocated at the code
1530 % beginning; remember that \LaTeXiii registers of any kind are
1531 % not limited in number as they were some years ago with
1532 % \LaTeXe.
1533 %
1534 % The last opening commands are conceived to box the object to
1535 % be wrapped, typeset within a coloured box with the default of
1536 % specified width; compared to version~4, these new versions~5
1537 % to~7 do not use anymore the functionalities provided by
1538 % package \pack{tcolorbox}; instead they use the \pack{pic2e}
1539 % package functionalities to draw similar framed and shaded
1540 % boxes; this implies much less memory used by the almost
1541 % unlimited, but unused, functionalities of the \pack{tikz}
1542 % package on which \pack{tcolorbox} relies. Notice that the
1543 % plain \Env{picture} environment, extended with the
1544 % \pack{pict2e} package, can draw “ovals”, that is rectangles
1545 % with rounded corners, but, as far as we know, they have the
1546 % frame but cannot be colour filled.
1547 %
1548 % Notice the \Env{wraptext} has three definitions
1549 % depending on the logical switches \texttt{WFnew},
1550 % \texttt{WFfive}; if one of these switches is \texttt{true} the
1551 % definitions apply to either version~5 or versions~6 to~7 of
1552 % this package; otherwise the last definition is a fall back to
1553 % the functionality and the syntax of the previous version~4 of
1554 % this package; in this case, in spite of the fact that the
1555 % previous version used package \pack{tcolorbox}, the new code
1556 % relies on the \pack{pict2e} functionalities in oder to get the
1557 % same results without using the memory heavy \pack{tcolorbox}
1558 % package.
1559 %
1560 % With version 7, the frame that surrounds the wrapped text
1561 % has the desired rounded corners; it is possible to easily
1562 % specify the background and the frame colours, that by default
1563 % are maintained to light grey and almost black respectively;
1564 % this flexibility allows to set also the frame thickness and
1565 % the gap width between the frame and its contents; by
1566 % default they are~1pt for the frame thickness, and~1ex for the
1567 % gap width, that changes with the font size.
1568 %
1569 % The number of indented lines is computed by means of the
1570 % \cs{fpeval} \LaTeXiii function; among the operands of this
1571 % function there is the number \texttt{2} used to take into
1572 % account the vertical space above and below the framed box.
1573 % It is possible that a value of \texttt{3} might reduce the
1574 % probability of using the \meta{line number correction}. But
1575 % it is not always true and we found that the chosen value is
1576 % a better choice. By increasing the corner arc radius it is
1577 % possible to modify the gap width.
1578 %
1579 % Eventually the \Env{wrapfloat} opening statement is created by
1580 % expanding the whole line complete of its arguments, by means
1581 % of the usual trick of defining a dummy macro within a group
1582 % that contains among its expansion the group closing command,
1583 % so that while it is being executed, it deletes itself from
1584 % memory.
1585 %
1586 % Notice that the syntax of the new \Env{wraptext} environment
1587 % is absolutely identical to that of the other two wrapping
1588 % environments in terms of \meta{line number correction},
1589 % mandatory \meta{location}, optional \meta{overhang} and braced
1590 % optional \meta{width}. See below for the very different syntax
1591 % of the fall back version~4 opening \Env{wraptext} statement;
1592 % they become almost identical when no optional parameters are
1593 % specified, the only little difference being that the
1594 % \meta{location} argument is mandatory for versions~5 to~7,
1595 % while it is optional for version~4.
1596 % \begin{macrocode}
1597 \ifboolexpr{bool{WFnew} or bool{WFfive}}{% definition for versions 5 to 7
1598 \NewDocumentEnvironment{wraptext}%
1599 {O{0} m O{0pt} G{0.5\linewidth} s}%
1600 {%
1601 \insertwidth=#4\WFscalewidth
1602 \def\textcorrection{#1}%
1603 \def\textplacement{#2}%
1604 \def\textoverhang{#3}%
1605 \IfBooleanT{#5}{\PackageWarning{wrapfig2}{%
1606 *********************************************\MessageBreak
1607 With wraptext the optional star is useless \MessageBreak
1608 because the first optional argument always \MessageBreak
1609 means the "lines number CORRECTION" \MessageBreak
1610 *********************************************\MessageBreak}}
1611 \bgroup\edef\x{\egroup\noexpand\wrapfloat{text}%
1612 [\textcorrection]{\textplacement}[\textoverhang]{\insertwidth}*}\x%
1613 \def\caption{\unskip\unskip
1614 \refstepcounter\@captype
1615 \let\@tempf\@caption
1616 \unless\ifcsname @float@c@\@captype\endcsname
1617 \expandafter\expandafter\let
1618 \expandafter\@tempf\csname @float@c@\@captype\endcsname
1619 \fi
1620 \@dblarg{\@caption\@captype}%
1621 }%
1622 }{\endwrapfloat\ignorespaces}}%
1623 % \end{macrocode}
1624 %
1625 % For the fallback to version~4 definition of this
1626 % \Env{wraptext} environment we have to start with the old list
1627 % of specifically delimited optional arguments. We remember that
1628 % this opening statement receives in order a bracket delimited
1629 % optional \meta{location} parameter, a vertical bar delimited
1630 % optional \meta{width}, an angle bracket delimited optional
1631 % \meta{line number correction}, a round parenthesis delimited
1632 % optional \meta{caption label}; the different delimiters allow
1633 % to specify any optional argument without regard with the other
1634 % ones, provided they are in the same logical order when more
1635 % than one optional argument is specified.
1636 %
1637 % Notice that the third optional argument contains the
1638 % \meta{line number correction}, therefore the star used with
1639 % the other environments is useless; contrary to versions~5
1640 % to~7, if an asterisk is indadvertedly specified, it is typeset
1641 % as the first token of the wrapped test.
1642 %
1643 % The text to be wrapped, that forms the body of the
1644 % environment, must first be boxed into a correct width vertical
1645 % box; this is easily obtained with a \Env{minipage}
1646 % environment, of which the internal commands are used; this
1647 % insures that the text is typeset with the correct measure;
1648 % with the closing commands this boxed text is fed to the
1649 % \cs{framedbox} command, in order to be framed and assigned a
1650 % background color.
1651 % There is no possibility of specifying the colours unless the
1652 % whole \Env{wraptext} environment, preceded by explicit color
1653 % settings, is confined within a group delimited, for example,
1654 % by the \cs{begingroup} and \cs{endgroup} commands.
1655 % \begin{macrocode}
1656 {% definition for version 4 fall back
1657 %
1658 \NewDocumentEnvironment{wraptext}%
1659 {O{l} D||{0.5\columnwidth} D<>{0} D(){text}}%
1660 {% Open environment
1661 \insertwidth=#2
1662 \def\textplacement{#1}%
1663 \def\textcorrection{#3}%
1664 \def\WF@caption@label{#4}%
1665 \setbox0\hbox\bgroup
1666 \minipage{\dimexpr\insertwidth-2pt-6ex}%
1667 }{% Close environment
1668 \endminipage\egroup
1669 \begin{lrbox}{\NWF@box}%
1670 \framedbox{\box0}{1pt}{1ex}%
1671 \end{lrbox}
1672 \edef\NWF@wli]{\fpeval{%
1673 round((\ht\NWF@box+\dp\NWF@box)/\baselineskip,0)+2+\textcorrection}%
1674 }%
1675 \unles\ifhmode
1676 \leavevmode\noindent
1677 \fi
1678 \bgroup\edef\x{\egroup\noexpand\wrapfloat{\WF@caption@label}[\NWF@wli]%
1679 {\textplacement}{\the\insertwidth}}\x
1680 \box\NWF@box
1681 \endwrapfloat
1682 \ignorespaces
1683 }
1684 }
1685
1686 % \end{macrocode}
1687 %
1688 % The opening command of the \Env{wrapfloat} environment
1689 % receives the mandatory and optional arguments plus the name of
1690 % the particular object to be wrapped. It is used to define the
1691 % prefix label of the caption number in case that the object is
1692 % described with a caption. The optional star is not explicit,
1693 % because it is going to be read by the \cs{WF@wr} macro.
1694 %
1695 % The closing command of \Env{wrapfloat} performs most of
1696 % the work necessary to wrap the box that contains the object
1697 % to be wrapped, but certain tasks are demanded to other service
1698 % macros.
1699 %
1700 % It is possible to set the width of the box if the \meta{width}
1701 % parameter is specified; otherwise it closes the \cs{hbox} that
1702 % was used; then it closes the main vertical box \cs{WF@box}.
1703 % After executing \cs{WF@floatstyhook}, necessary when package
1704 % \pack{float.sty} has been used, it saves the \meta{overhang}
1705 % value to be used when wrapping is actually performed; then it
1706 % verifies if the box height is too high to fit, or is too
1707 % short; possibly re-boxes this box in the same box register
1708 % with a negative initial vertical skip that raises the box
1709 % contents.
1710 %
1711 % Now comes the new actual definition of the fundamental
1712 % environment \Env{wrapfloat}; compared to the original
1713 % Arseneau's definition it is much longer, but it contains the
1714 % code that Arseneau, who used the \LaTeXe language, had to
1715 % split it in several macros in order to handle the multitude of
1716 % interspersed mandatory and optional arguments.
1717 %
1718 % The main function of this environment is to handle the box
1719 % that contains the figure, or the table, or the framed text, or
1720 % what else, so that the inserted box is preceded and followed
1721 % by suitable vertical spaces, and it is possible to compute the
1722 % number of lines to be indented; often this computed number is
1723 % correct; but in certain cases, when the code is used too close
1724 % or within prohibited wrapping text, such number might need to
1725 % be corrected. As it can be seen the optional star is not among
1726 % the argument descriptors of the opening commands; it will be
1727 % the following macro \cs{WR@wr} responsible of taking care of
1728 % the list of arguments and see if a star has been specified but
1729 % is still in the input flow.
1730 %
1731 % In order to handle any kind of wrapped object, this
1732 % environment first argument is the \meta{caption label}. It may
1733 % remain blank; but for wrapping figures or tables their
1734 % respective definitions specify the name of the floating object
1735 % they belong to; it is necessary that there exists a floating
1736 % environment with the same name of the wrapped object, even
1737 % when its wrapping environment is not specified with a floating
1738 % \meta{location} argument.
1739 %
1740 % \begin{macrocode}
1741 \NewDocumentEnvironment{wrapfloat}{m o m o G{\z@}}%
1742 {% open environment code
1743 \def\@captype{#1}\WF@wr[#2]{#3}[#4]{#5}%
1744 }{% close environment code
1745 \ifdim\hsize>\z@
1746 \par\hrule\@width\hsize\@height\z@ % force width with
1747 % invisible rule
1748 \else
1749
1750 \egroup \box\z@ % or close hbox
1751 \fi
1752 \egroup % close the vtop box; its width now is known
1753 \WF@floatstyhook % support for float.sty
1754 \def\width{\wd\WF@box}%
1755 \setlength\wrapoverhang{\WF@ovh}%
1756 \xdef\WF@ovh{\the\wrapoverhang}% save until wrapping
1757 \ifdim\ht\WF@box>\topskip \ht\WF@box\z@ \fi% too high,
1758 % set flag
1759 \ifdim\ht\WF@box<.5\p@ % too short, move up
1760 \global\setbox\WF@box\vtop{\vskip-1.4ex\unvbox\WF@box}%
1761 \fi
1762 \global\WF@size=% compute total box hight with \fpeval
1763 \fpeval{\ht\WF@box+\dp\WF@box+1.5\baselineskip+\tw@\intextsep}\p@
1764 \aftergroup\WF@startfloating% use even when not floating
1765 \unless\ifWF@float
1766 \ifhmode
1767 {\unskip \parfillskip\z@skip \par \vskip-\parskip}%
1768 \aftergroup\noindent
1769 \fi
1770 \fi
1771 \global\@ignoretrue
1772 }
1773
1774 % \end{macrocode}
1775 %
1776 % The working macro \cs{WF@wr} is defined with the \LaTeXiii
1777 % language; it grabs all the optional and mandatory arguments
1778 % in a single step, contrary to \LaTeXe that requires to split
1779 % the various steps in separate macros. In the definition code
1780 % we use also some commands, such as \cs{unless}, originally
1781 % defined by the \eTeX typesetting program extensions, that have
1782 % been included in the \pdfLaTeX, \XeLaTeX and \LuaLaTeX kernels
1783 % several years ago.
1784 %
1785 % Notice that the optional first (optional) argument, that
1786 % represents the number of indented lines or their correction
1787 % number, is saved into the macro \cs{WF@wli}, but if this
1788 % argument is not specified, \cs{WF@wli} is assigned the value
1789 % zero. The same happens for the \meta{overhang} optional
1790 % argument.
1791 %
1792 % After these adjustments, the software computes the box total
1793 % height plus some fixed amounts needed mostly to set the
1794 % wrapped material below the wrapping text first line. Here is
1795 % where the \LaTeXiii \cs{fpeval} computing function comes into
1796 % play so as to assign such height to \cs{WF@size}. Afterwards
1797 % some unusual macros are executed; they were devised by
1798 % Arseneau to deal with possibly floating wrapped objects. The
1799 % optional star is not accepted by this macro; if the user
1800 % specified it, it is still in the input flow; notice that the
1801 % \Env{wraptext} environment does not accept the optional star;
1802 % if the user indadvertedly specifies it for this environment,
1803 % a star appears at the beginning of the wrapped text with
1804 % version~4; with versions~5 to~7 the asterisk produces a
1805 % warning that remind users that this environment does not use
1806 % any optional star. In all three versions, in facts, the first
1807 % optional parameter is always interpreted as the \meta{line
1808 % number correction}.
1809 %
1810 % The braced \meta{width} fourth parameter (actually a
1811 % \textit{braced optional parameter}) may be specified to be
1812 % \texttt{0pt}; in any case \texttt{0pt} is the default
1813 % parameter value; if so, the object is treated at its natural
1814 % width, by boxing it into an hbox and using this box width as
1815 % the working width; of course this works only with
1816 % \Env{wrapfigure} and \Env{wraptable}, because what is being
1817 % wrapped has its own natural width; with text the width is the
1818 % default setting made with the \emph{braced optional argument}
1819 % described with the \texttt{G} descriptor.
1820 % \begin{macrocode}
1821 \NewDocumentCommand\WF@wr{o m o m s}{%
1822 \xdef\WF@wfname{wrap\@captype\space}%
1823 \unless\ifvoid\WF@box
1824 \WFclear \WF@collision
1825 \fi
1826 \xdef\WF@place{\string`\@car#2r\@nil}%
1827 \ifnum\lccode\WF@place=\WF@place
1828 \global\WF@floatfalse
1829 \else
1830 \global\WF@floattrue
1831 \fi
1832 \ifx\parshape\WF@fudgeparshape
1833 \unless\ifWF@float\WF@collision\fi
1834 \else
1835 \ifx\par\@@par
1836 \ifnum\@@parshape>\z@\WF@conflict\fi
1837 \else
1838 \WF@conflict
1839 \fi
1840 \fi
1841 \IfValueTF{#1}% save optional line number or correction
1842 {\gdef\WF@wli{#1}}%
1843 {\gdef\WF@wli{0}}%
1844 %
1845 \IfValueTF{#3}% save optional overhang
1846 {\gdef\WF@ovh{#3}}%
1847 {\gdef\WF@ovh{\z@}}%
1848 %
1849 \global\setbox\WF@box\vtop\bgroup
1850 \setlength\hsize{#4}% set width
1851 \ifdim\hsize>\z@
1852 \@parboxrestore
1853 \else
1854 \setbox\z@\hbox\bgroup
1855 \let\wf@@caption\caption
1856 \let\caption\wf@caption
1857 \ignorespaces
1858 \fi
1859 \IfBooleanTF{#5}% if star, set the numerical switch
1860 {\global\WF@correctlines@switch=\@ne}%
1861 {\global\WF@correctlines@switch=\z@}%
1862
1863 }
1864 % \end{macrocode}
1865 %
1866 % At this point the main box \cs{WF@box} is opened in order to
1867 % store the object to be wrapped; with this box height the
1868 % software is going to compute the number of lines to be
1869 % indented, unless such a number has been specified and no star
1870 % was added to the input parameters.
1871 %
1872 % Also the \amb{wraptext} environment uses a box to collect the
1873 % framed text; the name of this second box must be different
1874 % from \cs{WF@box} otherwise interference of the various tasks
1875 % produces unrecoverable errors. This is why at the beginning of
1876 % this package we defined two different boxes: \cs{WF@box} and
1877 % \cs{NWF@box}.
1878 %
1879 % The trick of creating an alias for the \cs{caption} macro is
1880 % used by Arseneau to redefine one of the two macros according
1881 % to certain conditions. Here \cs{wf@caption} is actually
1882 % redefined if the \meta{width} parameter has been specified or
1883 % has been computed.
1884 % \begin{macrocode}
1885 \def\wf@caption{\relax% redefine \wf@caption if \hsize is zero
1886 \ifdim\hsize>\z@
1887 \let\caption\wf@@caption
1888 \else
1889 \unskip \egroup \hsize\wd\z@
1890 \@parboxrestore \box\z@% export \box0
1891 \fi
1892 \caption
1893 }
1894
1895 % \end{macrocode}
1896 %
1897 % One of the following unusual macros were introduced by
1898 % Arseneau to deal with paragraph parameters and possibly to
1899 % float the object to be wrapped.
1900 % \begin{macrocode}
1901 \def\WF@startfloating{%
1902 \WF@everypar\expandafter{\the\everypar}\let\everypar\WF@everypar
1903 \WF@@everypar{\ifvoid\WF@box\else\WF@floathand\fi \the\everypar
1904 \WF@wraphand
1905 }}
1906
1907 % \end{macrocode}
1908 % The following macro is for floating wrapping environments.
1909 % \begin{macrocode}
1910 \def\WF@floathand{%
1911 \ifx\parshape\WF@fudgeparshape
1912 \WF@fltmes
1913 \else
1914 \ifx\par\@@par
1915 \ifnum\@@parshape=\z@
1916 \ifdim\hangindent=\z@
1917 \setbox\z@\lastbox \begingroup
1918 \@@par \WF@@everypar{}\WF@putfigmaybe
1919 \endgroup % after this group start wrapping
1920 \unless\ifvoid\z@ % replace indentation
1921 \box\z@
1922 \fi
1923 \else
1924 \WF@fltmes
1925 \fi
1926 \else
1927 \WF@fltmes
1928 \fi
1929 \else
1930 \WF@fltmes
1931 \fi
1932 \fi}
1933
1934 % \end{macrocode}
1935 %
1936 % On the contrary if there is enough space or if the wrapped
1937 % object cannot float, it gets output here.
1938 % \begin{macrocode}
1939 \def\WF@putfigmaybe{%
1940 \ifinner
1941 \vskip-\parskip \global\WF@floatfalse
1942 \let\pagetotal\maxdimen % kludge flag for "not top of page"
1943 \else % outer page
1944 {\advance\parskip\@tempdima\vskip-\parskip}% back up to base
1945 % line
1946 \penalty\interlinepenalty % update page parameters
1947 \@tempdimb\dimexpr\pagegoal - \pagetotal \relax% room left
1948 % on page
1949 \ifdim \@tempdimb<\z@ % page already full
1950 \global\WF@floatfalse
1951 \unless\ifdim-\@tempdimb>\pageshrink \pagebreak \fi
1952 \else
1953 \ifdim\WF@size>\@tempdimb% box does not fit in \@tempdimb
1954 \ifWF@float
1955 \dimen@ 0.5\baselineskip
1956 \else
1957 \dimen@ 2\baselineskip
1958 \fi
1959 \ifdim\pagestretch>\dimen@ \dimen@\pagestretch \fi
1960 \ifdim\pagefilstretch>\z@ \dimen@\@tempdimb \fi
1961 \ifdim\pagefillstretch>\z@ \dimen@\@tempdimb \fi
1962 \advance\dimen@ 0.5\baselineskip
1963 \ifdim\dimen@>\@tempdimb % stretch page contents
1964 \global\WF@floatfalse \pagebreak
1965 \fi
1966 \else % box fits in \@tempdimb
1967 \global\WF@floatfalse
1968 \fi
1969 \fi
1970 \vskip\@tempdima% return erased page depth
1971 \fi
1972 \noindent
1973 \ifWF@float
1974 \WF@fltmes
1975 \else % place insertion here
1976 \WF@info{Put \WF@wfname here:}%
1977 {\ifodd
1978 \if@twoside\c@page\else\@ne\fi% assign l/r to i/o placement
1979 \lccode`i`l\lccode`o`r\else \lccode`i`r\lccode`o`l%
1980 \fi
1981 \xdef\WF@place{\the\lccode\lccode\WF@place}%
1982 }% twice to get only l or r
1983 \hbox to\z@{% llap o rlap depending on l or r;
1984 % determine effective width
1985 \@tempdima\wd\WF@box \@tempdimb\WF@ovh
1986 \advance\@tempdima-\@tempdimb \advance\@tempdima\columnsep
1987 \@tempdimb\hsize \advance\@tempdimb-\@tempdima
1988 \xdef\WF@adjlw{\the\@tempdima}%
1989 \ifnum `l=\WF@place % object on left
1990 \hss
1991 \def\@tempa{\kern\columnsep}% take right gap into action
1992 \else % object on right
1993 \@tempdima\z@ % no left indentation
1994 \kern\@tempdimb \kern\columnsep
1995 \def\@tempa{\hss}% object overlaps space to the right
1996 \fi
1997 \ifdim\@tempdimb<\hsize
1998 \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}%
1999 % indent.number and length
2000 \xdef\WF@adjtlm{\the\@tempdima}%
2001 \else
2002 \xdef\WF@wrapil{\z@ \the\hsize}%
2003 \xdef\WF@adjlw{\z@}\xdef\WF@adjtlm{\z@}%
2004 \fi
2005 \ifdim\pagetotal=\z@ % put object at top of page \thepage
2006 \global\advance\WF@size-\intextsep
2007 \else % put object in middle of the page
2008 \setbox\WF@box\hbox{\lower\intextsep\box\WF@box}%
2009 \fi
2010 \dp\WF@box\z@
2011 \box\WF@box
2012 \@tempa
2013 }% end \hbox to 0pt
2014 \aftergroup\WF@startwrapping
2015 \fi
2016 }
2017
2018 % \end{macrocode}
2019 %
2020 % Here comes the very important macro that counts the indented
2021 % wrapping lines, so that wrapping is correct; of course the
2022 % limitations of the \LaTeX processing (needed to ship out a
2023 % complete page) forbid to take into account the spaces inserted
2024 % between paragraphs and/or those inserted between entries of
2025 % various listings. The idiosyncrasies of this package arise
2026 % from the fact that this macro cannot preview actions that have
2027 % not yet taken place when this macro is executed.
2028 %
2029 % This macro counts the lines to be indented by rounding the
2030 % division of the box height by the current base line base skip.
2031 % Notice that \texttt{WF@wrappedlines} is the name of a \LaTeX
2032 % named counter, not of a \TeX numeric register; therefore
2033 % special \LaTeX commands, such as \cs{setcounter} or
2034 % \cs{value}, have to be used in order to set or access the
2035 % numerical value stored within the \TeX register associated to
2036 % the \LaTeX counter name.
2037 % \begin{macrocode}
2038 \def\WF@startwrapping{%
2039 \ifnum\WF@wli=\z@ % no number was specified
2040 \setcounter{WF@wrappedlines}%
2041 {\fpeval{round(\WF@size/\baselineskip,0)}}%
2042 \xdef\WF@wli{\value{WF@wrappedlines}}%
2043 \else
2044 \ifnum\WF@correctlines@switch>\z@ % line number correction
2045 \setcounter{WF@wrappedlines}
2046 {\fpeval{round((\WF@size)/\baselineskip,0)+\WF@wli}}%
2047 \xdef\WF@wli{\the\c@WF@wrappedlines}%
2048 \else
2049 \setcounter{WF@wrappedlines}{\WF@wli}% absolute number
2050 % of lines
2051 \stepcounter{WF@wrappedlines}%
2052 \fi
2053 \fi
2054 \ifnum\c@WF@wrappedlines>\@ne % fine tuning
2055 \let\parshape\WF@fudgeparshape \let\WF@pspars\@empty \let\WF@@par\par
2056 \def\@setpar##1{\def\WF@@par{##1}}\def\par{\@par}\let\@par\WF@mypar
2057 \xdef\WF@restoretol{\tolerance\the\tolerance}\tolerance9999\relax
2058 \advance\linewidth-\WF@adjlw \advance\@totalleftmargin\WF@adjtlm
2059 \fi
2060 }
2061
2062 % \end{macrocode}
2063 %
2064 % The next macro is the one that actually indents the wrapping
2065 % text lines and keeps track of the number of such processed
2066 % lines. It can work on more than a single paragraph. It resorts
2067 % to service macros that reiterate as long as the number of
2068 % indented lines is lower than the computed number of lines.
2069 % Possibly this process could be defined by means od the
2070 % \texttt{dowhile} or \texttt{whiledo} \LaTeXiii functions.
2071 % By now we did not afford this task, because first we would
2072 % like to see if the overall software is reliable.
2073 % \begin{macrocode}
2074 \def\WF@wraphand{% for indenting one or more paragraphs
2075 \ifnum\c@WF@wrappedlines<\tw@
2076 \WF@finale
2077 \else \begingroup % create a parshape command
2078 \@tempcnta\@ne \let\WF@wrapil\relax \gdef\WF@ps{}%
2079 \@whilenum
2080 \@tempcnta<\c@WF@wrappedlines\do{% repeated indentation
2081 \xdef\WF@ps{\WF@ps\WF@wrapil}\advance\@tempcnta\@ne
2082 }%
2083 \endgroup
2084 \ifx\WF@pspars\@empty
2085 \@@parshape\c@WF@wrappedlines \WF@ps \WF@noil
2086 \else %use external `parshape' values to modify my parshape
2087 \WF@modps
2088 \fi
2089 \fi
2090 }
2091
2092 % \end{macrocode}
2093 %
2094 % This macro resets the paragraph properties and terminates the
2095 % wrapping job.
2096 % \begin{macrocode}
2097 \def\WF@mypar{\relax
2098 \WF@@par
2099 \ifnum\@@parshape=\z@
2100 \let\WF@pspars\@empty % reset parshape
2101 \fi
2102 \global\advance\c@WF@wrappedlines-\prevgraf \prevgraf\z@
2103 \ifnum\c@WF@wrappedlines<\tw@
2104 \WF@finale
2105 \fi
2106 }
2107
2108 % \end{macrocode}
2109 %
2110 % These macros modify the paragraph settings.
2111 % \begin{macrocode}
2112 \def\WF@modps{\begingroup
2113 \afterassignment\@tempdimb \@tempdima\WF@pspars%
2114 % a=indent.num; b=width
2115 \advance\@tempdima-\WF@adjtlm \advance\@tempdimb\WF@adjlw
2116 \let\WF@wrapil\WF@pspars
2117 \edef\@tempb{\@@parshape\c@WF@wrappedlines
2118 \WF@ps \the\@tempdima \the\@tempdimb}%
2119 \expandafter\endgroup\@tempb
2120 }
2121
2122 \let\@@setpar\@setpar
2123 \def\WF@noil{\z@ \hsize}
2124 \let\WF@pspars\@empty
2125
2126 \def\WF@fudgeparshape{\relax
2127 \ifnum\c@WF@wrappedlines<\tw@
2128 \WF@finale
2129 \else
2130 \afterassignment\WF@fudgeparshapee \fam
2131 \fi
2132 }
2133
2134 \def\WF@fudgeparshapee{%
2135 \ifnum\fam=\@ne \expandafter
2136 \WF@parshapeee
2137 \else
2138 \WF@conflict \@@parshape\fam
2139 \fi
2140 }
2141
2142 \def\WF@parshapeee#1#2{%
2143 \begingroup\delimitershortfall#1%
2144 \nulldelimiterspace#2% \advance \nulldelimiterspace by
2145 % \WF@adjlw
2146 \edef\@tempa{\def\noexpand\WF@pspars{%
2147 \the\delimitershortfall \the\nulldelimiterspace}}%
2148 \expandafter\endgroup\@tempa \WF@wraphand
2149 }
2150
2151 % \end{macrocode}
2152 %
2153 % The following macro is the one that actually ends the single
2154 % wrapping job.
2155 % \begin{macrocode}
2156 \def\WF@finale{%
2157 \ifx\parshape\WF@fudgeparshape
2158 \WF@restoretol \let\@setpar\@@setpar \let\par\WF@@par
2159 \advance\linewidth\WF@adjlw \advance\@totalleftmargin-\WF@adjtlm
2160 \WF@info{Finish wrapping text}%
2161 \ifx\par\@@par
2162 \def\@par{\let\par\@@par\par}%
2163 \else
2164 \let\@par\WF@@par
2165 \fi
2166 \let\parshape\@@parshape
2167 \parshape=\ifx\WF@pspars\@empty
2168 \z@
2169 \else
2170 \@ne \WF@pspars
2171 \fi
2172 \fi
2173 \ifvoid\WF@box
2174 \ifx\everypar\WF@everypar
2175 \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
2176 \fi
2177 \fi
2178 }
2179
2180 % \end{macrocode}
2181 %
2182 % At the very end everything is restored, and the used boxes
2183 % are emptied.
2184 % \begin{macrocode}
2185 \newcommand{\WFclear}{\par
2186 \unless\ifvoid\WF@box
2187 \vskip\bigskipamount \box\WF@box
2188 \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
2189 \fi
2190 \global\c@WF@wrappedlines\z@ \WF@finale
2191 \global\WF@correctlines@switch\z@
2192 }
2193
2194 % \end{macrocode}
2195 %
2196 % The following code is one of those “dirty tricks” by which a
2197 % macro defined within a group is executed with the help of an
2198 %\cs{expandafter} command that bypasses an \cs{endgroup}; by so
2199 % doing, after execution nothing local to the group remains in
2200 % memory.
2201 % \begin{macrocode}
2202 \begingroup
2203 \toks0={\let\everypar\WF@@everypar
2204 \everypar\expandafter{\the\WF@everypar}%
2205 \let\parshape\@@parshape
2206 \let\@setpar\@@setpar
2207 }
2208 \toks1=\expandafter{\@arrayparboxrestore}%
2209 \toks2=\expandafter{\clearpage}%
2210 \edef\@tempa{%
2211 \def\noexpand\@arrayparboxrestore{\the\toks0 \the\toks1}%
2212 \def\noexpand\clearpage
2213 {\noexpand\protect\noexpand\WFclear \the\toks2}}%
2214 \expandafter\endgroup\@tempa
2215
2216 % \end{macrocode}
2217 %
2218 % Donald Arseneau classifies the following macro as the one
2219 % that “pampers the RevTeX's stupidity”.
2220 % \begin{macrocode}
2221 \@ifundefined{@capwidth}{\let\@capwidth\hsize}{}%
2222
2223 % \end{macrocode}
2224 %
2225 % This one, instead, issues a warning if a specific name
2226 % conflicts with another.
2227 % \begin{macrocode}
2228 \def\WF@conflict{\WF@warning
2229 {\WF@wfname used inside a conflicting environment}}%
2230
2231 % \end{macrocode}
2232 %
2233 % While this one issues a warning when a wrapping environment is
2234 % too close to another one.
2235 % \begin{macrocode}
2236 \def\WF@collision{\WF@warning{Collision between wrapping environments}}%
2237
2238 % \end{macrocode}
2239 %
2240 % And this one is when two wrapping environments are too close
2241 % to one another so that the second one is forced to move.
2242 % \begin{macrocode}
2243 \def\WF@fltmes{% message for floats
2244 \ifWF@float
2245 \WF@info{\WF@wfname floats}%
2246 \else
2247 \WF@warning{Stationary \WF@wfname forced to float}%
2248 \fi
2249 }
2250
2251 % \end{macrocode}
2252 %
2253 % These two aliases are just service macros for this package; in
2254 % particular, the second one is used to insert info of any kind
2255 % within a source file.
2256 % \begin{macrocode}
2257 \let\WF@warning\@warning
2258 \let\WF@info\@gobble
2259
2260 % \end{macrocode}
2261 %
2262 % Arseneau says that his \pack{wrapfig} package is already
2263 % compatible with package \pack{float.sty}, since, after
2264 % defining a new float \meta{foo}, it suffices to define the new
2265 % environment \Env{wrap\meta{foo}}. This fork version of his
2266 % package should do the same: it suffices to mimic the
2267 % definitions of environments \Env{wrapfigure} or
2268 % \Env{wraptable}. But as we saw with the \Env{wraptext}, the
2269 % above statement is not always true.
2270 %
2271 % Here there is some Arseneau's code that renders his
2272 % \pack{wrapfig} code compatible with \cs{newfloat} of class
2273 % \class{memoir}, and with \cs{newfloatlist} of package
2274 % \pack{ccaption}. We keep his code, but we did not test it with
2275 % this package.
2276 % \begin{macrocode}
2277 \let\WF@floatstyhook\relax
2278
2279 \@ifundefined{newfloat}{}{% \newfloat comes from somewhere
2280 % besides float.sty
2281 \@ifundefined{restylefloat}{%
2282 \@ifclassloaded{memoir}{%
2283 \toks@=\expandafter\expandafter\expandafter
2284 {\csname\string\newfloat\endcsname [{#1}]{#2}{#3}{#4}%
2285 \newenvironment{wrap#2}{\wrapfloat{#2}}{\endwrapfloat}%
2286 }% Mmmm; this might be wrong. Not tested
2287 \edef\@tempa{\def\expandafter\noexpand\csname\string\newfloat
2288 \endcsname[##1]##2##3##4{\the\toks@}}%
2289 \@tempa
2290 }% end memoir support
2291 {}% other origins of \newfloat here?
2292 }{% float.sty handler. Ops: Two versions for
2293 % different versions
2294 % Changing \floatstyle or \restylefloat changes also \newfloat.
2295 \@ifundefined{float@restyle}%
2296 {% older float.sty
2297 \toks@=\expandafter{\restylefloat{##1}% env. might be
2298 % undefined
2299 \@namedef{wrap#1}{%
2300 \def\@captype{#1}\@nameuse{fst@#1}%
2301 \def\WF@floatstyhook{\let\@currbox\WF@box
2302 \columnwidth\wd\WF@box
2303 \global\setbox\WF@box\float@makebox}%
2304 \@ifnextchar[\WF@wr{\WF@wr[]}}%
2305 \expandafter\let\csname endwrap#1\endcsname \endwrapfigure
2306 }%
2307 \edef\@tempa{\def\noexpand\restylefloat##1{\the\toks@}}%
2308 }{% newer float.sty: uses \float@restyle, and \float@makebox
2309 % takes width arg
2310 \toks@=\expandafter{\float@restyle{#1}% env. might be
2311 % undefined
2312 \@namedef{wrap#1}{\def\@captype{#1}\@nameuse{fst@#1}%
2313 \def\WF@floatstyhook{\let\@currbox\WF@box
2314 \global\setbox\WF@box\float@makebox{\wd\WF@box}}%
2315 \@ifnextchar[\WF@wr{\WF@wr[]}}%
2316 \expandafter\let\csname endwrap#1\endcsname
2317 \endwrapfigure
2318 }%
2319 \edef\@tempa{\def\noexpand\float@restyle##1{\the\toks@}}%
2320 }%
2321 \@tempa % perform redefinitions
2322 %
2323 }% end float.sty handler
2324 }% end redefinitions of \newfloat
2325
2326 \ifcsname newfloatlist\endcsname% support ccaption.sty
2327 \toks@=\expandafter\expandafter\expandafter
2328 {\csname\string\newfloatlist\endcsname [{#1}]{#2}{#3}{#4}{#5}%
2329 \@namedef{wrap#2}{\wrapfloat{#2}}%
2330 \expandafter\let\csname endwrap#2\endcsname \endwrapfloat
2331 }%
2332 \edef\@tempa{%
2333 \def\expandafter\noexpand\csname\string\newfloatlist\endcsname
2334 [##1]##2##3##4##5{\the\toks@}}%
2335 \@tempa
2336 \fi
2337
2338 \ifcsdef{amsTextText}{\let\text\amsTextText}{}
2339
2340 % \end{macrocode}
2341 %
2342 %\iffalse
2343 %</package>
2344 %\fi
2345 % \Finale
2346 %
2347 %^^A \endinput