summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ducksay/ducksay.code.v1.tex
blob: f8cd9ae89b575fe26291eef3fce0314d6540b39b (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
%%
%% 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-2019 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 }
      \tl_if_empty:NT \l_ducksay_animal_tl
        { \keys_set:nn { ducksay } { default_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'.