% \iffalse meta-comment
%
% Copyright (C) 2010, 2019 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}
%
% \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}[2019/01/18 v1.2 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}
% \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 
    {\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