diff options
author | Karl Berry <karl@freefriends.org> | 2017-10-30 20:40:11 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-10-30 20:40:11 +0000 |
commit | d1742894869da9494417216646bc5627ef3f3352 (patch) | |
tree | 72f25c524fd78ea0bce5cbfe612902388b71319a /Master/texmf-dist/tex | |
parent | 518143fa6ebbdfe93702cf0184bd96964a09b09d (diff) |
ducksay (30oct17)
git-svn-id: svn://tug.org/texlive/trunk@45647 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/ducksay/ducksay.sty | 172 |
1 files changed, 110 insertions, 62 deletions
diff --git a/Master/texmf-dist/tex/latex/ducksay/ducksay.sty b/Master/texmf-dist/tex/latex/ducksay/ducksay.sty index bb4a9fe3e5e..8282a35791c 100644 --- a/Master/texmf-dist/tex/latex/ducksay/ducksay.sty +++ b/Master/texmf-dist/tex/latex/ducksay/ducksay.sty @@ -5,8 +5,8 @@ \NeedsTeXFormat{LaTeX2e} \RequirePackage{xparse,l3keys2e} -\def\ducksay@version{v1.1} -\def\ducksay@date{2017/09/25} +\def\ducksay@version{v1.2} +\def\ducksay@date{2017/10/30} \ProvidesExplPackage {ducksay} {\ducksay@date} @@ -14,11 +14,57 @@ \ExplSyntaxOn +% variables>>> \int_new:N \l_ducksay_strlen_int \int_new:N \l_ducksay_lines_int \seq_new:N \l_ducksay_msg_lines_seq +\tl_new:N \l_ducksay_align_tl +\tl_new:N \l_ducksay_msg_align_tl +\tl_new:N \l_ducksay_animal_tl +\bool_new:N \l_ducksay_empty_ligatures_bool +\cs_new:Nn \ducksay_bubble: {} +\cs_new:Nn \ducksay_body: {} +\regex_new:N \l_ducksay_ligatures_regex +%<<< + +% predefined regexes>>> +% regexes for \duckthink >>> +\regex_const:Nn \c_ducksay_first_regex { \A(.\s*)\\ } +\regex_const:Nn \c_ducksay_second_regex { \A(.[^\c{null}]*\c{null}\s*)\\ } +\regex_const:Nn \c_ducksay_third_regex { + \A(.[^\c{null}]*\c{null}[^\c{null}]*\c{null}\s*)\\ } +%<<< +% regexes for \AddAnimal >>> +\regex_const:Nn \c_ducksay_newline_regex { \r } +\regex_set:Nn \l_ducksay_ligatures_regex { [\-<>`] } +%<<< +%<<< + +\keys_define:nn { ducksay } {%>>> + ,bubble .code:n = \cs_set:Nn \ducksay_bubble: {#1} + ,body .code:n = \cs_set:Nn \ducksay_body: {#1} + ,align .tl_set:N = \l_ducksay_align_tl + ,align .value_required:n = true + ,wd .int_set:N = \l_ducksay_strlen_int + ,wd .value_required:n = true + ,ht .int_set:N = \l_ducksay_lines_int + ,ht .value_required:n = true + ,animal .code:n = { + \keys_define:nn { ducksay } { default_animal .meta:n = {#1} }} + ,animal .initial:n = duck + ,msg-align .tl_set:N = \l_ducksay_msg_align_tl + ,msg-align .initial:n = l + ,msg-align .value_required:n = true + ,ligatures .code:n = { + \tl_if_empty:nTF { #1 } + { \bool_set_true:N \l_ducksay_empty_ligatures_bool } + { \regex_set:Nn \l_ducksay_ligatures_regex { #1 } } + } +}%<<< + +\ProcessKeysOptions { ducksay } -\cs_new:Npn \ducksay_longest_line:n #1 {%>>> +\cs_new:Nn \ducksay_longest_line:n {%>>> \int_incr:N \l_ducksay_lines_int \exp_args:NNx \tl_set:Nn \l_tmpa_tl { #1 } \regex_replace_all:nnN { \s } { \c{space} } \l_tmpa_tl @@ -26,7 +72,7 @@ \int_max:nn { \l_ducksay_strlen_int } { \tl_count:N \l_tmpa_tl } } }%<<< -\cs_new:Npn \ducksay_open_bubble: {%>>> +\cs_new:Nn \ducksay_open_bubble: {%>>> \begin{tabular}{@{}l@{}} \mbox{}\\ \int_compare:nNnTF {\l_ducksay_lines_int} = {1} { @@ -41,11 +87,11 @@ \begin{tabular}{@{}l@{}} _\\ \int_step_inline:nnnn{2}{1}{\l_ducksay_lines_int}{\\}\\[-1ex] - {-} + \mbox{-} \end{tabular} }%<<< -\cs_new:Npn \ducksay_close_bubble: {%>>> +\cs_new:Nn \ducksay_close_bubble: {%>>> \begin{tabular}{@{}l@{}} _\\ \int_step_inline:nnnn{2}{1}{\l_ducksay_lines_int}{\\}\\[-1ex] @@ -64,7 +110,7 @@ \end{tabular} }%<<< -\cs_new:Npn \ducksay_print_msg:n #1 #2 {%>>> +\cs_new:Nn \ducksay_print_msg:nn {%>>> \begin{tabular}{@{} #2 @{}} \int_step_inline:nnnn{1}{1}{\l_ducksay_strlen_int}{_}\\ #1\\[-1ex] @@ -72,7 +118,9 @@ \end{tabular} }%<<< -\cs_new:Npn \ducksay_print:n #1 {%>>> +\cs_generate_variant:Nn \ducksay_print_msg:nn { nV } + +\cs_new:Nn \ducksay_print:n {%>>> \int_case:nnF { \l_ducksay_strlen_int } { { 0 } { \seq_set_split:Nnn \l_ducksay_msg_lines_seq {\\} { #1 } @@ -85,14 +133,16 @@ \int_incr:N \l_ducksay_lines_int }} } - \frenchspacing \group_begin: + \frenchspacing \ttfamily + \verbatim@font + \@noligs \begin{tabular}[\l_ducksay_align_tl]{@{}l@{}} \ducksay_bubble: \begin{tabular}{@{}l@{}} \ducksay_open_bubble: - \exp_args:Nno \ducksay_print_msg:n {#1} { \l_ducksay_msg_align_tl } + \ducksay_print_msg:nV {#1} \l_ducksay_msg_align_tl \ducksay_close_bubble: \end{tabular}\\ \ducksay_body: @@ -103,63 +153,50 @@ \group_end: }%<<< +\cs_new:Nn \ducksay_prepare_say_and_think:n {%>>> + \int_zero:N \l_ducksay_strlen_int + \int_zero:N \l_ducksay_lines_int + \keys_define:nn { ducksay } { animal .meta:n = { ##1 } } + \keys_set:nn { ducksay } { default_animal,#1 } +}%<<< + +\cs_new:Nn \ducksay_to_duckthink: {%>>> + \regex_replace_once:NnN \c_ducksay_first_regex { \1O } \l_ducksay_animal_tl + \regex_replace_once:NnN \c_ducksay_second_regex { \1o } \l_ducksay_animal_tl + \regex_replace_once:NnN \c_ducksay_third_regex { \1o } \l_ducksay_animal_tl +}%<<< + \NewDocumentCommand{\ducksay}{ O{} m }{%>>> \group_begin: - \int_zero:N \l_ducksay_strlen_int - \int_zero:N \l_ducksay_lines_int - \keys_set:nn { ducksay } { default_animal,#1 } + \ducksay_prepare_say_and_think:n { #1 } \ducksay_print:n { #2 } \group_end: }%<<< -% regexes for \duckthink >>> -\regex_const:Nn \c_ducksay_first_regex { \A(.\s*)\\ } -\regex_const:Nn \c_ducksay_second_regex { \A(.[^\c{null}]*\c{null}\s*)\\ } -\regex_const:Nn \c_ducksay_third_regex { - \A(.[^\c{null}]*\c{null}[^\c{null}]*\c{null}\s*)\\ } -%<<< - \NewDocumentCommand{\duckthink}{ O{} m }{%>>> \group_begin: - \int_zero:N \l_ducksay_strlen_int - \int_zero:N \l_ducksay_lines_int - \keys_set:nn { ducksay } { default_animal,#1 } - \regex_replace_once:NnN \c_ducksay_first_regex { \1O } \l_ducksay_animal_tl - \regex_replace_once:NnN \c_ducksay_second_regex { \1o } \l_ducksay_animal_tl - \regex_replace_once:NnN \c_ducksay_third_regex { \1o } \l_ducksay_animal_tl + \ducksay_prepare_say_and_think:n { #1 } + \ducksay_to_duckthink: \ducksay_print:n { #2 } \group_end: }%<<< -\keys_define:nn { ducksay } {%>>> - ,bubble .code:n = \cs_set:Nn \ducksay_bubble: {#1} - ,bubble .initial:n = \relax - ,body .code:n = \cs_set:Nn \ducksay_body: {#1} - ,body .initial:n = \relax - ,align .tl_set:N = \l_ducksay_align_tl - ,align .initial:n = {} - ,align .value_required:n = true - ,wd .int_set:N = \l_ducksay_strlen_int - ,wd .value_required:n = true - ,ht .int_set:N = \l_ducksay_lines_int - ,ht .value_required:n = true - ,animal .code:n = { - \keys_define:nn { ducksay } { default_animal .meta:n = {#1} }} - ,animal .initial:n = duck - ,msg-align .tl_set:N = \l_ducksay_msg_align_tl - ,msg-align .initial:n = l - ,msg-align .value_required:n = true -}%<<< - \NewDocumentCommand{\DefaultAnimal}{ m }{%>>> \keys_define:nn { ducksay } { default_animal .meta:n = {#1} }}%<<< +\NewDocumentCommand{\DucksayOptions}{ m }{%>>> + \keys_set:nn { ducksay } { #1 }}%<<< + \NewDocumentCommand{\AddAnimal}{ s m +v }{%>>> \tl_set:Nn \l_tmpa_tl { \ #3 } - \regex_replace_all:nnN { \r } { \c{tabularnewline}\c{null} } \l_tmpa_tl - \cs_gset_eq:cN { g_ducksay_animal_#2_tl } \l_tmpa_tl + \bool_if:NF \l_ducksay_empty_ligatures_bool { + \regex_replace_all:NnN \l_ducksay_ligatures_regex { \c{mbox}\0 } \l_tmpa_tl + } + \regex_replace_all:NnN \c_ducksay_newline_regex { \c{tabularnewline}\c{null} } + \l_tmpa_tl + \tl_gset_eq:cN { g_ducksay_animal_#2_tl } \l_tmpa_tl \keys_define:nn { ducksay } { - #2 .code:n = \cs_set_eq:Nc \l_ducksay_animal_tl { g_ducksay_animal_#2_tl } + #2 .code:n = \tl_set_eq:Nc \l_ducksay_animal_tl { g_ducksay_animal_#2_tl } } \IfBooleanT{#1}{ \keys_define:nn { ducksay } { @@ -272,8 +309,8 @@ `""`""`}%<<< \AddAnimal{bunny}%>>> { \ - \ \ - \ /\ + \ / + /\ / ( ) .( o ).}%<<< \AddAnimal{small-rabbit}%>>> @@ -313,7 +350,28 @@ _(\.= ;:;;' `"_( _/="` `"'``}%<<< - +% from http://www.ascii-art.de/ascii/uvw/unicorn.txt +\AddAnimal{unicorn} +{ \ + \ /((((((\\\\ + ---====((((((((((\\\\\ + (( \\\\\\\ + ( (* _/ \\\\\\\ + \ / \ \\\\\\_ __,,__ + | | | </ "------"" ((\\\\ + o_| / / \ \\\\ \\\\\\\ + | ._ ( \ \\\\\\\\\\\\\\\\ + | / / / \\\\\\\ \\ + .______/\/ / / / \\\ + / __.____/ _/ ___----( /\ + / / / ________/:______,---' \ / \_ + / / \ \ \ \ \_ \ + ( < \ \ > / \ \ + \/ \\_ / / > ) + \_| / / / / + _// _// + /_| /_|} + % from http://www.ascii-art.de/ascii/s/starwars.txt : \AddAnimal{yoda}%>>> { \ @@ -409,15 +467,5 @@ | `' |}%<<< %<<< -\ExplSyntaxOn - -\ProcessKeysOptions { ducksay } - -\keys_define:nn { ducksay } { - ,animal .undefine: -} - -\ExplSyntaxOff - \endinput % vim: fdm=marker foldmarker=>>>,<<< |