Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2010, 2019, 2021 by Gonzalo Medina
4 %
5 % --------------------------------------------------------------------------
6 %
7 % This file may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in:
11 %
12 % http://www.latex-project.org/lppl.txt
13 %
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2003/12/01 or later.
16 %
17 % This work has the LPPL maintenance status `maintained'.
18 %
19 % The Current Maintainer of this work is Gonzalo Medina.
20 %
21 % This work consists of the files fancypar.dtx and fancypar.ins,
22 % and the derived files fancypar.sty and fancypar.pdf.
23 %
24 % \fi
25 %
26 % \iffalse
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \usepackage[english]{babel}
31 \usepackage{manfnt}
32 \usepackage{kpfonts}
33 \usepackage{caption}
34 \usepackage{array}
35 \usepackage{booktabs}
36 \usepackage[x11names]{xcolor}
37 \usepackage{ragged2e}
38 \usepackage{ntheorem}
39 \usepackage{framed}
40 \usepackage{ifpdf}
41 \usepackage{fancypar}
42 \usepackage{hypdoc}
43 \ifpdf
44 \usepackage{hypdestopt}
45 \fi
46 \hypersetup{pdfkeywords={LaTeX, package, fancypar},%
47 pdfstartpage={},pdfstartview={},breaklinks=true,%
48 linktocpage}
49 \usepackage{titletoc}
50
51 \titlecontents*{section}[0pt]
52 {\itshape}{}{}
53 {, \thecontentspage}[\ --\ ][.]
54 \titlecontents*{subsection}[0pt]
55 {\upshape\small}{}{}
56 {, \thecontentspage}[ (][. ][)]
57 \setcounter{tocdepth}{2}
58
59 \newcommand\colorsample[1]{%
60 \raisebox{1.5pt}{\colorbox{#1}{\hphantom{e}\vphantom{e}}}%
61 }
62
63 \makeatletter
64 \renewtheoremstyle{margin}%
65 {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]}
66 {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]}
67 \makeatother
68
69 \theoremstyle{margin}
70 \newtheorem{exam}{Example}
71
72 \newenvironment{mycode}
73 {\begin{shaded}\ttfamily}
74 {\end{shaded}}
75
76 \renewenvironment{shaded}{%
77 \def\FrameCommand{\FrameRestore\fboxsep=\FrameSep\colorbox{Honeydew2}}%
78 \MakeFramed {\FrameRestore}}%
79 {\endMakeFramed}
80
81 \newcommand\testtext{But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.}
82
83 \newcommand*\myref[1]{\ref{#1}, page~\pageref{#1}}
84
85 \newcommand\MarNote[1]{\marginpar{\RaggedLeft\textcolor{blue}{#1}}}
86 \newcommand*\package[1]{{\upshape\mdseries\sffamily #1}}
87
88 \setlength\parindent{0pt}
89
90 \setcounter{tocdepth}{4}
91
92 \EnableCrossrefs
93 \CodelineIndex
94 \RecordChanges
95
96 \begin{document}
97 \DocInput{fancypar.dtx}
98 \end{document}
99 %</driver>
100 % \fi
101 %
102 % \CharacterTable
103 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
104 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
105 % Digits \0\1\2\3\4\5\6\7\8\9
106 % Exclamation \! Double quote \" Hash (number) \#
107 % Dollar \$ Percent \% Ampersand \&
108 % Acute accent \' Left paren \( Right paren \)
109 % Asterisk \* Plus \+ Comma \,
110 % Minus \- Point \. Solidus \/
111 % Colon \: Semicolon \; Less than \<
112 % Equals \= Greater than \> Question mark \?
113 % Commercial at \@ Left bracket \[ Backslash \\
114 % Right bracket \] Circumflex \^ Underscore \_
115 % Grave accent \` Left brace \{ Vertical bar \|
116 % Right brace \} Tilde \~}
117 %
118 % \changes{v 1.1}{2010/04/25}{First revision}
119 % \changes{v 1.2}{2019/01/18}{Second revision}
120 % \changes{v 1.3}{2021/04/17}{Third revision}
121 %
122 % \GetFileInfo{fancypar.sty}
123 %
124 % \title{Fancy paragraph designs with the \package{fancypar} package\\
125 % {\footnotesize\fileversion , dated \filedate.}}
126 % \author{Gonzalo Medina\\%
127 % Universidad Nacional de Colombia -- Sede Manizales\\%
128 % Departamento de Matem\'aticas y Estad\'istica\\
129 % \texttt{[email protected]}}
130 %
131 % \maketitle
132 %
133 % \begin{abstract}
134 % \noindent This package offers five predefined decorative styles for text
135 % paragraphs of a document; the user can easily control the styles' attributes using the
136 % key-value mechanism. The package also allows the creation of new fancy designs.
137 % \end{abstract}
138 %
139 % \tableofcontents
140 %
141 % \section{Introduction}
142 % The \package{fancypar} package exploits the ``dissecting paragraphs with |\lastbox|"
143 % technique explained in Section 5.9.6 of Victor Eijkhout's
144 % \TeX\ by Topic (\cite{eijk}) to provide five predefined
145 % and easily customizable fancy paragraph styles. New designs can also be
146 % easily defined.\par\medskip
147 %
148 % \MarkedPar[position=left,mark=\color{blue}\manerrarrow]{The five commands were
149 % designed for \emph{text} paragraphs, so the mandatory argument of the five main
150 % commands described in Section~\myref{sec:options} cannot contain, for example,
151 % displayed math. By the way, this
152 % paragraph was typeset using one of the predefined styles offered by this
153 % package.}\par\medskip
154 %
155 % The author will gladly receive suggestions, comments and bug reports.
156 %
157 % \section{User Interface}
158 % Simply load this package in the preamble of a document (i.e.~the part of your
159 % document between |\documentclass| and |\begin{document}|) in the
160 % standard way:
161 % \begin{mycode}
162 % |\usepackage{fancypar}|
163 % \end{mycode}
164 % This will make available the five predefined styles, through the commands
165 % |\NotebookPar|, |\ZebraPar|, |\DashedPar|, |\MarkedPar| and |\UnderlinedPar|, described
166 % in Section~\myref{sec:options}.\par\medskip
167 %
168 % \MarkedPar[position=left,mark=\color{blue}\manerrarrow]{The \package{fancypar}
169 % package internally loads the \package{xcolor} package (\cite{kern}) without
170 % package options. If \package{xcolor} needs to be loaded with some options in a
171 % document, then \package{fancypar} must be loaded \emph{after} \package{xcolor}
172 % to prevent a clash.}
173 %
174 % \subsection{Package options}
175 % The \package{fancypar} package can also be loaded declaring some package options:
176 % \begin{mycode}
177 % |\usepackage[|\emph{options}|]{fancypar}|
178 % \end{mycode}
179 % Here (and in what follows) \emph{options} represents a comma-separated list of
180 % \emph{key=value} pairs\footnote{This feature was implemented using the
181 % \package{xkeyval} package (\cite{adri}).}, controlling some attributes of the
182 % predefined styles. The available options are described in Section~\myref{sec:options}
183 % (a summary with the default values is shown in Table~\myref{tab:options}).
184 % \par\medskip
185 %
186 % \DescribeMacro{\fancyparsetup}
187 % Additionally, for a later change of options, the \package{fancypar} package offers the
188 % command |\fancyparsetup|:
189 % \begin{mycode}
190 % |\fancyparsetup{|\emph{options}|}|
191 % \end{mycode}
192 % So, for example,
193 % \begin{mycode}
194 % |\usepackage[colorone=blue!20,colortwo=red!20]{fancypar}|
195 % \end{mycode}
196 % and
197 % \begin{mycode}
198 % |\usepackage{fancypar}|\\
199 % |\fancyparsetup{colorone=blue!20,colortwo=red!20}|
200 % \end{mycode}
201 % will produce the same result. The advantage of |\fancyparsetup| is that it can be used
202 % not only in the preamble but on the body of the document, as many times as required.
203 % Even more control can be obtained using the optional
204 % argument for the commands |\NotebookPar|, |\ZebraPar|, |\DashedPar|,
205 % |\MarkedPar|, and |\UnderlinedPar|.\par\medskip
206 %
207 % \section{Predefined styles}\label{sec:options}
208 % Each of the commands |\NotebookPar|, |\ZebraPar|, |\DashedPar|, |\MarkedPar|, and
209 % |\UnderlinedPar| described in this section has one
210 % mandatory argument: the \emph{text} paragraph to which the style will be applied to.
211 % As mentioned above, each style has some predefined settings which can be changed
212 % by using the corresponding options in either the |\usepackage| or |\fancyparsetup|
213 % commands or individually, by using the optional argument of the corresponding
214 % command.\par\medskip
215 %
216 % Below is an illustration of the look of the predefined styles, using some placeholder
217 % text (see Section~\myref{sec:examples}).\par\medskip
218 %
219 % \phantomsection\label{exa:outpredefined}
220 % \textit{The notebook style:}
221 % \NotebookPar{\testtext}
222 % \textit{The zebra style:}
223 % \ZebraPar{\testtext}
224 % \textit{The marked style:}
225 % \MarkedPar{\testtext}
226 % \textit{The dashed style:}
227 % \DashedPar{\testtext}
228 % \textit{The underlined style:}
229 % \UnderlinedPar{\testtext}
230 %
231 % \subsection{The notebook style}
232 %
233 % \DescribeMacro{\NotebookPar}
234 % This command will present the affected paragraph as if it was written in a notebook.
235 % Using the \package{TikZ} package (\cite{tant}), a spiral is added by default to
236 % the notebook (the spiral can be activated/deactivated using the |spiral| option). The
237 % options for this command are\par\medskip
238 %
239 % \begin{tabular}{rl}
240 % |linecolor=|\meta{color} & Color of the notebook's lines.\\
241 % |intercolor=|\meta{color} & Color of the rule between lines.\\
242 % |textcolor=|\meta{color} & Color of the text.\\
243 % |spiralcolor=|\meta{color} & Color of the spiral.\\
244 % |interheight=|\meta{length} & Height of the rule used between consecutive lines.\\
245 % |spiral=|\meta{true$\,\mid\,$false} & Activate/deactivate the spiral.\\
246 % |nbtextwidth=|\meta{length} & Text width inside the notebook (only affects the text).
247 % \end{tabular}\par\medskip
248 %
249 % The syntax is
250 % \begin{mycode}
251 % |\NotebookPar[|\emph{options}|]{|\meta{text paragraph}|}|
252 % \end{mycode}
253 %
254 % \subsection{The zebra-like style}
255 %
256 % \DescribeMacro{\ZebraPar}
257 % This command will color every line of the affected paragraph using a two-color
258 % (zebra-like) pattern. The options for this command are\par\medskip
259 %
260 % \begin{tabular}{rl}
261 % |colorone=|\meta{color} & Background color of the odd-numbered lines.\\
262 % |colortwo=|\meta{color} & Background color of the even-numbered lines.\\
263 % |textcolorone=|\meta{color} & Color of the text in the odd-numbered lines.\\
264 % |textcolortwo=|\meta{color} & Color of the text in the even-numbered lines.
265 % \end{tabular}\par\medskip
266 %
267 % The syntax is
268 % \begin{mycode}
269 % |\ZebraPar[|\emph{options}|]{|\meta{text paragraph}|}|
270 % \end{mycode}
271 %
272 % \DescribeMacro{fancycolor}
273 % \DescribeMacro{\FancyZColor}
274 % \DescribeMacro{\FancyZTextColor}
275 % Internally, the counter |fancycolor| is used to alternate colors for the odd and
276 % even-numbered lines, by redefining the command |\FancyZColor|. A little variation
277 % allows to achieve more sophisticated patterns with more than two alternating colors
278 % (see Example \myref{exa:zebrathree}). By an appropriate redefinition of the
279 % |\FancyZTextColor|, some interesting patterns for the color of the text could also be
280 % achieved.
281 %
282 % \subsection{The dashed paragraph}
283 %
284 % \DescribeMacro{\DashedPar}
285 % This command uses the |\xleaders| \TeX\ primitive to fill the textwidth with evenly
286 % spaced copies of a symbol (or ``dash"). The options for this command
287 % are\par\medskip
288 %
289 % \begin{tabular}{rl}
290 % |dashsymbol=|\meta{symbol} & Symbol to be used as ``dash".\\
291 % |dashcolor=|\meta{color} & Color for the symbol to be used as ``dash".\\
292 % |separation=|\meta{length} & Distance between two copies of the symbol.
293 % \end{tabular}\par\medskip
294 %
295 %The syntax is as follows:
296 % \begin{mycode}
297 % |\DashedPar[|\emph{options}|]{|\meta{text paragraph}|}|
298 % \end{mycode}
299 %
300 % \subsection{Marking every line}
301 %
302 % \DescribeMacro{\MarkedPar}
303 % This command will add a symbol (or ``mark") to every line in the affected paragraph;
304 % the options for this style are |mark=|\meta{symbol} (the symbol to be used as the
305 % mark) and |position=|\meta{right$\,\mid\,$left} (the position of the symbol). The
306 % syntax is as follows:
307 % \begin{mycode}
308 % |\MarkedPar[|\emph{options}|]{|\meta{text paragraph}|}|
309 % \end{mycode}
310 %
311 % \subsection{Underlining every line}
312 %
313 % \DescribeMacro{\UnderlinedPar}
314 % This command will underline every line of the affected paragraph. The only option for
315 % this command is |rulecolor|=\meta{color} which controls the color of the rule used.
316 % The syntax is
317 % \begin{mycode}
318 % |\UnderlinedPar[rulecolor=|\meta{color}|]{|\meta{text paragraph}|}|
319 % \end{mycode}
320 %
321 % \begin{table}[!ht]
322 % \centering
323 % \begin{tabular}{rl>{\small}l}\toprule
324 % Command/Style & Options & {\normalsize Default}\\\toprule
325 % |\NotebookPar| & |linecolor=|\meta{color} &|SlateGray3!80|
326 % \colorsample{SlateGray3!80}\\
327 % & |intercolor=|\meta{color} & |green!20| \colorsample{green!20}\\
328 % & |textcolor=|\meta{color} & |black|\\
329 % & |interheight=|\meta{length} & |1pt|\\
330 % & |spiralcolor=|\meta{color}&|LightYellow3| \colorsample{LightYellow3}\\
331 % & |spiral=|\meta{true$\,\mid\,$false} & true\\
332 % & |nbtextwidth=|\meta{length} & |\textindentright|\\\midrule
333 % |\ZebraPar| & |colorone=|\meta{color}&|SlateGray2| \colorsample{SlateGray2}\\
334 % & |colortwo=|\meta{color} & |DarkOliveGreen2!90!white!70|
335 % \colorsample{DarkOliveGreen2!90!white!70}\\
336 % & |textcolorone=|\meta{color} & |black|\\
337 % & |textcolortwo=|\meta{color} & |black|\\\midrule
338 % |\DashedPar| & |separation=|\meta{length} & |0.9em|\\
339 % & |dashsymbol=|\meta{symbol} & -- (en-dash: |--|)\\
340 % & |dashcolor=|\meta{color} & |blue!50|~\colorsample{blue!50}\\\bottomrule
341 % |\MarkedPar| & |mark=|\meta{symbol} & |$\surd$|
342 % $\surd$\\
343 % & |position=|\meta{right$\,\mid\,$left}& |right|\\\midrule
344 % |\UnderlinedPar| & |rulecolor=|\meta{color} & |DarkOliveGreen3|
345 % \colorsample{DarkOliveGreen3}\\\bottomrule
346 % \end{tabular}
347 % \captionsetup{width=.8\textwidth}
348 % \caption{summary of the predefined styles, their options and their default values.}
349 % \label{tab:options}
350 % \end{table}
351 % \changes{v 1.1}{2010/04/25}{default symbol for the mark option changed to
352 % $\surd$}
353 %
354 % \section{Defining new styles}
355 % \DescribeMacro{\FancyPreFormat}
356 % \DescribeMacro{\FancyFormat}
357 % \DescribeMacro{\AddFancyFormat}
358 % The creation of new paragraph designs involves the redefinition of the two commands
359 % |\FancyPreFormat| and |\FancyFormat|. The redefinition of the former will have effect
360 % just before the first line of the affected paragraph, whilst the redefinition of the latter
361 % will affect all lines of the paragraph; the redefinition of |\FancyFormat| \emph{must}
362 % contain the |\box\linebox| construct. After redefining those commands, the actual
363 % typesetting of the modified paragraph is done by invoking
364 % |\vbox{#1\par\AddFancyFormat}|. Schematically the definition of a new style
365 % (called, for example, |\MyStylePar|) should have the following aspect:
366 % \begin{mycode}
367 % |\newcommand\MyStylePar[1]{%|\\
368 % | \renewcommand\FancyPreFormat{%|\\
369 % | ...some commands...|\\
370 % | \renewcommand\FancyFormat{%|\\
371 % | ...some commands...|\\
372 % | \box\linebox%|\\
373 % | ...some commands...|\\
374 % | }|\\
375 % | ...some commands...|\\
376 % | \vbox{#1\par\AddFancyFormat}%|\\
377 % | ...some commands...|\\
378 % |}%|\\
379 % \end{mycode}
380 %
381 % For a complete illustration of a new style definition, see
382 % Example~\myref{exa:newstyle}.
383 %
384 % \section{Examples}\label{sec:examples}
385 % In the following examples we will use some placeholder text, taken from
386 % H.~Rackham's 1914 translation of Section 1.10.32 of ``de Finibus Bonorum et
387 % Malorum", written by Cicero:
388 % \begin{mycode}
389 % |\newcommand*\testtext{But I must explain to you how all this|\\
390 % | mistaken idea of denouncing pleasure and praising pain was born|\\
391 % | and I will give you a complete account of the system, and|\\
392 % | expound the actual teachings of the great explorer of the|\\
393 % | truth, the master-builder of human happiness. No one rejects,|\\
394 % | dislikes, or avoids pleasure itself, because it is pleasure, but|\\
395 % | because those who do not know how to pursue pleasure rationally|\\
396 % | encounter consequences that are extremely painful.}|
397 % \end{mycode}
398 %
399 % Each example includes the complete compilable code (after addition of the above
400 % definition of the |\testtext| command) and its result.
401 %
402 % \begin{exam}\label{exa:predefined}
403 % The default predefined styles.
404 % \end{exam}
405 %
406 % \begin{mycode}
407 % |\documentclass{article}|\\
408 % |\usepackage[english]{babel}|\\
409 % |\usepackage{fancypar}|\\
410 %
411 % |\begin{document}|\\
412 % |\textit{The notebook style:}|\\
413 % |\NotebookPar{\testtext}|\\
414 % |\textit{The zebra style:}|\\
415 % |\ZebraPar{\testtext}|\\
416 % |\textit{The marked style:}|\\
417 % |\MarkedPar{\testtext}|\\
418 % |\textit{The dashed style:}|\\
419 % |\DashedPar{\testtext}|\\
420 % |\textit{The underlined style:}|\\
421 % |\UnderlinedPar{\testtext}|\\
422 % |\end{document}|
423 % \end{mycode}
424 %
425 % The output of this example is shown on Section~\myref{sec:options}.
426 %
427 % \begin{exam}
428 % Changing the predefined styles {\normalfont (via |\usepackage| and |\fancyparsetup|)}.
429 % \end{exam}
430 %
431 % \begin{mycode}
432 % |\documentclass{article}|\\
433 % |\usepackage[english]{babel}|\\
434 % |\usepackage[x11names]{xcolor}|\\
435 % |\usepackage[spiral=false,linecolor=Chocolate3!100!white!80]%|\\
436 % | {fancypar}|\\
437 %
438 % |\begin{document}|\\
439 % |\NotebookPar{\testtext}|\\
440 % |\fancyparsetup{spiral=true,linecolor=LightGoldenrod3,|\\
441 % | interheight=2pt,intercolor=Cornsilk2}|\\
442 % |\NotebookPar{\testtext}|\\
443 % |\fancyparsetup{spiral=false,linecolor=OliveDrab4!100!white!90,|\\
444 % | interheight=0pt,textcolor=white}|\\
445 % |\NotebookPar{\testtext}|\\
446 % |\end{document}|
447 % \end{mycode}
448 % \fancyparsetup{spiral=false,linecolor=Chocolate3!100!white!80}
449 % \NotebookPar{\testtext}
450 %\fancyparsetup{spiral=true,linecolor=LightGoldenrod3,interheight=2pt,
451 % intercolor=Cornsilk2}
452 % \NotebookPar{\testtext}
453 % \fancyparsetup{spiral=false,linecolor=OliveDrab4!100!white!90,
454 % interheight=0pt,textcolor=white}
455 % \NotebookPar{\testtext}
456 %
457 % \begin{exam}
458 % Changing the predefined styles {\normalfont (via the optional argument of the
459 % commands)}.
460 % \end{exam}
461 %
462 % \begin{mycode}
463 % |\documentclass{article}|\\
464 % |\usepackage[english]{babel}|\\
465 % |\usepackage{fancypar}|\\
466 %
467 % |\begin{document}|\\
468 % |\MarkedPar{\testtext}|\\
469 % |\MarkedPar[mark=\ddag,position=left]{\testtext}|\\
470 % |\MarkedPar[mark=$\bullet$]{\testtext}|\\
471 % |\end{document}|
472 % \end{mycode}
473 % \MarkedPar{\testtext}
474 % \MarkedPar[mark=\ddag,position=left]{\testtext}
475 % \MarkedPar[mark=$\bullet$]{\testtext}
476 %
477 % \begin{exam}\label{exa:zebrathree}
478 % In this example a three color zebra pattern is used for the lines of the paragraph.
479 % \end{exam}
480 % \begin{mycode}
481 % |\documentclass{book}|\\
482 % |\usepackage[english]{babel}|\\
483 % |\usepackage[x11names]{xcolor}|\\
484 % |\usepackage{fancypar}|\\
485 % |\usepackage{intcalc}|\\
486 %
487 % |\renewcommand{\FancyZColor}{%|\\
488 % | \ifcase\intcalcMod{\value{fancycount}}{3}%|\\
489 % | OliveDrab4!100!white!90\or Chocolate3!100!white!80%|\\
490 % | \or LightGoldenrod3\fi|\\
491 % |}|\\
492 %
493 % |\begin{document}|\\
494 % |\ZebraPar{\testtext}|\\
495 % |\end{document}|
496 % \end{mycode}
497 %
498 % \renewcommand{\FancyZColor}{%
499 % \ifcase\intcalcMod{\value{fancycount}}{3}%
500 % OliveDrab4!100!white!90\or Chocolate3!100!white!80\or LightGoldenrod3\fi
501 % }
502 %
503 % \ZebraPar{\testtext}
504 %
505 % \begin{exam}\label{exa:newstyle}
506 % Definition of a new style. {\normalfont In this example we build a new style; the
507 % odd-numbered lines will be typeset in red and the even-numbered lines will be typeset
508 % in black.}
509 % \end{exam}
510 %
511 % \begin{mycode}
512 % |\documentclass{article}|\\
513 % |\usepackage[english]{babel}|\\
514 % |\usepackage{fancypar}|\\
515 %
516 % |\newcounter{mycount}|\\
517 %
518 % |\newcommand\MyStylePar[1]{%|\\
519 % | \renewcommand\FancyPreFormat{\setcounter{mycount}{0}}|\\
520 % | \renewcommand\FancyFormat{%|\\
521 % | \stepcounter{mycount}|\\
522 % | \ifodd\themycount%|\\
523 % | \noindent\textcolor{red}{\box\linebox}%|\\
524 % | \else%|\\
525 % | \box\linebox%|\\
526 % | \fi%|\\
527 % | }|\\
528 % | \par\medskip%|\\
529 % | \vbox{\noindent#1\par\AddFancyFormat}%|\\
530 % | \par\medskip%|\\
531 % |}%|\\
532 %
533 % |\begin{document}|\\
534 % |\MyStylePar{\testtext}|\\
535 % |\end{document}|
536 % \end{mycode}
537 % \newcounter{mycount}
538 %
539 % \newcommand\MyStylePar[1]{%
540 % \renewcommand\FancyPreFormat{\setcounter{mycount}{0}}
541 % \renewcommand\FancyFormat{%
542 % \stepcounter{mycount}
543 % \ifodd\themycount%
544 % \noindent\textcolor{red}{\box\linebox}%
545 % \else%
546 % \box\linebox%
547 % \fi%
548 % }
549 % \par\medskip%
550 % \vbox{#1\par\AddFancyFormat}%
551 % \par\medskip%
552 % }%
553 % \MyStylePar{\testtext}
554 %
555 % \begin{thebibliography}{9}
556 % \bibitem{adri} Hendri Adriaens, The \package{xkeyval} package.
557 % \href{http://www.ctan.org/pkg/xkeyval}{http://www.ctan.org/pkg/xkeyval}.
558 % \bibitem{eijk} Victor Eijkhout, \TeX\ by Topic.
559 % \href{http://www.eijkhout.net/tbt/}{http://www.eijkhout.net/tbt/}.
560 % \bibitem{kern} Dr. Uwe Kern, The \package{xcolor} package.
561 % \href{http://www.ctan.org/pkg/xcolor}{http://www.ctan.org/pkg/xcolor}.
562 % \bibitem{tant} Till Tantau, The \package{PGF/TikZ} package.
563 % \href{http://www.ctan.org/pkg/pgf}{http://www.ctan.org/pkg/pgf}.
564 % \end{thebibliography}
565 %
566 % \PrintChanges
567 %
568 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ ,\@ifpackageloaded}
569 % \DoNotIndex{\addtolength,\baselineskip,\begingroup,\begin,\bigskip,\box}
570 % \DoNotIndex{\color,\colorbox,\CurrentOption,\day,\def,\draw,\else,\end,\endgroup,\fi}
571 % \DoNotIndex{\fboxsep,\hbox,\hfill,\hrule,\hskip,\hss,\ifcase,\ifodd,\ifvoid,}
572 % \DoNotIndex{\let,\lastbox,\linebox,\llap,\makebox,\mbox,\medskip}
573 % \DoNotIndex{\newcommand,\newcounter,\newlength,\newsavebox,\node,\noindent}
574 % \DoNotIndex{\nr,\or,\par,\parindent,\parshape,\quad,\relax,\renewcommand}
575 % \DoNotIndex{\RequirePackage,\rightpointleft,\rlap,\setbox,\setcounter,\setkeys}
576 % \DoNotIndex{\setlength,\smallskip,\stepcounter,\textcolor,\textwidth,\tikz}
577 % \DoNotIndex{\unpenalty,\unskip,\usetikzlibrary,\val,\vbox,\vphantom,\vskip}
578 % \DoNotIndex{\NeedsTeXFormat,\ProvidesPackage,\xleaders}
579 %
580 % \StopEventually{\PrintIndex}
581 %
582 % \clearpage
583 % \section{Implementation}
584 %
585 % Standard identification:
586 % \begin{macrocode}
587 \NeedsTeXFormat{LaTeX2e}
588 \ProvidesPackage{fancypar}[2021/04/17 v1.3 fancy paragraphs]
589
590 % \end{macrocode}
591 %
592 % We load the necessary packages:
593 % \changes{v 1.1}{2010/04/25}{dingbat will not be used}
594 % \begin{macrocode}
595 \@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}
596 \@ifpackageloaded{tikz}{\usetikzlibrary{calc}}
597 {\RequirePackage{tikz}\usetikzlibrary{calc}}
598 \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}
599
600 % \end{macrocode}
601 %
602 % \begin{macro}{colorone}
603 % \begin{macro}{colortwo}
604 % \begin{macro}{textcolorone}
605 % \begin{macro}{textcolortwo}
606 % \begin{macro}{linecolor}
607 % \begin{macro}{intercolor}
608 % \begin{macro}{interheight}
609 % \begin{macro}{spiralcolor}
610 % \begin{macro}{textcolor}
611 % \begin{macro}{nbtextwidth}
612 % \begin{macro}{mark}
613 % \begin{macro}{rulecolor}
614 % \begin{macro}{separation}
615 % \begin{macro}{dashcolor}
616 % \begin{macro}{dashsymbol}
617 % The |xkeyval| package was used to handle the package options that will also be used
618 % later on. First, the options declaration (prefix: |FP|, family: |fancypar|).
619 % \begin{macrocode}
620 \DeclareOptionX[FP]<fancypar>{colorone}{\def\FancyZColorOne{#1}}
621 \DeclareOptionX[FP]<fancypar>{colortwo}{\def\FancyZColorTwo{#1}}
622 \DeclareOptionX[FP]<fancypar>{textcolorone}{\def\FancyZTextColorOne{#1}}
623 \DeclareOptionX[FP]<fancypar>{textcolortwo}{\def\FancyZTextColorTwo{#1}}
624 \DeclareOptionX[FP]<fancypar>{linecolor}{\def\FancyNlColor{#1}}
625 \DeclareOptionX[FP]<fancypar>{intercolor}{\def\FancyNilColor{#1}}
626 \DeclareOptionX[FP]<fancypar>{interheight}{\def\FancyNilHeight{#1}}
627 \DeclareOptionX[FP]<fancypar>{spiralcolor}{\def\FancyNSColor{#1}}
628 \DeclareOptionX[FP]<fancypar>{textcolor}{\def\FancyNTextColor{#1}}
629 \DeclareOptionX[FP]<fancypar>{nbtextwidth}{\def\FancyNTWidth{#1}}
630 \DeclareOptionX[FP]<fancypar>{mark}{\def\FancyMark{#1}}
631 \DeclareOptionX[FP]<fancypar>{rulecolor}{\def\FancyUColor{#1}}
632 \DeclareOptionX[FP]<fancypar>{separation}{\def\FancyDSeparation{#1}}
633 \DeclareOptionX[FP]<fancypar>{dashcolor}{\def\FancyDColor{#1}}
634 \DeclareOptionX[FP]<fancypar>{dashsymbol}{\def\FancyDSymbol{#1}}
635
636 % \end{macrocode}
637 % \end{macro}
638 % \end{macro}
639 % \end{macro}
640 % \end{macro}
641 % \end{macro}
642 % \end{macro}
643 % \end{macro}
644 % \end{macro}
645 % \end{macro}
646 % \end{macro}
647 % \end{macro}
648 % \end{macro}
649 % \end{macro}
650 % \end{macro}
651 % \end{macro}
652 %
653 % \begin{macro}{\textindent}
654 % \begin{macro}{\textindentright}
655 % The length |\textindent| will be used to control the indentation of the paragraph in the
656 % notebook style, depending on whether or not the spiral will be used. The length
657 % |\textindentright| controls the distance from the right indentation of the text;
658 % it is set to |\textwidth-2cm|.
659 % \begin{macrocode}
660 \newlength\textindent{}
661 \newlength\textindentright{}
662 \setlength\textindentright{\textwidth}
663 \addtolength\textindentright{-2cm}
664
665 % \end{macrocode}
666 % \end{macro}
667 % \end{macro}
668 %
669 % \begin{macro}{spiral}
670 % The boolean key |spiral| is used here to set |\textindent| appropriately and will be used
671 % in the definition of the notebook style to draw or not the spiral.
672 % \begin{macrocode}
673 \define@boolkey[FP]{fancypar}{spiral}{%
674 \ifFP@fancypar@spiral
675 \setlength\textindent{-2.6mm}%
676 \else
677 \setlength\textindent{3mm}%
678 \fi
679 }
680
681 % \end{macrocode}
682 % \end{macro}
683 %
684 % \begin{macro}{position}
685 % The choince-key |position| is used to specify the placement of the mark in the marked
686 % style.
687 % \begin{macrocode}
688 \define@choicekey+[FP]{fancypar}{position}[\val\nr]{left,right}{%
689 \ifcase\nr\relax
690 \def\FancyMarkPosition{\llap{\mbox{\FancyMark\quad}}\box\linebox}
691 \or
692 \def\FancyMarkPosition{\box\linebox\rlap{\mbox{\quad\FancyMark}}}
693 \fi
694 }{%
695 \PackageWarning{fancypar}{erroneous input ignored}%
696 }
697
698 % \end{macrocode}
699 % \end{macro}
700 %
701 % \begin{macrocode}
702 \DeclareOptionX*{\PackageWarning{fancypar}{‘\CurrentOption’ ignored}}
703
704 % \end{macrocode}
705 %
706 % Now we define some of the colors that will be used by default. We use the RGB system
707 % to define colors already present in the |x11names| family, just to avoid loading the
708 % |xcolor| package with options.
709 % \begin{macrocode}
710 \definecolor{zcolori}{RGB}{185,211,238}%SlateGray2
711 \definecolor{zcolorii}{RGB}{188,238,104}%DarkOliveGreen2
712 \definecolor{lcolor}{RGB}{159,182,205}%SlateGray3
713 \definecolor{scolor}{RGB}{205,205,180}%LightYellow3
714 \definecolor{rcolor}{RGB}{162,205,90}%DarkOliveGreen3
715
716 % \end{macrocode}
717 %
718 % We set the default value for the keys that were defined.
719 % \begin{macrocode}
720 \ExecuteOptionsX[FP]<fancypar>{%
721 colorone=zcolori,%
722 colortwo=zcolorii!90!white!70,%
723 textcolorone=black,%
724 textcolortwo=black,%
725 linecolor=lcolor!80,%
726 intercolor=green!20,%
727 interheight=1pt,%
728 spiralcolor=scolor,%
729 spiral=true,%
730 textcolor=black,%
731 nbtextwidth=\textindentright,%
732 mark=$\surd$,% \changes{v 1.1}{2010/04/25}{changed to $\surd$}
733 rulecolor=rcolor,%
734 position=right,%
735 dashcolor=blue!50,%
736 separation=0.9em,%
737 dashsymbol=--
738 }
739
740 % \end{macrocode}
741 %
742 % Now comes the processing of the keys and values which will be passed by the user to
743 % the package.
744 % \begin{macrocode}
745 \ProcessOptionsX[FP]<fancypar>
746
747 % \end{macrocode}
748 %
749 % \begin{macro}{\fancyparsetup}
750 % Definition of the command to control attributes in the preamble or at any point of the
751 % document.
752 % \begin{macrocode}
753 \DeclareRobustCommand*\fancyparsetup[1]{%
754 \setkeys[FP]{fancypar}{#1}
755 }
756
757 % \end{macrocode}
758 % \end{macro}
759 %
760 % \begin{macro}{\NotebookPar}
761 % Now, to the definition of the five predefined styles. |\NotebookPar| comes first.
762 % \changes{v 1.2}{2019/01/18}{NotebookPar admits more than one paragraph. Thanks to Frank Mittelbach}
763 % \begin{macrocode}
764 %%%% notebook %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 \newcommand\NotebookPar[2][]{%
766 \begingroup
767 \setkeys[FP]{fancypar}{#1}
768 \renewcommand\FancyPreFormat{\smallskip}
769 \renewcommand\FancyFormat{%
770 \hskip\textindent%
771 \tikz{%
772 \draw[draw=black,fill=white] (-1,-0.3) circle (3pt);%
773 \ifFP@fancypar@spiral
774 \draw[very thin,rotate=4,double=\FancyNSColor,%
775 double distance=1.5pt]%
776 (-1,-0.2) arc (40:-250:10pt and 2pt);%
777 \else\relax
778 \fi
779 }
780 \hskip4mm\vphantom{\strut}%
781 \textcolor{\FancyNTextColor}{\box\linebox}%
782 \color{\FancyNilColor}\hrule height\FancyNilHeight%
783 \smallskip%
784 }
785 \setlength\parindent{0pt}
786 \par\vskip\baselineskip
787 \noindent%
788 \begin{tikzpicture}[inner sep=-1.1pt]%
789 \setlength\fboxsep{0pt}%
790 \node (a) {\colorbox{\FancyNlColor}{%
791 \vbox{%
792 \vskip-0.5mm\parshape 1 0cm \FancyNTWidth%
793 \def\par{{\@@par}}% A trick that executes the real "par" = \@@par inside a group so that the parshape is restored. Thanks to Frank Mittelbach.
794 #2\@@par
795 \add@fancy@format%
796 }%
797 }%
798 } {};
799 \end{tikzpicture}
800 \par\bigskip
801 \endgroup
802 }
803
804 % \end{macrocode}
805 % \end{macro}
806 %
807 % \begin{macro}{fancycount}
808 % \begin{macro}{\FancyZColor}
809 % \begin{macro}{\FancyZTextColor}
810 % Next, we define the counter |fancycount|, and the command |\FancyZColor| used to
811 % produce the zebra-like pattern (by changing the color depending on whether the value
812 % of the counter is odd or even). We also define the command |\FancyZTextColor| to
813 % allow a similar definition for the color of the text lines. The counter and the commands
814 % can be used, or redefined by the user, in a \LaTeX\ document to produce more
815 % sophisticated zebra-like designs.
816 % \begin{macrocode}
817 \newcounter{fancycount}
818 \newcommand\FancyZColor{}
819 \renewcommand\FancyZColor{%alternate line colors
820 \ifodd\thefancycount %
821 \FancyZColorOne%
822 \else
823 \FancyZColorTwo%
824 \fi
825 }
826
827 \newcommand\FancyZTextColor{}
828 \renewcommand\FancyZTextColor{%alternate text colors
829 \ifodd\thefancycount %
830 \FancyZTextColorOne%
831 \else
832 \FancyZTextColorTwo%
833 \fi
834 }
835
836 % \end{macrocode}
837 % \end{macro}
838 % \end{macro}
839 % \end{macro}
840 %
841 % \begin{macro}{\ZebraPar}
842 % Now, the definition of |\ZebraPar|.
843 % \begin{macrocode}
844 %%%% zebra %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
845 \newcommand\ZebraPar[2][]{%
846 \begingroup
847 \setkeys[FP]{fancypar}{#1}%
848 \renewcommand\FancyPreFormat{\setcounter{fancycount}{0}}%
849 \renewcommand\FancyFormat{%
850 \noindent\stepcounter{fancycount}%
851 \makebox[\textwidth]{\colorbox{\FancyZColor}{%
852 \textcolor{\FancyZTextColor}{\box\linebox}}}%
853 \hrule height 0pt%
854 }
855 \par\smallskip\noindent%
856 \vbox{#2\par\add@fancy@format}%
857 \par\smallskip%
858 \endgroup
859 }
860
861 % \end{macrocode}
862 % \end{macro}
863 %
864 % \begin{macro}{\leaderfill}
865 % Definition of the leader that will be used in |\DashedPar|.
866 % \begin{macrocode}
867 \def\leaderfill{%
868 \color{\FancyDColor}%
869 \xleaders\hbox to \FancyDSeparation{\hss\FancyDSymbol\hss}\hfill%
870 }
871
872 % \end{macrocode}
873 % \end{macro}
874 %
875 % \begin{macro}{\DashedPar}
876 % The turn now is for |\DashedPar|.
877 % \begin{macrocode}
878 %%%% dashed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
879 \newcommand\DashedPar[2][]{%
880 \begingroup
881 \setkeys[FP]{fancypar}{#1}%
882 \renewcommand\FancyPreFormat{%
883 \hbox to \textwidth{\leaderfill}%
884 \vskip-\baselineskip%
885 }
886 \renewcommand\FancyFormat{%
887 \vphantom{\strut}\box\linebox%
888 \hbox to \textwidth{\leaderfill}%
889 \vskip-\baselineskip%
890 }
891 \par\medskip
892 \vbox{\noindent#2\par\add@fancy@format\medskip}%
893 \par\bigskip
894 \endgroup
895 }%
896
897 % \end{macrocode}
898 % \end{macro}
899 %
900 % \begin{macro}{\MarkedPar}
901 % The definition of |\MarkedPar|.
902 % \begin{macrocode}
903 %%%% marked %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904 \newcommand\MarkedPar[2][]{%
905 \begingroup
906 \setkeys[FP]{fancypar}{#1}
907 \renewcommand\FancyPreFormat{}
908 \renewcommand\FancyFormat{%
909 \noindent%
910 \FancyMarkPosition\par%
911 }%
912 \par\medskip%
913 \vbox{#2\par\add@fancy@format}%
914 \par\medskip%
915 \endgroup
916 }
917
918 % \end{macrocode}
919 % \end{macro}
920 %
921 % \begin{macro}{\UnderlinedPar}
922 % And last, but not least, the definition of |\UnderlinedPar|.
923 % \begin{macrocode}
924 %%%% underlined %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 \newcommand\UnderlinedPar[2][]{
926 \begingroup
927 \setkeys[FP]{fancypar}{#1}
928 \renewcommand\FancyPreFormat{}%
929 \renewcommand\FancyFormat{%
930 \box\linebox\color{\FancyUColor}\hrule
931 \smallskip
932 }
933 \par\medskip%
934 \vbox{\noindent#2\par\add@fancy@format}
935 \par\medskip%
936 \endgroup
937 }
938
939 % \end{macrocode}
940 % \end{macro}
941 %
942 % \begin{macro}{\add@fancy@format}
943 % The simple, yet powerful macro that makes use of |\lastbox| to dissect a paragraph;
944 % this macro is the core of this package; it is invoked in each one of the five predefined
945 % styles (and must be used in newly defined ones). A description can be found in
946 % \cite{eijk}.
947 % \changes{v 1.2}{2019/01/18}{Now all other styles also admit more than one paragraph. Thanks to Frank Mittelbach}
948 % \changes{v 1.3}{2021/04/17}{An additional unskip was added since the 2021 release of LaTeX adds an extra glue in the material between paragraphs. Thanks to Frank Mittelbach}
949 % \begin{macrocode}
950 \newsavebox\linebox%
951 \def\add@fancy@format{%
952 \setbox\linebox\lastbox
953 \ifvoid\linebox\FancyPreFormat\else
954 \unskip
955 \unpenalty
956 \unskip %Allows more than one paragraph in MarkedPar, DashedPar, ZebraPar, and UnderlinedPar. Thanks to Frank Mittelbach
957 \unskip %Required after the 2021 LaTeX release to handle an additional glue in the material between paragraphs. Thanks to Frank Mittelbach
958 {\add@fancy@format}%
959 \FancyFormat
960 \fi
961 }
962
963 % \end{macrocode}
964 % \end{macro}
965 %
966 % \begin{macro}{\AddFancyFormat}
967 % A copy of |\add@fancy@format| which the user can employ to apply new styles
968 % defined with the two commands below.
969 % \begin{macrocode}
970 \let\AddFancyFormat\add@fancy@format
971
972 % \end{macrocode}
973 % \end{macro}
974 %
975 % \begin{macro}{\FancyPreFormat}
976 % \begin{macro}{\FancyFormat}
977 % These two commands will allow the user to define his/her own styles.
978 % \begin{macrocode}
979 \newcommand\FancyPreFormat{}%
980 \newcommand\FancyFormat{}%
981 % \end{macrocode}
982 % \end{macro}
983 % \end{macro}
984 % \Finale
985 \endinput