%% This package is distributed under the terms of the GPLv3 or later, or the
%% LPPL 1.3c or later, which ever license fits your needs the best.
%%
%% Copyright (C) 2017 by Jonathan P. Spratte
%%
%% This file is for documentation only
\documentclass[a4paper,10pt]{article}

%\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage[ligatures]{ducksay}
\usepackage{multicol}
\usepackage[colorlinks]{hyperref}
\usepackage{lmodern}

\makeatletter
\newcommand*{\availableAnimal}[1]{\@for\cs:=#1\do{%
  \ifx\cs\@empty\else%
    \rlap{\expandafter\ducksay\expandafter[\cs]{\cs}}\hfill\mbox{}\\[1ex]%
  \fi%
}}
\makeatother
\newcommand*{\anml}{\texttt{<animal>}}
\newcommand*{\msg}{\texttt{<message>}}
\newenvironment{codedescription}{%
  \parindent=-3em%
  \parskip=1em%
  \par%
}{}

\begin{document}
\begin{titlepage}%>>>
  \makeatletter
  \centering
  %\mbox{}\vfill
  \Large
    \ducksay[duck,bubble=\huge,msg-align=c,wd=8]{This is\\ducksay!}\\
  \vfill
  \normalsize
  \hspace*{-2cm}
    \ducksay[cow,bubble=\large]{\ducksay@version}\\
  \small
  \vspace*{-5cm}\hspace*{5cm}
    \ducksay[small-duck,bubble=\normalsize]{But which Version?}
  \mbox{}\hfil
  \vspace{2cm}
  \vfill
  \vfill
  \hspace*{-0cm}
  \large
  \smash{%
    \ducksay[r2d2,bubble=\large]{by Jonathan P. Spratte}}
  \small
    \ducksay[hedgehog,bubble=\normalsize]{Today is \ducksay@date}
  \makeatother
\end{titlepage}%<<<
\tableofcontents
\section{Macros}%>>>
\marginpar{%
  \rlap{%
    \tiny\ducksay[yoda,bubble=\footnotesize,align=t]{Use those, you might}}}
The following macros are available:

\begin{codedescription}
\verb|\ducksay[<options>]{<message>}|\\
  options might include any of the options described in
  \autoref{sec:options}. Prints an \anml\ saying \msg. \msg\ is not read in
  verbatim. Multi-line \msg s are possible using \verb|\\|. \verb|\\| should not
  be inside a macro but at toplevel. Else use the option \texttt{ht}.

\verb|\duckthink[<options>]{<message>}|\\
  options might include any of the options described in
  \autoref{sec:options}. Prints an \anml\ thinking \msg. \msg\ is not read in
  verbatim. It is implemented using regular expressions replacing a \verb|\|
  which is only preceded by \verb|\s*| in the first three lines with \verb|O|
  and \verb|o|. It is therefore slower than \verb|\ducksay|. Multi-line \msg s
  are possible using \verb|\\|. \verb|\\| should not be inside a macro but at
  toplevel. Else use the option \texttt{ht}.

\verb|\DefaultAnimal{<animal>}|\\
  use the \anml\ if none is given in the optional argument to \verb|\ducksay| or
  \verb|\duckthink|. Package default is \texttt{duck}.

\verb|\DucksayOptions{<options>}|\\
  set the defaults to the keys described in \autoref{sec:options}. Don't use an
  \anml\ here, it has no effect.

\verb|\AddAnimal(*){<animal>}<ascii-art>|\\
  adds \anml\ to the known animals. \texttt{<ascii-art>} is multi-line verbatim
  and therefore should be delimited either by matching braces or by anything
  that works for \verb|\verb|. If the star is given \anml\ is the new default.
  One space is added to the begin of \anml\ (compensating the opening symbol).
  For example, snowman is added with:\\[1ex]
  \begin{minipage}{\linewidth}
\begin{verbatim}
\AddAnimal{snowman}
{  \
    \_[_]_
      (")
   >-( : )-<
    (__:__)}
\end{verbatim}
  \end{minipage}
\end{codedescription}
%<<<
\section{Options}\label{sec:options}%>>>
{\reversemarginpar\marginpar{%
  \vspace*{-2em}\hspace*{-4em}%
  \tiny%
  \ducksay[hedgehog,bubble=\footnotesize,align=t]{Everyone likes\\options}}}
The following options are available to \verb|\ducksay|, \verb|\duckthink|, and
\verb|\DucksayOptions| and if not otherwise specified also as package options:

\begin{codedescription}
\anml\\
  One of the animals listed in \autoref{sec:animals} or any of the ones added
  with \verb|\AddAnimal|. Not useable as package option.

\texttt{animal=\anml}\\
  a longer alternative to the use of \anml\ if used in \verb|\ducksay| or
  \verb|\duckthink|. If it is used as a package option or in
  \verb|\DucksayOptions| it changes the default animal to \anml.

\texttt{bubble=\#1}\\
  use \texttt{\#1} in a group right before the bubble (for font switches). Might
  be used as a package option but not all control sequences work out of the box
  there.

\texttt{body=\#1}\\
  use \texttt{\#1} in a group right before the body (meaning the \anml). Might
  be used as a package option but not all control sequences work out of the box
  there. E.g., to right-align the \anml\ to the bubble, use \verb|body=\hfill|.

\texttt{align=\#1}\\
  use \texttt{\#1} as the vertical alignment specifier given to the
  \texttt{tabular} which is around the contents of \verb|\ducksay| and
  \verb|\duckthink|.

\texttt{msg-align=\#1}\\
  use \texttt{\#1} for alignment of the rows of multi-line \msg s. It should
  match a \texttt{tabular} column specifier. Default is \texttt{l}. It only
  affects the contents of the speech bubble not the bubble.

\texttt{wd=\#1}\\
  in order to detect the width the \msg\ is expanded. This might not work out
  for some commands (e.g. \verb|\url| from \texttt{hyperref}). If you specify
  the width using \texttt{wd} the \msg\ is not expanded and therefore the
  command \emph{might} work out. \texttt{\#1} should be the character count.

\texttt{ht=\#1}\\
  you might explicitly set the height (the row count) of the \msg. This only has
  an effect if you also specify \texttt{wd}.

\texttt{ligatures=\#1}\\
  this is a \LaTeX3 regular expression which should match every character you
  don't want to form ligatures during \verb|\AddAnimal|. The default expression
  is \verb|[\-<>`]|. Giving no argument (or an empty one) disables the
  replacement, which enhances compilation speed. The formation of ligatures was
  only observed in combination with \verb|\usepackage[T1]{fontenc}| by the
  author of this package. Therefore giving the option \texttt{ligatures} without
  an argument might enhance the compilation speed for you without any
  drawbacks.
\end{codedescription}
  %<<<
\section{Defects}%>>>
{\reversemarginpar\marginpar{%
  \tiny\rlap{\ducksay[frog,bubble=\footnotesize,align=t]{Ohh, no!}}}}
\begin{itemize}
  \item no automatic line wrapping
\end{itemize}
%<<<
\section{Dependencies}%>>>
\marginpar{%
  \tiny\rlap{\ducksay[kangaroo,bubble=\footnotesize,align=t]{We rely on you}}}
The package depends on the two packages \texttt{xparse} and \texttt{l3keys2e}
and all of their dependencies.
%<<<
%\clearpage
\section{Available Animals}\label{sec:animals}%>>>
The following animals are provided by this package. I did not create them (but
altered some), they belong to their original creators.
\bgroup
\footnotesize
\begin{multicols}{2}
\availableAnimal{%>>>
  ,duck%
  ,small-duck%
  ,duck-family%
  ,small-rabbit%
  ,squirrel%
  ,cow%
  ,tux%
  ,head-in%
  ,pig%
  ,frog%
  ,snowman%
  ,bunny%
  ,dragon%
  ,sodomized%
  ,hedgehog%
  ,kangaroo%
  ,dog%
  ,rabbit%
  ,unicorn%
}\end{multicols}\begin{multicols}{2}
\availableAnimal{%
  ,r2d2%
  ,vader%
  ,yoda-head%
  ,small-yoda%
  ,yoda%
}%<<<
\end{multicols}
\egroup
%<<<
\section{Miscellaneous}%>>>
\marginpar{%
  \rlap{\tiny\ducksay[squirrel,bubble=\footnotesize,align=t]{I'd choose WTFPL}}}
This package is distributed under the terms of the GPLv3 or later, or the LPPL
1.3c or later, choose which ever license fits your needs the best.

The package is hosted on \url{https://github.com/Skillmon/ltx_ducksay}, you
might report bugs there.
%<<<
\clearpage
% closing page>>>
\thispagestyle{empty}
\bgroup
\Huge
\mbox{}\vfill
\centering
\makebox[0pt]{\duckthink{Who's gonna use it anyway?}}
\vfill
\hfill\smash{\footnotesize\ducksay[small-yoda,wd=49]{hosted at
  \url{https://github.com/Skillmon/ltx_ducksay}}}
\egroup
%<<<
\end{document}

% vim: fdm=marker foldmarker=>>>,<<<
