%%
%% This is file `ducksay.code.v1.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ducksay.dtx  (with options: `code.v1')
%% 
%% --------------------------------------------------------------
%% ducksay -- cowsay for LaTeX
%% E-mail: jspratte@yahoo.de
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% --------------------------------------------------------------
%% 
%% Copyright (C) 2017-2020 Jonathan P. Spratte
%% 
%% This  work may be  distributed and/or  modified under  the conditions  of the
%% LaTeX Project Public License (LPPL),  either version 1.3c  of this license or
%% (at your option) any later version.  The latest version of this license is in
%% the file:
%% 
%%   http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%%   Jonathan P. Spratte.
%% 
%% This work consists of the file  ducksay.dtx
%% and the derived files           ducksay.pdf
%%                                 ducksay.sty
%%                                 ducksay.code.v1.tex
%%                                 ducksay.code.v2.tex and
%%                                 ducksay.animals.tex.
%% 
\ProvidesFile{ducksay.code.v1.tex}
  [\ducksay@date\space v\ducksay@version\space ducksay code version 1]
\cs_new:Npn \ducksay_longest_line:n #1
  {
    \int_incr:N \l_ducksay_msg_height_int
    \exp_args:NNx \tl_set:Nn \l_ducksay_tmpa_tl { #1 }
    \regex_replace_all:nnN { \s } { \c { space } } \l_ducksay_tmpa_tl
    \int_set:Nn \l_ducksay_msg_width_int
      {
        \int_max:nn
          { \l_ducksay_msg_width_int } { \tl_count:N \l_ducksay_tmpa_tl }
      }
  }
\cs_new:Npn \ducksay_open_bubble:
  {
    \begin{tabular}{@{}l@{}}
      \null\\
      \int_compare:nNnTF { \l_ducksay_msg_height_int } = { 1 } { ( }
        {
          /
          \int_step_inline:nnn
            { 3 } { \l_ducksay_msg_height_int } { \\\kern-0.2em| }
          \\\detokenize{\ }
        }
      \\[-1ex]\null
    \end{tabular}
    \begin{tabular}{@{}l@{}}
      _\\
      \int_step_inline:nnn { 2 } { \l_ducksay_msg_height_int } { \\ } \\[-1ex]
      \mbox { - }
    \end{tabular}
  }
\cs_new:Npn \ducksay_close_bubble:
  {
    \begin{tabular}{@{}l@{}}
      _\\
      \int_step_inline:nnn { 2 } { \l_ducksay_msg_height_int } { \\ } \\[-1ex]
      { - }
    \end{tabular}
    \begin{tabular}{@{}r@{}}
      \null\\
      \int_compare:nNnTF { \l_ducksay_msg_height_int } = { 1 }
        { ) }
        {
          \detokenize {\ }
          \int_step_inline:nnn
            { 3 } { \l_ducksay_msg_height_int } { \\|\kern-0.2em }
          \\/
        }
      \\[-1ex]\null
    \end{tabular}
  }
\cs_new:Npn \ducksay_print_msg:nn #1 #2
  {
    \begin{tabular}{@{} #2 @{}}
      \int_step_inline:nn { \l_ducksay_msg_width_int } { _ } \\
      #1\\[-1ex]
      \int_step_inline:nn { \l_ducksay_msg_width_int } { { - } }
    \end{tabular}
  }
\cs_generate_variant:Nn \ducksay_print_msg:nn { nV }
\cs_new:Npn \ducksay_print:nn #1 #2
  {
    \int_compare:nNnTF { \l_ducksay_msg_width_int } < { 0 }
      {
        \int_zero:N \l_ducksay_msg_height_int
        \seq_set_split:Nnn \l_ducksay_msg_lines_seq { \\ } { #1 }
        \seq_map_function:NN \l_ducksay_msg_lines_seq \ducksay_longest_line:n
      }
      {
        \int_compare:nNnT { \l_ducksay_msg_height_int } < { 0 }
          {
            \regex_count:nnN { \c { \\ } } { #1 } \l_ducksay_msg_height_int
            \int_incr:N \l_ducksay_msg_height_int
          }
      }
    \group_begin:
      \frenchspacing
      \verbatim@font
      \@noligs
      \begin{tabular}[\l_ducksay_align_tl]{@{}#2@{}}
        \l_ducksay_bubble_tl
        \begin{tabular}{@{}l@{}}
          \ducksay_open_bubble:
          \ducksay_print_msg:nV { #1 } \l_ducksay_msg_align_tl
          \ducksay_close_bubble:
        \end{tabular}\\
        \l_ducksay_body_tl
        \begin{tabular}{@{}l@{}}
          \l_ducksay_animal_tl
        \end{tabular}
      \end{tabular}
    \group_end:
  }
\cs_generate_variant:Nn \ducksay_print:nn { nV }
\cs_new:Npn \ducksay_say_and_think:nn #1 #2
  {
    \group_begin:
      \int_set:Nn \l_ducksay_msg_width_int  { -\c_max_int }
      \int_set:Nn \l_ducksay_msg_height_int { -\c_max_int }
      \keys_set:nn { ducksay } { #1 }
      \ducksay_default_or_random_animal:
      \ducksay_print:nV { #2 } \l_ducksay_rel_align_tl
    \group_end:
  }
\NewDocumentCommand \ducksay { O{} m }
  {
    \ducksay_say_and_think:nn { #1 } { #2 }
  }
\NewDocumentCommand \duckthink { O{} m }
  {
    \ducksay_say_and_think:nn { think, #1 } { #2 }
  }
%% 
%%
%% End of file `ducksay.code.v1.tex'.
