summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fancypar/fancypar.dtx
blob: 6335941e499aa25786a9875f0aa4c50805678a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
% \iffalse meta-comment
%
% Copyright (C) 2010, 2019, 2021 by Gonzalo Medina
%
% --------------------------------------------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Gonzalo Medina.
%
% This work consists of the files fancypar.dtx and fancypar.ins,
% and the derived files fancypar.sty and fancypar.pdf.
%
% \fi
%
% \iffalse
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[english]{babel}
\usepackage{manfnt}
\usepackage{kpfonts}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage[x11names]{xcolor}
\usepackage{ragged2e}
\usepackage{ntheorem}
\usepackage{framed}
\usepackage{ifpdf}
\usepackage{fancypar}
\usepackage{hypdoc}
\ifpdf
  \usepackage{hypdestopt}
\fi
\hypersetup{pdfkeywords={LaTeX, package, fancypar},%
  pdfstartpage={},pdfstartview={},breaklinks=true,%
  linktocpage}
\usepackage{titletoc}

\titlecontents*{section}[0pt]
  {\itshape}{}{}
  {, \thecontentspage}[\ --\ ][.]
\titlecontents*{subsection}[0pt]
  {\upshape\small}{}{}
  {, \thecontentspage}[ (][. ][)]
\setcounter{tocdepth}{2}

\newcommand\colorsample[1]{%
  \raisebox{1.5pt}{\colorbox{#1}{\hphantom{e}\vphantom{e}}}%
}

\makeatletter
\renewtheoremstyle{margin}%
  {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]} 
  {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]}
\makeatother

\theoremstyle{margin}
\newtheorem{exam}{Example}

\newenvironment{mycode}
  {\begin{shaded}\ttfamily}
  {\end{shaded}}

\renewenvironment{shaded}{%
  \def\FrameCommand{\FrameRestore\fboxsep=\FrameSep\colorbox{Honeydew2}}%
  \MakeFramed {\FrameRestore}}%
 {\endMakeFramed}

\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.}

\newcommand*\myref[1]{\ref{#1}, page~\pageref{#1}}

\newcommand\MarNote[1]{\marginpar{\RaggedLeft\textcolor{blue}{#1}}}
\newcommand*\package[1]{{\upshape\mdseries\sffamily #1}}

\setlength\parindent{0pt}

\setcounter{tocdepth}{4}

\EnableCrossrefs
\CodelineIndex
\RecordChanges

\begin{document}
\DocInput{fancypar.dtx}
\end{document}
%</driver>
% \fi
%
% \CharacterTable
%  {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
%   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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v 1.1}{2010/04/25}{First revision}
% \changes{v 1.2}{2019/01/18}{Second revision}
% \changes{v 1.3}{2021/04/17}{Third revision}
%
% \GetFileInfo{fancypar.sty}
%
% \title{Fancy paragraph designs with the \package{fancypar} package\\
% {\footnotesize\fileversion , dated \filedate.}}
% \author{Gonzalo Medina\\%
%   Universidad Nacional de Colombia -- Sede Manizales\\%
%   Departamento de Matem\'aticas y Estad\'istica\\
%   \texttt{gmedinaar@unal.edu.co}}
%
% \maketitle
%
% \begin{abstract}
% \noindent This package offers five predefined decorative styles for text
% paragraphs of a document; the user can easily control the styles' attributes using the
% key-value mechanism. The package also allows the creation of new fancy designs.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% The \package{fancypar} package exploits the ``dissecting paragraphs with |\lastbox|" 
% technique explained in Section 5.9.6 of Victor Eijkhout's 
% \TeX\ by Topic (\cite{eijk}) to provide five predefined 
% and easily customizable fancy paragraph styles. New designs can also be 
% easily defined.\par\medskip
%
% \MarkedPar[position=left,mark=\color{blue}\manerrarrow]{The five commands were
% designed for \emph{text} paragraphs, so the mandatory argument of the five main
% commands described in Section~\myref{sec:options} cannot contain, for example,
% displayed math. By the way, this
% paragraph was typeset using one of the predefined styles offered by this
% package.}\par\medskip
%
% The author will gladly receive suggestions, comments and bug reports.
%
% \section{User Interface}
% Simply load this package in the preamble of a document (i.e.~the part of your
% document between |\documentclass| and |\begin{document}|) in the 
% standard way:
% \begin{mycode}
% |\usepackage{fancypar}|
% \end{mycode}
% This will make available the five predefined styles, through the commands 
% |\NotebookPar|, |\ZebraPar|, |\DashedPar|, |\MarkedPar| and |\UnderlinedPar|, described
% in Section~\myref{sec:options}.\par\medskip
%
% \MarkedPar[position=left,mark=\color{blue}\manerrarrow]{The \package{fancypar}
% package internally loads the \package{xcolor} package (\cite{kern}) without
% package options. If \package{xcolor} needs to be loaded with some options in a
% document, then \package{fancypar} must be loaded \emph{after} \package{xcolor}
% to prevent a clash.}
%
% \subsection{Package options}
% The \package{fancypar} package can also be loaded declaring some package options:
% \begin{mycode}
% |\usepackage[|\emph{options}|]{fancypar}|
% \end{mycode}
% Here (and in what follows) \emph{options} represents a comma-separated list of
% \emph{key=value} pairs\footnote{This feature was implemented using the
% \package{xkeyval} package (\cite{adri}).}, controlling some attributes of the
% predefined styles. The available options are described in Section~\myref{sec:options}
% (a summary with the default values is shown in Table~\myref{tab:options}).
% \par\medskip
%
% \DescribeMacro{\fancyparsetup}
% Additionally, for a later change of options, the \package{fancypar} package offers the
% command |\fancyparsetup|:
% \begin{mycode}
% |\fancyparsetup{|\emph{options}|}|
% \end{mycode}
% So, for example,
% \begin{mycode}
% |\usepackage[colorone=blue!20,colortwo=red!20]{fancypar}|
% \end{mycode}
% and
% \begin{mycode}
% |\usepackage{fancypar}|\\
% |\fancyparsetup{colorone=blue!20,colortwo=red!20}|
% \end{mycode}
% will produce the same result. The advantage of |\fancyparsetup| is that it can be used
% not only in the preamble but on the body of the document, as many times as required. 
% Even more control can be obtained using the optional
% argument for the commands |\NotebookPar|, |\ZebraPar|, |\DashedPar|, 
% |\MarkedPar|, and |\UnderlinedPar|.\par\medskip 
%
% \section{Predefined styles}\label{sec:options}
% Each of the commands |\NotebookPar|, |\ZebraPar|, |\DashedPar|, |\MarkedPar|, and 
% |\UnderlinedPar| described in this section has one 
% mandatory argument: the \emph{text} paragraph to which the style will be applied to.
% As mentioned above, each style has some predefined settings which can be changed
% by using the corresponding options in either the |\usepackage| or |\fancyparsetup|
% commands or individually, by using the optional argument of the corresponding
% command.\par\medskip
%
% Below is an illustration of the look of the predefined styles, using some placeholder
% text (see Section~\myref{sec:examples}).\par\medskip
%
% \phantomsection\label{exa:outpredefined}
% \textit{The notebook style:}
% \NotebookPar{\testtext}
% \textit{The zebra style:}
% \ZebraPar{\testtext}
% \textit{The marked style:}
% \MarkedPar{\testtext}
% \textit{The dashed style:}
% \DashedPar{\testtext}
% \textit{The underlined style:}
% \UnderlinedPar{\testtext}
%
% \subsection{The notebook style}
%
% \DescribeMacro{\NotebookPar}
% This command will present the affected paragraph as if it was written in a notebook.
% Using the \package{TikZ} package (\cite{tant}), a spiral is added by default to 
% the notebook (the spiral can be activated/deactivated using the |spiral| option). The
% options for this command are\par\medskip
%
% \begin{tabular}{rl}
%   |linecolor=|\meta{color} & Color of the notebook's lines.\\
%   |intercolor=|\meta{color} & Color of the rule between lines.\\
%   |textcolor=|\meta{color} & Color of the text.\\
%  |spiralcolor=|\meta{color} & Color of the spiral.\\
%  |interheight=|\meta{length} & Height of the rule used between consecutive lines.\\
%  |spiral=|\meta{true$\,\mid\,$false} & Activate/deactivate the spiral.\\
%  |nbtextwidth=|\meta{length} & Text width inside the notebook (only affects the text).
% \end{tabular}\par\medskip
%
% The syntax is
% \begin{mycode}
% |\NotebookPar[|\emph{options}|]{|\meta{text paragraph}|}|
% \end{mycode} 
%
% \subsection{The zebra-like style}
%
% \DescribeMacro{\ZebraPar}
% This command will color every line of the affected paragraph using a two-color 
% (zebra-like) pattern. The options for this command are\par\medskip
%
% \begin{tabular}{rl}
%   |colorone=|\meta{color} & Background color of the odd-numbered lines.\\
%  |colortwo=|\meta{color} & Background color of the even-numbered lines.\\
%  |textcolorone=|\meta{color} & Color of the text in the odd-numbered lines.\\
%  |textcolortwo=|\meta{color} & Color of the text in the even-numbered lines.
% \end{tabular}\par\medskip
%
% The syntax is
% \begin{mycode}
% |\ZebraPar[|\emph{options}|]{|\meta{text paragraph}|}|
% \end{mycode} 
%
% \DescribeMacro{fancycolor}
% \DescribeMacro{\FancyZColor}
% \DescribeMacro{\FancyZTextColor}
% Internally, the counter |fancycolor| is used to alternate colors for the odd and 
% even-numbered lines, by redefining the  command |\FancyZColor|. A little variation
% allows to achieve more sophisticated patterns with more than two alternating colors
% (see Example \myref{exa:zebrathree}). By an appropriate redefinition of the 
% |\FancyZTextColor|, some interesting patterns for the color of the text could also be
% achieved.
%
% \subsection{The dashed paragraph}
%
% \DescribeMacro{\DashedPar}
% This command uses the |\xleaders| \TeX\ primitive to fill the textwidth with evenly
% spaced copies of a symbol (or ``dash"). The options for this command
% are\par\medskip
%
% \begin{tabular}{rl}
%  |dashsymbol=|\meta{symbol} & Symbol to be used as ``dash".\\
%  |dashcolor=|\meta{color} & Color for the symbol to be used as ``dash".\\
%  |separation=|\meta{length} & Distance between two copies of the symbol.
% \end{tabular}\par\medskip
%
%The syntax is as follows:
% \begin{mycode}
% |\DashedPar[|\emph{options}|]{|\meta{text paragraph}|}|
% \end{mycode} 
%
% \subsection{Marking every line}
%
% \DescribeMacro{\MarkedPar}
% This command will add a symbol (or ``mark") to every line in the affected paragraph;
% the options for this style are |mark=|\meta{symbol} (the symbol to be used as the
% mark) and |position=|\meta{right$\,\mid\,$left} (the position of the symbol). The
% syntax is as follows:
% \begin{mycode}
% |\MarkedPar[|\emph{options}|]{|\meta{text paragraph}|}|
% \end{mycode} 
%
% \subsection{Underlining every line}
%
% \DescribeMacro{\UnderlinedPar}
% This command will underline every line of the affected paragraph. The only option for
% this command is |rulecolor|=\meta{color} which controls the color of the rule used.
% The syntax is
% \begin{mycode}
% |\UnderlinedPar[rulecolor=|\meta{color}|]{|\meta{text paragraph}|}|
% \end{mycode} 
%
% \begin{table}[!ht]
%   \centering
%   \begin{tabular}{rl>{\small}l}\toprule
%   Command/Style & Options & {\normalsize Default}\\\toprule
%   |\NotebookPar| & |linecolor=|\meta{color} &|SlateGray3!80|
%     \colorsample{SlateGray3!80}\\
%   & |intercolor=|\meta{color} & |green!20| \colorsample{green!20}\\
%   & |textcolor=|\meta{color} & |black|\\
%   & |interheight=|\meta{length} & |1pt|\\
%   & |spiralcolor=|\meta{color}&|LightYellow3| \colorsample{LightYellow3}\\
%   & |spiral=|\meta{true$\,\mid\,$false} & true\\
%   & |nbtextwidth=|\meta{length} & |\textindentright|\\\midrule
%   |\ZebraPar| & |colorone=|\meta{color}&|SlateGray2| \colorsample{SlateGray2}\\
%   & |colortwo=|\meta{color} & |DarkOliveGreen2!90!white!70| 
%     \colorsample{DarkOliveGreen2!90!white!70}\\
%   & |textcolorone=|\meta{color} & |black|\\
%   & |textcolortwo=|\meta{color} & |black|\\\midrule
%   |\DashedPar| & |separation=|\meta{length} & |0.9em|\\
%   & |dashsymbol=|\meta{symbol} & -- (en-dash: |--|)\\
%   & |dashcolor=|\meta{color} & |blue!50|~\colorsample{blue!50}\\\bottomrule
%   |\MarkedPar| & |mark=|\meta{symbol} & |$\surd$| 
%     $\surd$\\
%   & |position=|\meta{right$\,\mid\,$left}& |right|\\\midrule
%   |\UnderlinedPar| & |rulecolor=|\meta{color} & |DarkOliveGreen3|
%     \colorsample{DarkOliveGreen3}\\\bottomrule
%   \end{tabular}
%   \captionsetup{width=.8\textwidth}
%   \caption{summary of the predefined styles, their options and their default values.}
%   \label{tab:options}
% \end{table}
% \changes{v 1.1}{2010/04/25}{default symbol for the mark option changed to 
% $\surd$}
%
% \section{Defining new styles}
% \DescribeMacro{\FancyPreFormat}
% \DescribeMacro{\FancyFormat}
% \DescribeMacro{\AddFancyFormat}
% The creation of new paragraph designs involves the redefinition of the two commands
% |\FancyPreFormat| and |\FancyFormat|. The redefinition of the former will have effect
%  just before the first line of the affected paragraph, whilst the redefinition of the latter
% will affect all lines of the paragraph; the redefinition of |\FancyFormat| \emph{must}
% contain the |\box\linebox| construct. After redefining those commands, the actual
% typesetting of the modified paragraph is done by invoking
% |\vbox{#1\par\AddFancyFormat}|. Schematically the definition of a new style
% (called, for example, |\MyStylePar|) should have the following aspect:
% \begin{mycode}
%  |\newcommand\MyStylePar[1]{%|\\
%  |  \renewcommand\FancyPreFormat{%|\\
%  |    ...some commands...|\\
%  |  \renewcommand\FancyFormat{%|\\
%  |    ...some commands...|\\
%  |      \box\linebox%|\\
%  |    ...some commands...|\\
%  |  }|\\
%  |    ...some commands...|\\
%  |  \vbox{#1\par\AddFancyFormat}%|\\
%  |    ...some commands...|\\
%  |}%|\\
% \end{mycode}
%
% For a complete illustration of a new style definition, see
% Example~\myref{exa:newstyle}.
%
% \section{Examples}\label{sec:examples}
% In the following examples we will use some placeholder text, taken from 
% H.~Rackham's 1914 translation of Section 1.10.32 of ``de Finibus Bonorum et
% Malorum", written by Cicero:
% \begin{mycode}
%   |\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.}|
% \end{mycode}
%
% Each example includes the complete compilable code (after addition of the above
% definition of the |\testtext| command) and its result.
%
% \begin{exam}\label{exa:predefined}
% The default predefined styles.
% \end{exam}
%
% \begin{mycode}
% |\documentclass{article}|\\
% |\usepackage[english]{babel}|\\
% |\usepackage{fancypar}|\\
%
% |\begin{document}|\\
% |\textit{The notebook style:}|\\
% |\NotebookPar{\testtext}|\\
% |\textit{The zebra style:}|\\
% |\ZebraPar{\testtext}|\\
% |\textit{The marked style:}|\\
% |\MarkedPar{\testtext}|\\
% |\textit{The dashed style:}|\\
% |\DashedPar{\testtext}|\\
% |\textit{The underlined style:}|\\
% |\UnderlinedPar{\testtext}|\\
% |\end{document}|
% \end{mycode}
%
%  The output of this example is shown on Section~\myref{sec:options}.
%
% \begin{exam}
% Changing the predefined styles {\normalfont (via |\usepackage| and |\fancyparsetup|)}.
% \end{exam}
%
% \begin{mycode}
% |\documentclass{article}|\\
% |\usepackage[english]{babel}|\\
% |\usepackage[x11names]{xcolor}|\\
% |\usepackage[spiral=false,linecolor=Chocolate3!100!white!80]%|\\
% |   {fancypar}|\\
%
% |\begin{document}|\\
% |\NotebookPar{\testtext}|\\
% |\fancyparsetup{spiral=true,linecolor=LightGoldenrod3,|\\
% |  interheight=2pt,intercolor=Cornsilk2}|\\
% |\NotebookPar{\testtext}|\\
% |\fancyparsetup{spiral=false,linecolor=OliveDrab4!100!white!90,|\\
% |  interheight=0pt,textcolor=white}|\\
% |\NotebookPar{\testtext}|\\
% |\end{document}|
% \end{mycode}
% \fancyparsetup{spiral=false,linecolor=Chocolate3!100!white!80}
% \NotebookPar{\testtext}
%\fancyparsetup{spiral=true,linecolor=LightGoldenrod3,interheight=2pt,
%   intercolor=Cornsilk2}
% \NotebookPar{\testtext}
% \fancyparsetup{spiral=false,linecolor=OliveDrab4!100!white!90,
%  interheight=0pt,textcolor=white}
% \NotebookPar{\testtext}
%
% \begin{exam}
% Changing the predefined styles {\normalfont (via the optional argument of the
% commands)}.
% \end{exam}
%
% \begin{mycode}
% |\documentclass{article}|\\
% |\usepackage[english]{babel}|\\
% |\usepackage{fancypar}|\\
%
% |\begin{document}|\\
% |\MarkedPar{\testtext}|\\
% |\MarkedPar[mark=\ddag,position=left]{\testtext}|\\
% |\MarkedPar[mark=$\bullet$]{\testtext}|\\
% |\end{document}|
% \end{mycode}
% \MarkedPar{\testtext}
% \MarkedPar[mark=\ddag,position=left]{\testtext}
% \MarkedPar[mark=$\bullet$]{\testtext}
%
% \begin{exam}\label{exa:zebrathree}
% In this example a three color zebra pattern is used for the lines of the paragraph.
% \end{exam}
% \begin{mycode}
% |\documentclass{book}|\\
% |\usepackage[english]{babel}|\\
% |\usepackage[x11names]{xcolor}|\\
% |\usepackage{fancypar}|\\
% |\usepackage{intcalc}|\\
%
% |\renewcommand{\FancyZColor}{%|\\ 
% |  \ifcase\intcalcMod{\value{fancycount}}{3}%|\\ 
% |    OliveDrab4!100!white!90\or Chocolate3!100!white!80%|\\
% |      \or LightGoldenrod3\fi|\\
% |}|\\ 
%
% |\begin{document}|\\
% |\ZebraPar{\testtext}|\\
% |\end{document}| 
% \end{mycode}
%
% \renewcommand{\FancyZColor}{% 
%   \ifcase\intcalcMod{\value{fancycount}}{3}% 
%     OliveDrab4!100!white!90\or Chocolate3!100!white!80\or LightGoldenrod3\fi
% }
%
% \ZebraPar{\testtext}
%
% \begin{exam}\label{exa:newstyle}
% Definition of a new style. {\normalfont In this example we build a new style; the 
% odd-numbered lines will be typeset in red and the even-numbered lines will be typeset
% in black.}
% \end{exam}
%
% \begin{mycode}
% |\documentclass{article}|\\
% |\usepackage[english]{babel}|\\
% |\usepackage{fancypar}|\\
%
% |\newcounter{mycount}|\\
%
% |\newcommand\MyStylePar[1]{%|\\
% |  \renewcommand\FancyPreFormat{\setcounter{mycount}{0}}|\\
% |  \renewcommand\FancyFormat{%|\\
% |    \stepcounter{mycount}|\\
% |    \ifodd\themycount%|\\
% |      \noindent\textcolor{red}{\box\linebox}%|\\
% |    \else%|\\
% |      \box\linebox%|\\
% |    \fi%|\\
% |  }|\\
% |  \par\medskip%|\\
% |  \vbox{\noindent#1\par\AddFancyFormat}%|\\
% |  \par\medskip%|\\
% |}%|\\
%
% |\begin{document}|\\
% |\MyStylePar{\testtext}|\\
% |\end{document}|
% \end{mycode}
% \newcounter{mycount}
%
% \newcommand\MyStylePar[1]{%
%  \renewcommand\FancyPreFormat{\setcounter{mycount}{0}}
%  \renewcommand\FancyFormat{%
%    \stepcounter{mycount}
%    \ifodd\themycount%
%      \noindent\textcolor{red}{\box\linebox}%
%    \else%
%      \box\linebox%
%    \fi%
%  }
%  \par\medskip%
%  \vbox{#1\par\AddFancyFormat}%
%  \par\medskip%
% }%
% \MyStylePar{\testtext}
%
% \begin{thebibliography}{9}
% \bibitem{adri} Hendri Adriaens, The \package{xkeyval} package.
%   \href{http://www.ctan.org/pkg/xkeyval}{http://www.ctan.org/pkg/xkeyval}.
% \bibitem{eijk} Victor Eijkhout, \TeX\ by Topic.
%   \href{http://www.eijkhout.net/tbt/}{http://www.eijkhout.net/tbt/}.
% \bibitem{kern} Dr. Uwe Kern, The \package{xcolor} package. 
%   \href{http://www.ctan.org/pkg/xcolor}{http://www.ctan.org/pkg/xcolor}.
% \bibitem{tant} Till Tantau, The \package{PGF/TikZ} package. 
%   \href{http://www.ctan.org/pkg/pgf}{http://www.ctan.org/pkg/pgf}.
% \end{thebibliography}
%
% \PrintChanges
%
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ ,\@ifpackageloaded}
% \DoNotIndex{\addtolength,\baselineskip,\begingroup,\begin,\bigskip,\box}
% \DoNotIndex{\color,\colorbox,\CurrentOption,\day,\def,\draw,\else,\end,\endgroup,\fi}
% \DoNotIndex{\fboxsep,\hbox,\hfill,\hrule,\hskip,\hss,\ifcase,\ifodd,\ifvoid,}
% \DoNotIndex{\let,\lastbox,\linebox,\llap,\makebox,\mbox,\medskip}
% \DoNotIndex{\newcommand,\newcounter,\newlength,\newsavebox,\node,\noindent}
% \DoNotIndex{\nr,\or,\par,\parindent,\parshape,\quad,\relax,\renewcommand}
% \DoNotIndex{\RequirePackage,\rightpointleft,\rlap,\setbox,\setcounter,\setkeys}
% \DoNotIndex{\setlength,\smallskip,\stepcounter,\textcolor,\textwidth,\tikz}
% \DoNotIndex{\unpenalty,\unskip,\usetikzlibrary,\val,\vbox,\vphantom,\vskip}
% \DoNotIndex{\NeedsTeXFormat,\ProvidesPackage,\xleaders}
% 
% \StopEventually{\PrintIndex}
%
% \clearpage
% \section{Implementation}
% 
% Standard identification:
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fancypar}[2021/04/17 v1.3 fancy paragraphs]

%    \end{macrocode}
%
% We load the necessary packages:
% \changes{v 1.1}{2010/04/25}{dingbat will not be used}
% \begin{macrocode}
\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}
\@ifpackageloaded{tikz}{\usetikzlibrary{calc}}
  {\RequirePackage{tikz}\usetikzlibrary{calc}}
\@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}

%    \end{macrocode}
%
% \begin{macro}{colorone}
% \begin{macro}{colortwo}
% \begin{macro}{textcolorone}
% \begin{macro}{textcolortwo}
% \begin{macro}{linecolor}
% \begin{macro}{intercolor}
% \begin{macro}{interheight}
% \begin{macro}{spiralcolor}
% \begin{macro}{textcolor}
% \begin{macro}{nbtextwidth}
% \begin{macro}{mark}
% \begin{macro}{rulecolor}
% \begin{macro}{separation}
% \begin{macro}{dashcolor}
% \begin{macro}{dashsymbol}
% The |xkeyval| package was used to handle the package options that will also be used
% later on. First, the options declaration (prefix: |FP|, family: |fancypar|).
% \begin{macrocode}
\DeclareOptionX[FP]<fancypar>{colorone}{\def\FancyZColorOne{#1}}
\DeclareOptionX[FP]<fancypar>{colortwo}{\def\FancyZColorTwo{#1}}
\DeclareOptionX[FP]<fancypar>{textcolorone}{\def\FancyZTextColorOne{#1}}
\DeclareOptionX[FP]<fancypar>{textcolortwo}{\def\FancyZTextColorTwo{#1}}
\DeclareOptionX[FP]<fancypar>{linecolor}{\def\FancyNlColor{#1}}
\DeclareOptionX[FP]<fancypar>{intercolor}{\def\FancyNilColor{#1}}
\DeclareOptionX[FP]<fancypar>{interheight}{\def\FancyNilHeight{#1}}
\DeclareOptionX[FP]<fancypar>{spiralcolor}{\def\FancyNSColor{#1}}
\DeclareOptionX[FP]<fancypar>{textcolor}{\def\FancyNTextColor{#1}}
\DeclareOptionX[FP]<fancypar>{nbtextwidth}{\def\FancyNTWidth{#1}}
\DeclareOptionX[FP]<fancypar>{mark}{\def\FancyMark{#1}}
\DeclareOptionX[FP]<fancypar>{rulecolor}{\def\FancyUColor{#1}}
\DeclareOptionX[FP]<fancypar>{separation}{\def\FancyDSeparation{#1}}
\DeclareOptionX[FP]<fancypar>{dashcolor}{\def\FancyDColor{#1}}
\DeclareOptionX[FP]<fancypar>{dashsymbol}{\def\FancyDSymbol{#1}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\textindent}
% \begin{macro}{\textindentright}
% The length |\textindent| will be used to control the indentation of the paragraph in the
% notebook style, depending on whether or not the spiral will be used. The length
% |\textindentright| controls the distance from the right indentation of the text;
% it is set to |\textwidth-2cm|.
% \begin{macrocode}
\newlength\textindent{}
\newlength\textindentright{}
\setlength\textindentright{\textwidth}
\addtolength\textindentright{-2cm}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{spiral}
% The boolean key |spiral| is used here to set |\textindent| appropriately and will be used
% in the definition of the notebook style to draw or not the spiral.
% \begin{macrocode}
\define@boolkey[FP]{fancypar}{spiral}{%
\ifFP@fancypar@spiral
  \setlength\textindent{-2.6mm}%
\else
  \setlength\textindent{3mm}%
\fi
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{position}
% The choince-key |position| is used to specify the placement of the mark in the marked
% style.
% \begin{macrocode}
\define@choicekey+[FP]{fancypar}{position}[\val\nr]{left,right}{%
  \ifcase\nr\relax
    \def\FancyMarkPosition{\llap{\mbox{\FancyMark\quad}}\box\linebox}
  \or
    \def\FancyMarkPosition{\box\linebox\rlap{\mbox{\quad\FancyMark}}}
  \fi	
}{%
  \PackageWarning{fancypar}{erroneous input ignored}%
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\DeclareOptionX*{\PackageWarning{fancypar}{‘\CurrentOption’ ignored}}

%    \end{macrocode}
%
% Now we define some of the colors that will be used by default. We use the RGB system
% to define colors already present in the |x11names| family, just to avoid loading the 
% |xcolor| package with options.
% \begin{macrocode}
\definecolor{zcolori}{RGB}{185,211,238}%SlateGray2
\definecolor{zcolorii}{RGB}{188,238,104}%DarkOliveGreen2
\definecolor{lcolor}{RGB}{159,182,205}%SlateGray3
\definecolor{scolor}{RGB}{205,205,180}%LightYellow3
\definecolor{rcolor}{RGB}{162,205,90}%DarkOliveGreen3

%    \end{macrocode}
%
% We set the default value for the keys that were defined.
% \begin{macrocode}
\ExecuteOptionsX[FP]<fancypar>{%
  colorone=zcolori,%
  colortwo=zcolorii!90!white!70,%
  textcolorone=black,%
  textcolortwo=black,%
  linecolor=lcolor!80,%
  intercolor=green!20,%
  interheight=1pt,%
  spiralcolor=scolor,%
  spiral=true,%
  textcolor=black,%
  nbtextwidth=\textindentright,%
  mark=$\surd$,% \changes{v 1.1}{2010/04/25}{changed to $\surd$}
  rulecolor=rcolor,%
  position=right,%
  dashcolor=blue!50,%
  separation=0.9em,%
  dashsymbol=--
}

%    \end{macrocode}
%
% Now comes the processing of the keys and values which will be passed by the user to
% the package.
% \begin{macrocode}
\ProcessOptionsX[FP]<fancypar>

%    \end{macrocode}
%
% \begin{macro}{\fancyparsetup}
% Definition of the command to control attributes in the preamble or at any point of the
% document.
% \begin{macrocode}
\DeclareRobustCommand*\fancyparsetup[1]{%
  \setkeys[FP]{fancypar}{#1}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NotebookPar}
% Now, to the definition of the five predefined styles. |\NotebookPar| comes first.
% \changes{v 1.2}{2019/01/18}{NotebookPar admits more than one paragraph. Thanks to Frank Mittelbach}
% \begin{macrocode}
%%%% notebook %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\NotebookPar[2][]{%
  \begingroup
  \setkeys[FP]{fancypar}{#1}
  \renewcommand\FancyPreFormat{\smallskip}
  \renewcommand\FancyFormat{%
    \hskip\textindent%
    \tikz{%
      \draw[draw=black,fill=white] (-1,-0.3) circle (3pt);%
      \ifFP@fancypar@spiral
        \draw[very thin,rotate=4,double=\FancyNSColor,%
          double distance=1.5pt]% 
          (-1,-0.2) arc (40:-250:10pt and 2pt);%
      \else\relax
      \fi
    }
    \hskip4mm\vphantom{\strut}%
    \textcolor{\FancyNTextColor}{\box\linebox}%
    \color{\FancyNilColor}\hrule height\FancyNilHeight%
    \smallskip%
  }
  \setlength\parindent{0pt}
  \par\vskip\baselineskip
  \noindent%
  \begin{tikzpicture}[inner sep=-1.1pt]%
    \setlength\fboxsep{0pt}%
    \node (a) {\colorbox{\FancyNlColor}{%
      \vbox{%
        \vskip-0.5mm\parshape 1 0cm \FancyNTWidth%
         \def\par{{\@@par}}% A trick that executes the real "par" = \@@par inside a group so that the parshape is restored. Thanks to Frank Mittelbach.
         #2\@@par
         \add@fancy@format%
      }%
    }%
  } {};
  \end{tikzpicture}
  \par\bigskip
  \endgroup
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{fancycount}
% \begin{macro}{\FancyZColor}
% \begin{macro}{\FancyZTextColor}
% Next, we define the counter |fancycount|, and the command |\FancyZColor| used to
% produce the zebra-like pattern (by changing the color depending on whether the value
% of the counter is odd or even). We also define the command |\FancyZTextColor| to
% allow a similar definition for the color of the text lines. The counter and the commands
% can be used, or redefined by the user, in a \LaTeX\ document to produce more
% sophisticated zebra-like designs.
% \begin{macrocode}
\newcounter{fancycount}
\newcommand\FancyZColor{}
\renewcommand\FancyZColor{%alternate line colors
  \ifodd\thefancycount % 
    \FancyZColorOne% 
  \else
    \FancyZColorTwo% 
  \fi 
}

\newcommand\FancyZTextColor{}
\renewcommand\FancyZTextColor{%alternate text colors
  \ifodd\thefancycount % 
    \FancyZTextColorOne% 
  \else
    \FancyZTextColorTwo% 
  \fi 
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ZebraPar}
% Now, the definition of |\ZebraPar|.
% \begin{macrocode}
%%%% zebra %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\ZebraPar[2][]{%
  \begingroup
  \setkeys[FP]{fancypar}{#1}%
  \renewcommand\FancyPreFormat{\setcounter{fancycount}{0}}%
  \renewcommand\FancyFormat{%
    \noindent\stepcounter{fancycount}%
    \makebox[\textwidth]{\colorbox{\FancyZColor}{%
      \textcolor{\FancyZTextColor}{\box\linebox}}}%
    \hrule height 0pt%
  }
  \par\smallskip\noindent%
  \vbox{#2\par\add@fancy@format}%
  \par\smallskip%
  \endgroup
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\leaderfill}
% Definition of the leader that will be used in |\DashedPar|.
% \begin{macrocode}
\def\leaderfill{%
  \color{\FancyDColor}%
  \xleaders\hbox to \FancyDSeparation{\hss\FancyDSymbol\hss}\hfill%
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DashedPar}
% The turn now is for |\DashedPar|.
% \begin{macrocode}
%%%% dashed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\DashedPar[2][]{%
  \begingroup
  \setkeys[FP]{fancypar}{#1}%
  \renewcommand\FancyPreFormat{%
    \hbox to \textwidth{\leaderfill}%
    \vskip-\baselineskip%
  }
  \renewcommand\FancyFormat{%
    \vphantom{\strut}\box\linebox%
    \hbox to \textwidth{\leaderfill}%
    \vskip-\baselineskip%
  }
  \par\medskip
  \vbox{\noindent#2\par\add@fancy@format\medskip}%
  \par\bigskip
  \endgroup
}%

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MarkedPar}
% The definition of |\MarkedPar|.
% \begin{macrocode}
%%%% marked %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\MarkedPar[2][]{%
  \begingroup
  \setkeys[FP]{fancypar}{#1}
  \renewcommand\FancyPreFormat{}
  \renewcommand\FancyFormat{%
    \noindent%
    \FancyMarkPosition\par%
  }%
  \par\medskip%
  \vbox{#2\par\add@fancy@format}%
  \par\medskip%
  \endgroup
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\UnderlinedPar}
% And last, but not least, the definition of |\UnderlinedPar|.
% \begin{macrocode}
%%%% underlined %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\UnderlinedPar[2][]{
  \begingroup
  \setkeys[FP]{fancypar}{#1}
  \renewcommand\FancyPreFormat{}%
  \renewcommand\FancyFormat{%
    \box\linebox\color{\FancyUColor}\hrule
    \smallskip 
  }  
  \par\medskip%
  \vbox{\noindent#2\par\add@fancy@format}
  \par\medskip%
  \endgroup
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\add@fancy@format}
% The simple, yet powerful macro that makes use of |\lastbox| to dissect a paragraph;
% this macro is the core of this package; it is invoked in each one of the five predefined
% styles (and must be used in newly defined ones). A description can be found in
% \cite{eijk}.
% \changes{v 1.2}{2019/01/18}{Now all other styles also admit more than one paragraph. Thanks to Frank Mittelbach}
% \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}
% \begin{macrocode}
\newsavebox\linebox%
\def\add@fancy@format{% 
  \setbox\linebox\lastbox 
  \ifvoid\linebox\FancyPreFormat\else 
    \unskip 
    \unpenalty
    \unskip %Allows more than one paragraph in MarkedPar, DashedPar, ZebraPar, and UnderlinedPar. Thanks to Frank Mittelbach 
    \unskip %Required after the 2021 LaTeX release to handle an additional glue in the material between paragraphs. Thanks to Frank Mittelbach 
    {\add@fancy@format}% 
    \FancyFormat
  \fi 
} 

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\AddFancyFormat}
% A copy of |\add@fancy@format| which the user can employ to apply new styles
% defined with the two commands below.
% \begin{macrocode}
\let\AddFancyFormat\add@fancy@format

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\FancyPreFormat}
% \begin{macro}{\FancyFormat}
% These two commands will allow the user to define his/her own styles.
% \begin{macrocode}
\newcommand\FancyPreFormat{}%
\newcommand\FancyFormat{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \Finale
\endinput