-
Notifications
You must be signed in to change notification settings - Fork 2
/
chickenize.dtx
2728 lines (2491 loc) · 130 KB
/
chickenize.dtx
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse
%<*driver>
%% File: chickenize.dtx by Arno Trautmann, mail: arno dot trautmann at gmx dot de
\iffalse
%</driver>
%<*readme>
The package chickenize provides several commands and Lua functions to manipulate the input or output tokens of any Lua(La)TeX document. It serves mostly educational and playful usage, but some functions may be used in serious documents.
To produce the package files, run lualatex on chickinize.dtx, wich should result in the creation of the following files:
chickenize.pdf (documentation)
chickenize.tex (plainTeX user interface)
chickenize.sty (LaTeX user interface)
chickenize.lua (Lua package code) [does the actual work]
You need an up-to-date TeX Live (2020, if possible) to use this package. Maybe a full MiKTeX will also work. (Not tested!) Lua\TeX > 1.0.4 is required for some features since the corresponding syntax has changed; tested with Lua\TeX 1.12.0 (TeX Live 2020)
For any comments or suggestions, contact me:
arno dot trautmann at gmx dot de
Hope you have fun with this package!
This package is copyright © 2021 Arno L. Trautmann. It may be distributed and/or
modified under the conditions of the LaTeX Project Public License, either version 1.3c
of this license or (at your option) any later version. This work has the LPPL mainten-
ance status ‘maintained’.
%</readme>
%<*driver>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
\input docstrip.tex
\keepsilent
\let\MetaPrefix\relax
\preamble
EXPERIMENTAL CODE
This package is copyright © 2021 Arno L. Trautmann. It may be distributed and/or
modified under the conditions of the LaTeX Project Public License, either version 1.3c
of this license or (at your option) any later version. This work has the LPPL mainten-
ance status ‘maintained’.
\endpreamble
\let\MetaPrefix\DoubleperCent
\postamble
\endpostamble
\askforoverwritefalse
\generate{\file{chickenize.sty}{\from{chickenize.dtx}{package}}}
\generate{\file{chickenize.tex}{\from{chickenize.dtx}{tex}}}
\def\MetaPrefix{-- }
\def\luapostamble{%
\MetaPrefix^^J%
\MetaPrefix\space End of File `\outFileName'.%
}
\def\currentpostamble{\luapostamble}%
\generate{\file{chickenize.lua}{\from{chickenize.dtx}{lua}}}
\nopreamble\nopostamble
\catcode`\@12
\generate{\file{README.md}{\from{chickenize.dtx}{readme}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
\documentclass[11pt,english]{ltxdoc}
\usepackage{
array,
babel,
booktabs,
fontspec,
geometry,
graphicx,
hyperref,
longtable,
microtype,
scrlayer-scrpage,
tabu,
xcolor
}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=blue,
urlcolor=blue
}
\cfoot{chicken \pagemark}
\ohead{}
\pagestyle{scrheadings}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\newfontfamily\XITS{XITS}
\newfontfamily\TGChorus{TeX Gyre Chorus}
\usepackage{chickenize}
\chickenizesetup{
rainbow_step=0.3
}
\begin{document}
{\hspace*{-2cm}{\scalebox{.2}{\drawchicken\hspace*{20cm}\reflectbox{\chickenizesetup{drawwidth=5}\drawunicorn}}
\hfill\hfill \parbox{6.3cm}{{\TGChorus{\Large »\,}\large The Monty Pythons, were they \TeX~users,\\\hspace*{.2em} could have written the chickenize macro.{\Large \textit «}}\\[1ex]
\hspace*{4cm}\small Paul Isambert}\kern-2.5cm
}
\begin{center}
\rainbowcolor
\fontsize{55}{0}\selectfont \fontspec[Letters=Random]{Punk Nova}
chickenize
\end{center}
\unrainbowcolor
\centerline{v0.3a}
\centerline{\hspace*{2cm} Arno L. Trautmann {\Large \ALT}}
\centerline{\href{mailto:[email protected]}{[email protected]}}
\kern.5cm
\textcolor{blue}{\Large How to read this document.}
This is the documentation of the package |chickenize|. It allows manipulations of any Lua\TeX\ document\footnote{The code is based on pure Lua\TeX\ features, so don't even try to use it with any other \TeX\ flavour. The package is (partially) tested under plain Lua\TeX\ and (fully) under Lua\LaTeX. If you tried using it with Con\TeX t, please share your experience, I will gladly try to make it compatible!} exploiting the possibilities offered by the callbacks that influence line breaking (and~some other stuff). Most of this package's content is just for fun and educational use, but there are also some functions that can be useful in a normal production document.
The table on the next page shortly informs you about some of your possibilities and provides links to the (documented) Lua functions. The \TeX\ interface is presented \hyperlink{texinterface}{below}.
The documentation of this package is far from being well-readable, consistent or even complete. This is caused either by lack of time or priority. If you miss anything that should be documented or if you have suggestions on how to increase the readability of the descriptions, please let me know.
For a better understanding of what's going on in the code of this package, there is a small \hyperlink{tutorial}{tutorial} below that explains shortly the most important features used here.
\emph{Attention}: This package is under development and everything presented here might be subject to incompatible changes. If, by any reason, you decide to use this package for an important document, please make a local copy of the source code and use that. This package will only be considered stable and long-term compatible should it reach version 1.0.
If you have any suggestions or comments, just drop me a mail, I’ll be happy to get any response! The latest source code is hosted on github: \url{https://github.com/alt/chickenize}. Feel free to comment or report bugs there, to fork, pull, etc.
\vfill
\small\noindent
\fbox{\parbox{.97\textwidth}{
This package is copyright © 2021 Arno L. Trautmann. It may be distributed and/or
modified under the conditions of the LaTeX Project Public License, either version 1.3c
of this license or (at your option) any later version. This work has the LPPL maintenance status ‘maintained’.}}
\vspace*{1cm}
\newpage
\section*{\rainbowcolor For the Impatient:}
\unrainbowcolor
A small and incomplete overview of the functionalities offered by this package.\footnote{If you notice that something is missing, please help me improving the documentation!} Of course, the label “complete nonsense” depends on what you are doing … The links will take you to the source code, while a more complete list with explanations is given \hyperlink{texinterface}{further below}.
\noindent
\tabulinesep=.5ex
%% this is a temporary fix for longtabu – longtable changed internal box names from \@ne to \LT@gbox, needs to be adapted in tabu. So long we have to use a workaround:
\makeatletter
\def\tabuendlongtrial{%
\LT@echunk \global\setbox\LT@gbox \hbox{\unhbox\LT@gbox}\kern\wd\LT@gbox
\LT@get@widths
}%
\makeatother
\begin{longtabu} to .95\textwidth [c]{lX[j]}
\hbox to 0cm{\bfseries \hspace*{2cm} maybe useful functions}\\
\cmidrule(lr){1-2}
\hyperref[sec:colorstretch]{colorstretch} & shows grey boxes that visualise the badness and font expansion line-wise\\
\hyperref[sec:letterspaceadjust]{letterspaceadjust} & improves the greyness by using a small amount of letterspacing\\
\hyperref[sec:substitutewords]{substitutewords} & replaces words by other words (chosen by the user)\\
\hyperref[sec:variantjustification]{variantjustification} & Justification by using glyph variants\\
\hyperref[sec:suppressonecharbreak]{suppressonecharbreak} & suppresses linebreaks after single-letter words\\
\addlinespace\addlinespace
\hbox to 0cm{\bfseries \hspace*{2cm} less useful functions} \\
\cmidrule(lr){1-2}
\hyperref[sec:boustrophedon]{boustrophedon} & invert every second line in the style of archaic greek texts\\
\hyperref[sec:countglyphs]{countglyphs} & counts the number of glyphs in the whole document\\
\hyperref[sec:countwords]{countwords} & counts the number of words in the whole document\\
\hyperref[sec:leetspeak]{leetspeak} & translates the (latin-based) input into 1337 5p34k\\
\hyperref[sec:medievalumlaut]{medievalumlaut} & \medievalumlaut changes each umlaut to normal glyph plus “e” above it: äöü\\
\hyperref[sec:randomuclc]{randomuclc} & \unmedievalumlaut alternates randomly between uppercase and lowercase\\
\hyperref[sec:rainbowcolor]{rainbowcolor} & changes the color of letters slowly according to a rainbow\\
\hyperref[sec:randomcolor]{randomcolor} & prints every letter in a random color\\
\hyperref[sec:tabularasa]{tabularasa} & removes every glyph from the output and leaves an empty document\\
\hyperref[sec:uppercasecolor]{uppercasecolor} & makes every uppercase letter colored\\
\addlinespace\addlinespace
\hbox to 0cm{\bfseries \hspace*{2cm} complete nonsense} \\
\cmidrule(lr){1-2}
\hyperref[sec:chickenize]{chickenize} & replaces every word with “chicken” (or user-adjustable words)\\
\hyperref[sec:drawchicken]{drawchicken} & draws a nice chicken with random, “hand-sketch”-type lines\\
\hyperref[sec:drawcov]{drawcov} & draws a corona virus\\
\hyperref[sec:drawchicken]{drawhorse} & draws a horse\\
\hyperref[sec:guttenbergenize]{guttenbergenize} & deletes every quote and footnotes\\
\hyperref[sec:hammertime]{hammertime} & U can't touch this!\\
\hyperref[sec:italianize]{italianize} & Mamma mia!! \\
\hyperref[sec:italianizerandwords]{italianizerandwords} & Will put the word order in a sentence at random. (tbi)\\
\hyperref[sec:kernmanipulate]{kernmanipulate} & manipulates the kerning (tbi)\\
\hyperref[sec:matrixize]{matrixize} & replaces every glyph by its ASCII value in binary code\\
\hyperref[sec:randomerror]{randomerror} & just throws random (La)\TeX\ errors at random times (tbi)\\
\hyperref[sec:randomfonts]{randomfonts} & changes the font randomly between every letter\\
\hyperref[sec:randomchars]{randomchars} & randomizes the (letters of the) whole input\\
\bottomrule
\end{longtabu}
\newpage
\tableofcontents
\newpage
\part{User Documentation}
\section{How It Works}
We make use of Lua\TeX s callbacks, especially the |pre_line|\-|break_filter| and the |post_line|\-|break_filter|. Hooking a function into these, we can nearly arbitrarily change the content of the document. If the changes should be on the input-side (e.\,g.~replacing words with |chicken|), one can use the |pre_linebreak_filter|. However, changes like inserting color are best made after the linebreak is finalized, so |post_linebreak_filter| is to be preferred for such things.
All functions traverse the node list of a paragraph and manipulate the nodes' properties (like |.font| or |.char|) or insert nodes (like color push/pop nodes) and return this changed node list.
\hypertarget{texinterface}{}
\section{Commands – How You Can Use It}
There are several ways to make use of the \emph{chickenize} package – you can either stay on the \TeX\ side or use the Lua functions directly. In fact, the \TeX\ macros are in most cases simple wrappers around the functions.
\subsection{\TeX\ Commands – Document Wide}
You have a number of commands at your hand, each of which does some manipulation of the input or output. In fact, the code is simple and straightforward, but be careful, especially when combining things. Apply features step by step so your brain won't be damaged …
The effect of the commands can be influenced, not with arguments, but only via the |\chickenizesetup| described \hyperlink{adjustment}{below}. The links provided here will bring you to the more relevant part of the implementation, i.\,e.~either the \TeX\ code or the Lua code, depending on what is doing the main job. Mostly it's the Lua part. If no link is provided then the command is mostly just an adaption of another one. I'll try to get this consistent somehow, but for now, it's not.
\begin{description}
\def\command#1{\item[{\hyperref[sec:#1]{\textbackslash #1}}]}
\command{allownumberincommands} Normally, you cannot use numbers as part of a control sequence (or, command) name. This makes perfect sense and is good as it is. However, just to raise awareness to this, we provide a command here that changes the chategory codes of numbers 0–9 to 11, i.\,e.~normal character. So they \emph{can} be used in command names. However, this will break many packages, so do \emph{not} expect anything to work! At least use it \emph{after} all packages are loaded.
\command{boustrophedon} Reverts every second line. This imitates archaic greek writings where one line was right-to-left, the next one left-to-right etc.\footnote{\url{en.wikipedia.org/wiki/Boustrophedon}} Interestingly, also every glyph was adapted to the writing direction, so all glyphs are inverted in the right-to-left lines. Actually, there are two versions of this command that differ in their implementation: |\boustrophedon| rotates the whole line, while |\boustrophedonglyphs| changes the writing direction and reverses glyph-wise. The second one takes much more compilation time, but may be more reliable. A Rongorongo\footnote{\url{en.wikipedia.org/wiki/Rongorongo}} similar style boustrophedon is available with |\boustrophedoninverse| or |\rongorongonize|, where subsequent lines are rotated by 180° instead of mirrored.
\command{countglyphs} \textcolor{blue}{\texttt{\textbackslash countwords}} Counts every printed character (or word, respectively) that appears in anything that is a paragraph. Which is quite everything, in fact, \emph{except} math mode! The total number of glyphs/words will be printed at the end of the log file/console output. For glyphs, also the number of use for every letter is printed separately.
\command{chickenize} Replaces every word of the input with the word “chicken”. Maybe sometime the replacement will be made configurable, but up to now, it's only chicken. To be a bit less static, about every 10\textsuperscript{th} chicken is uppercase. However, the beginning of a sentence is not recognized automatically.\footnote{If you have a nice implementation idea, I'd love to include this!}
\command{drawchicken} Draws a chicken based on some low-level lua drawing code. Each stroke is parameterized with random numbers so the chicken will always look different.
\command{colorstretch} Inspired by Paul Isambert's code, this command prints boxes instead of lines. The greyness of the first (left-hand) box corresponds to the badness of the line, i.\,e. it is a measure for how much the space between words has been extended to get proper paragraph justification. The second box on the right-hand side shows the amount of stretching/shrinking when font expansion is used. Together, the greyness of both boxes indicate how well the greyness is distributed over the typeset page.
\command{dubstepize} wub wub wub wub wub BROOOOOAR WOBBBWOBBWOBB BZZZRRRRRRROOOOOOAAAAA … (inspired by \url{http://www.youtube.com/watch?v=ZFQ5EpO7iHk} and \url{http://www.youtube.com/watch?v=nGxpSsbodnw})
\command{dubstepenize} synomym for |\dubstepize| as I am not sure what is the better name. Both macros are just a special case of |chickenize| with a very special “zoo” … there is no |\undubstepize| – once you go dubstep, you cannot go back …
\command{explainbackslashes} A small list that gives hints on how many |\| characters you actually need for a backslash. It's supposed to be funny. At least my head thinks it's funny. Inspired (and mostly copied from, actually) xkcd.
\command{gameofchicken} This is a temptative implementation of Conway's classic Game of Life. This is actually a rather powerful code with some choices for you. The game itself is played on a matrix in Lua and can be output either on the console (for quick checks) or in a pdf. The latter case needs a LaTeX document, and the packages |geometry|, |placeat|, and |graphicx|. You can choose which \LaTeX\ code represents the cells or you take the pre-defined – a \kern-1.5em\raisebox{.75ex}{\scalebox{0.075}{\drawchicken}}\kern2.5em , of course! Additionally, there are |anticells| which is basically just a second set of cells. However, they can interact, and you have full control over the rules, i.\,e.~how many neighbors a cell or anticell may need to be born, die, or stay alive, and what happens if cell and anticell collide. See \hyperlink{sec:GOC_options}{below} for parameters; all of them start with GOC for clarity.
\command{gameoflife} Try it.
\command{hammertime} STOP! —— Hammertime!
\command{leetspeak} Translates the input into 1337 speak. If you don't understand that, learn it, n00b.
\command{matrixize} Replaces every glyph by a binary representation of its ASCII value.
\command{medievalumlaut} Changes every lowercase umlaut into the corresponding vocale glyph with a small “e” glyph above it to show the origins of the german umlauts coming from ae, oe, ue. Text-variant may follow.
\command{nyanize} A synonym for |rainbowcolor|.
\command{randomerror} Just throws a random \TeX\ or \LaTeX\ error at a random time during the compilation. I have quite no idea what this could be used for.
\command{randomuclc} Changes every character of the input into its uppercase or lowercase variant. Well, guess what the “random” means …
\command{randomfonts} Changes the font randomly for every character. If no parameters are given, all fonts that have been loaded are used, especially including math fonts.
\command{randomcolor} Does what its name says.
\command{rainbowcolor} Instead of random colors, this command causes the text color to change gradually according to the colors of a rainbow. Do not mix this with |randomcolor|, as that doesn't make any sense.
\command{relationship} Draws the relationship. A ship made of relations.
\command{pancakenize} This is a dummy command that does nothing. However, every time you use it, you owe a pancake to the package author. You can either send it via mail or bring it to some (local) \TeX\ user's group meeting.
\command{substitutewords} You have to specify pairs of words by using |\addtosubstitutions{word1}{word2}|. Then call |\substitutewords| (or the other way round, doesn't matter) and each occurance of |word1| will be replaced by |word2|. You can add replacement pairs by repeated calls to |\addtosubstitutions|. Take care! This function works with the input stream directly, therefore it does \emph{not} work on text that is inserted by macros, but it \emph{will} work on macro names itself! This way, you may use it to change macros (or environments) at will. Bug or feature? I'm not sure right now …
\command{suppressonecharbreak} \TeX~normally does not suppress a linebreak after words with only one character (“I“, “a” etc.) This command suppresses line breaks. It is very similar to the code provided by the |impnattypo| package and based on the same ideas. However, the code in |chickenize| has been written before the author knew |impnattypo|, and the code differs a bit, might even be a bit faster. Well, test it!
\command{tabularasa} Takes every glyph out of the document and replaces it by empty space of the same width. That could be useful if you want to hide some part of a text or similar. The |\text|-version is most likely more useful.
\command{uppercasecolor} Makes every uppercase character in the input colored. At the moment, the color is randomized over the full rgb scale, but that will be adjustable once options are well implemented.
\command{variantjustification} For special document types, it might be mandatory to have a fixed interword space. If you still want to have a justified type area, there must be another kind of stretchable material – one version realized by this command is using wide variants of glyphs to fill the remaining space. As the glyph substitution takes place randomly, this does \emph{not} provide the optimum justification, as this would take up much computation power.
\end{description}
\subsection{How to Deactivate It}
Every command has a |\un|-version that deactivates its functionality. So once you used |\chickenize|, it will chickenize the whole document up to |\unchickenize|. However, the paragraph in which |\unchickenize| appears, will \emph{not} be chickenized. The same is true for all other manipulations. Take care that you don't |\un|-anything bevor activating it, as this will result in an error.\footnote{Which is so far not catchable due to missing functionality in luatexbase.}
If you want to manipulate only a part of a paragraph, you will have to use the corresponding |\text|-version of the function, see below. However, feel free to set and unset every function at will at any place in your document.
\subsection{\texttt{\textbackslash text}-Versions}
The functions provided by this package might be much more useful if applied only to a short sequence of words or single words instead of the whole document or paragraph. Therefore, most of the above-mentioned commands have\footnote{If they don't have, I did miss that, sorry. Please inform me about such cases.} a |\text|-version that takes an argument. |\textrandomcolor{foo}| results in a colored |foo| while the rest of the document remains unaffected. However, to achieve this effect, still the whole node list has to be traversed. Thus, it may slow down the compilation of your document, even if you use |\textrandomcolor| only once. Fortunately, the effect is very small and mostly negligible.\footnote{On a 500 pages text-only \LaTeX\ document the dilation is on the order of 10\% with |textrandomcolor|, but other manipulations can take much more time. However, you are not supposed to make such long documents with |chickenize|!}
Please don't fool around by mixing a |\text|-version with the non-|\text|-version. If you feel like it and are not pleased with the result, it is up to \emph{you} to provide a stable and working solution.
\subsection{Lua functions}
As all features are implemented on the Lua side, you can use these functions independently. If you do so, please consult the corresponding subsections in the \hyperlink{sec:luamodule}{implementation} part, because there are some variables that can be adapted to your need.
You can use the following code inside a |\directlua| statement or in a |luacode| environment (or the corresponding thing in your format):
\begin{verbatim}
luatexbase.add_to_callback("pre_linebreak_filter",chickenize,"chickenize")
\end{verbatim}
Replace |pre| by |post| to register into the post linebreak filter. The second argument (here: |chickenize|) specifies the function name; the available functions are listed below. You can supply a label as you like in the third argument. The fourth and last argument, which is omitted in the example, determines the order in which the functions in the callback are used. If you have no fancy stuff going on, you can safely use |1|.
\hypertarget{adjustment}{}
\section{Options – How to Adjust It}
There are several ways to change the behaviour of |chickenize| and its macros. Most of the options are Lua variables and can be set using |\chickenizesetup|. But be \emph{careful!} The argument of |\chickenizesetup| is passed directly to Lua, therefore you are \emph{not} using a comma-separated key-value list, but uncorrelated Lua commands. The argument must have the syntax |{randomfontslower = 1| |randomfontsupper = 0}| instead of |{randomfontslower = 1,| |randomfontsupper = 0}|. Alright?
However, |\chickenizesetup| is a macro on the \TeX\ side meaning that you can use \emph{only} |%| as comment string. If you use |--|, all of the argument will be ignored as \TeX\ does not pass an eol to |\directlua|. If you don't understand that, just ignore it and go on as usual.
The following list tries to kind of keep track of the options and variables. There is no guarantee for completeness, and if you find something that is missing or doesn't work as described here, please inform me!
\def\arg#1{\textcolor{red}{\ttfamily <#1>}}
\def\opt#1{\textcolor{blue}{\ttfamily #1}}
\def\default#1{\textcolor{black}{\ttfamily #1}}
\begin{description}
\item[\opt{randomfontslower}, \opt{randomfontsupper} = \arg{int}] These two integer variables determine the span of fonts used for the font randomization. Just play around with them a bit to find out what they are doing.
\subsection{options for chickenization}
\item[\opt{chickenstring} = \arg{table}] The string that is printed when using |\chickenize|. In fact, |chickenstring| is a table which allows for some more random action. To specify the default string, say |chickenstring[1] = 'chicken'|. For more than one animal, just step the index:\\
|chickenstring[2] = 'rabbit'|. All existing table entries will be used randomly. Remember that we are dealing with Lua strings here, so use |' '| to mark them. (|" "| can cause problems with |babel|.)
\item[\opt{chickenizefraction} = \arg{float} \default{1}] Gives the fraction of words that get replaced by the |chickenstring|. The default means that every word is substituted. However, with a value of, say, |0.0001|, only one word in ten thousand will be |chickenstring|. |chickenizefraction| must be specified \emph{after} |\begin{document}|. No idea, why …
\item[\opt{chickencount} = \arg{bool} \default{true}] Activates the counting of substituted words and prints the number at the end of the terminal output.
\item[\opt{colorstretchnumbers} = \arg{bool} \default{false}] If true, the amount of stretching or shrinking of each line is printed into the margin as a green, red or black number.
\item[\opt{chickenkernamount} = \arg{int}] The amount the kerning is set to when using |\kernmanipulate|.
\item[\opt{chickenkerninvert} = \arg{bool}] If set to true, the kerning is inverted (to be used with |\kernmanipulate|).
\item[\opt{drawwidth} = \arg{float} \default{1}] Defines the widths of the sloppy drawings of chickens, horses, etc.
\item[\opt{leettable} = \arg{table}] From this table, the substitution for 1337 is taken. If you want to add or change an entry, you have to provide the unicode numbers of the characters, e.\,g. |leettable[101] = 50| replaces every |e| (|101|) with the number |3| (|50|).
\item[\opt{uclcratio} = \arg{float} \default{0.5}] Gives the fraction of uppercases to lowercases in the |\randomuclc| mode. A higher number (up to 1) gives more uppercase letters. Guess what a lower number does.
\item[\opt{randomcolor\_grey} = \arg{bool} \default{false}] For a printer-friendly version, this offers a grey scale instead of an rgb value for |\randomcolor|.
\item[\opt{rainbow\_step} = \arg{float} \default{0.005}] This indicates the relative change of color using the rainbow functionality. A value of |1| changes the color in one step from red to yellow, while a value of |0.005| takes 200 letters for the transition to be completed. Useful values are below |0.05|, but it depends on the amount of text. The longer the text and the lower the |step|, the nicer your rainbow will be.
\item[\opt{Rgb\_lower}, \opt{rGb\_upper} = \arg{int}] To specify the color space that is used for |\randomcolor|, you can specify six values, the upper and lower value for each color. The uppercase letter in the variable denotes the color, so |rGb_upper| gives the upper value for green etc. Possible values are between |1| and |254|. If you enter anything outside this range, your PDF will become invalid and break. For grey scale, use |grey_lower| and |grey_upper|, with values between |0| (black) and |1000| (white), included. Default is |0| to |900| to prevent white letters.
\item[\opt{keeptext} = \arg{bool} \default{false}] This is for the |\colorstretch| command. If set to |true|, the text of your document will be kept. This way, it is easier to identify bad lines and the reason for the badness.
\item[\opt{colorexpansion} = \arg{bool} \default{true}] If |true|, two bars are shown of which the second one denotes the font expansion. Only useful if font expansion is used. (You \emph{do} use font expansion, don’t you?)
\end{description}
\subsection{Options for Game of Chicken}\hypertarget{sec:GOC_options}{test}
This deserves a separate section since there are some more options and they need some explanation. So here go the parameters for the GOC:
\begin{description}
\item[\opt{GOCrule\_live} = \arg{\{int,int,...\}} \default{\{2,3\}}] This gives the number of neighbors for an existing cell to keep it alive. This is a list, so you can say |\chickenizesetup{GOCrule_live = {2,3,7}}| or similar.
\item[\opt{GOCrule\_spawn} = \arg{\{int,int,...\}} \default{\{3\}}] The number of neighbors to spawn a new cell.
\item[\opt{GOCrule\_antilive} = \arg{int} \default{2,3}] The number of neighbors to keep an anticell alive.
\item[\opt{GOCrule\_antispawn} = \arg{int} \default{3}] The number of neighbors to spawn a new anticell.
\item[\opt{GOCcellcode} = \arg{string} \default {"\\scalebox\{0.03\}\{\\drawchicken\}"}] The \LaTeX\ code for graphical representation of a living cell. You can use basically any valid \LaTeX\ code in here. A chicken is the default, of course.
\item[\opt{GOCanticellcode} = \arg{string} \default {"O"}] The \LaTeX\ code for graphical representation of a living anticell.
\item[\opt{GOCx} = \arg{int} \default{100}] Grid size in |x| direction (vertical).
\item[\opt{GOCy} = \arg{int} \default{100}] Grid size in |y| direction (horizontal).
\item[\opt{GOCiter} = \arg{int} \default{150}] Number of iterations to run the game.
\item[\opt{GOC\_console} = \arg{bool} \default{false}] Activate output on the console.
\item[\opt{GOC\_pdf} = \arg{bool} \default{true}] Activate output in the pdf.
\item[\opt{GOCsleep} = \arg{int} \default{0}] Wait after one cycle of the game. This helps especially on the console, or for debugging. By default no wait time is added.
\item[\opt{GOCmakegif} = \arg{bool} \default{false}] Produce a gif. This requires the command line tool |convert| since I use it for the creation. If you have troubles with this feel free to contact me.
\item[\opt{GOCdensity} = \arg{int} \default{100}] Defines the density of the gif export. 100 is quite dense and it might take quite some time to get your gif done.
\end{description}
I recommend to use the |\gameofchicken| with a code roughly like this:
\begin{verbatim}
\documentclass{scrartcl}
\usepackage{chickenize}
\usepackage[paperwidth=10cm,paperheight=10cm,margin=5mm]{geometry}
\usepackage{graphicx}
\usepackage{placeat}
\placeatsetup{final}
\begin{document}
\gameofchicken{GOCiter=50}
%\gameofchicken{GOCiter=50 GOCmakegif = true}
% \directlua{ os.execute("gwenview test.gif")} % substitute your filename
\end{document}
\end{verbatim}
Keep in mind that for convenience |\gameofchicken{}| has one argument which is equivalent to using |\chickenizesetup{}| and actually just executes the argument as Lua code …
\clearpage
\part[Tutorial]{Tutorial\hypertarget{tutorial}}
I thought it might be helpful to add a small tutorial to this package as it is mainly written with instructional purposes in mind. However, the following is \emph{not} intended as a comprehensive guide to Lua\TeX. It's just to get an idea how things work here. For a deeper understanding of Lua\TeX\ you should consult both the Lua\TeX\ manual and some introduction into Lua proper like “Programming in Lua“. (See the section \hyperref[sec:literature]{Literature} at the end of the manual.)
\section{Lua code}
The crucial novelty in Lua\TeX\ is the first part of its name: The programming language Lua. One can use nearly any Lua code inside the commands |\directlua{}| or |\latelua{}|. This alleviates simple tasks like calculating a number and printing it, just as if it was entered by hand:
\begin{verbatim}
\directlua{
a = 5*2
tex.print(a)
}
\end{verbatim}
A number of additions to the Lua language renders it particularly suitable for \TeX ing, especially the |tex.| library that offers access to \TeX\ internals. In the simple example above, the function |tex.print()| inserts its argument into the \TeX\ input stream, so the result of the calcuation (10) is printed in the document.
Larger parts of Lua code should not be embedded in your \TeX\ code, but rather in a separate file. It can then be loaded using
\begin{verbatim}
\directlua{dofile("filename")}
\end{verbatim}
If you use Lua\LaTeX, you can also use the |luacode| environment from the eponymous package.
\section{callbacks}
While Lua code can be inserted using |\directlua| at any point in the input, a very powerful concept allows to change the way \TeX\ behaves: The \emph{callbacks}. A callback is a point where you can hook into \TeX's working and do anything to it that may make sense – or not. (Thus maybe breaking your document completely …)
Callbacks are employed at several stages of \TeX's work – e.\,g. for font loading, paragraph breaking, shipping out etc. In this package, we make heavy use of mostly two callbacks: The |pre_linebreak_filter| and the |post_linebreak| filter. These callbacks are called just before (or after, resp.) \TeX\ breaks a paragraph into lines. Normally, these callbacks are empty, so they are a great playground. In between these callbacks, the |linebreak_filter| takes care of \TeX's line breaking mechanism. We won't touch this as I have no idea of what's going on there ;)
\section{How to use a callback}
The normal way to use a callback is to “register” a function in it. This way, the function is called each time the callback is executed. Typically, the function takes a node list (see below) as an argument, does something with it, and returns it. So a basic use of the |post_linebreak_filter| would look like:
\begin{verbatim}
function my_filter(head)
return head
end
callback.register("post_linebreak_filter",my_filter)
\end{verbatim}
The function |callback.register| takes the name of the callback and your new function. However, there are some reasons why we avoid this syntax here. Instead, we rely on the function |luatexbase.add_to_callback|. This is provided by the \LaTeX\ kernel table |luatexbase| which was initially a package by Manuel Pégourié-Gonnard and Élie Roux.\footnote{Since the late 2015 release of \LaTeX, the package has not to be loaded anymore since the functionality is absorbed by the kernel. Plain\TeX~users can load the |ltluatex| file which provides the needed functionality.} This function has a more extended syntax:
\begin{verbatim}
luatexbase.add_to_callback("post_linebreak_filter",my_filter,"a fancy new filter")
\end{verbatim}
The third argument is a name you can (have to) give to your function in the callback. That is necessary because the package also allows for removing functions from callbacks, and then you need a unique identifier for the function:
\begin{verbatim}
luatexbase.remove_from_callback("post_linebreak_filter","a fancy new filter")
\end{verbatim}
You have to consult the Lua\TeX\ manual to see what functionality a callback has when executed, what arguments it expects and what return values have to be given.
Everything I have written here is not the complete truth – please consult the Lua\TeX\ manual and the |luatexbase| section in the \LaTeX\ kernel documentation for details!
\section{Nodes}
Essentially everything that Lua\TeX\ deals with are nodes – letters, spaces, colors, rules etc. In this package, we make heavy use of different types of nodes, so an understanding of the concept is crucial for the functionality.
A node is an object that has different properties, depending on its type which is stored in its |.id| field. For example, a node of type |glyph| has |id| 27 (up to Lua\TeX~0.80, it was 37) has a number |.char| that represents its unicode codepoint, a |.font| entry that determines the font used for this glyph, a |.height|, |.depth| and |.width| etc.
Also, a node typically has a non-empty field |.next| and |.prev|. In a list, these point to the – guess it – next or previous node. Using this, one can walk over a list of nodes step by step and manipulate the list.
A more convenient way to adress each node of a list is the function |node.traverse(head)| which takes as first argument the first node of the list. However, often one wants to adress only a certain type of nodes in a list – e.\,g. all glyphs in a vertical list that also contains glue, rules etc. This is achieved by calling the function |node.traverse_id(GLYPH,head)|, with the first argument giving the respective id of the nodes.\footnote{GLYPH here stands for the id that the glyph node type has. This number can be achieved by calling |GLYPH = nodeid("glyph")| which will result in the correct number independent of the Lua\TeX~version. We will use this substitute throughout this document.}
The following example removes all characters “e” from the input just before paragraph breaking. This might not make any sense, but it is a good example anyways:
\begin{verbatim}
function remove_e(head)
for n in node.traverse_id(GLYPH,head) do
if n.char == 101 then
node.remove(head,n)
end
end
return head
end
luatexbase.add_to_callback("pre_linebreak_filter",remove_e,"remove all letters e")
\end{verbatim}
Now, don't read on, but try out this code by yourself! Change the number of the character to be removed, try to play around a bit. Also, try to remove the spaces between words. Those are glue nodes – look up their id in the Lua\TeX\ manual! Then, you have to remove the |if n.char| condition on the third line of the listing, because glue nodes lack a |.char| field. If everything works, you should have an input consisting of only one long word. Congratulations!
The |pre_linebreak_filter| is especially easy because its argument (here called |head|) is just one horizontal list. For the |post_linebreak_filter|, one has to traverse a whole vertical stack of horizontal lists, vertical glue and other material. See some of the functions below to understand what is necessary in this more complicated case.
\section{Other things}
Lua is a very intuitive and simple language, but nonetheless powerful. Just two tips: use local variables if possible – your code will be much faster. For this reason we prefer synonyms like |nodetraverseid = node.traverse_id| instead of the original names.
Also, Lua is kind of built around tables. Everything is best done with tables!
The namespace of the chickenize package is \emph{not} consistent. Please don't take anything here as an example for good Lua coding, for good \TeX ing or even for good Lua\TeX ing. It's not. For high quality code check out the code written by Hans Hagen or other professionals. Once you understand the package at hand, you should be ready to go on and improve your knowledge. After that, you might come back and help me improve this package – I'm always happy for any help ☺
\DocInput{chickenize.dtx}
\end{document}
%</driver>
%<*tex>
% \fi
% \clearpage
%\part{Implementation}
%\label{sec:implementation}
%\section{\TeX\ file}
% This file is more-or-less a dummy file to offer a nice interface for the functions. Basically, every macro registers a function of the same name in the corresponding callback. The |un|-macros later remove these functions. Where it makes sense, there are |text|-variants that activate the function only in a certain area of the text, by means of Lua\TeX's attributes.
%
% For (un)registering, we use the |luatexbase| \LaTeX\ kernel functionality. Then, the |.lua| file is loaded which does the actual work. Finally, the \TeX\ macros are defined as simple |\directlua| calls.
%
% The Lua file is not found by using a simple |dofile("chickenize.lua")| call, but we have to use kpse's |find_file|.
% \begin{macrocode}
\directlua{dofile(kpse.find_file("chickenize.lua"))}
\def\ALT{%
\bgroup%
\fontspec{Latin Modern Sans}%
A%
\kern-.375em \raisebox{.65ex}{\scalebox{0.3}{L}}%
\kern.03em \raisebox{-.99ex}{T}%
\egroup%
}
% \end{macrocode}
% \subsection{allownumberincommands}\label{sec:allownumberincommands}
% \begin{macrocode}
\def\allownumberincommands{
\catcode`\0=11
\catcode`\1=11
\catcode`\2=11
\catcode`\3=11
\catcode`\4=11
\catcode`\5=11
\catcode`\6=11
\catcode`\7=11
\catcode`\8=11
\catcode`\9=11
}
\def\BEClerize{
\chickenize
\directlua{
chickenstring[1] = "noise noise"
chickenstring[2] = "atom noise"
chickenstring[3] = "shot noise"
chickenstring[4] = "photon noise"
chickenstring[5] = "camera noise"
chickenstring[6] = "noising noise"
chickenstring[7] = "thermal noise"
chickenstring[8] = "electronic noise"
chickenstring[9] = "spin noise"
chickenstring[10] = "electron noise"
chickenstring[11] = "Bogoliubov noise"
chickenstring[12] = "white noise"
chickenstring[13] = "brown noise"
chickenstring[14] = "pink noise"
chickenstring[15] = "bloch sphere"
chickenstring[16] = "atom shot noise"
chickenstring[17] = "nature physics"
}
}
\def\boustrophedon{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",boustrophedon,"boustrophedon")}}
\def\unboustrophedon{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","boustrophedon")}}
\def\boustrophedonglyphs{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",boustrophedon_glyphs,"boustrophedon_glyphs")}}
\def\unboustrophedonglyphs{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","boustrophedon_glyphs")}}
\def\boustrophedoninverse{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",boustrophedon_inverse,"boustrophedon_inverse")}}
\def\unboustrophedoninverse{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","boustrophedon_inverse")}}
\def\bubblesort{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",bubblesort,"bubblesort")}}
\def\unbubblesort{
\directlua{luatexbase.remove_from_callback("bubblesort","bubblesort")}}
\def\chickenize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",chickenize,"chickenize")
luatexbase.add_to_callback("start_page_number",
function() texio.write("["..status.total_pages) end ,"cstartpage")
luatexbase.add_to_callback("stop_page_number",
function() texio.write(" chickens]") end,"cstoppage")
luatexbase.add_to_callback("stop_run",nicetext,"a nice text")
}
}
\def\unchickenize{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","chickenize")
luatexbase.remove_from_callback("start_page_number","cstartpage")
luatexbase.remove_from_callback("stop_page_number","cstoppage")}}
\def\coffeestainize{ %% to be implemented.
\directlua{}}
\def\uncoffeestainize{
\directlua{}}
\def\colorstretch{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",colorstretch,"stretch_expansion")}}
\def\uncolorstretch{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","stretch_expansion")}}
\def\countglyphs{
\directlua{
counted_glyphs_by_code = {}
for i = 1,10000 do
counted_glyphs_by_code[i] = 0
end
glyphnumber = 0 spacenumber = 0
luatexbase.add_to_callback("post_linebreak_filter",countglyphs,"countglyphs")
luatexbase.add_to_callback("stop_run",printglyphnumber,"printglyphnumber")
}
}
\def\countwords{
\directlua{wordnumber = 0
luatexbase.add_to_callback("pre_linebreak_filter",countwords,"countwords")
luatexbase.add_to_callback("stop_run",printwordnumber,"printwordnumber")
}
}
\def\detectdoublewords{
\directlua{
luatexbase.add_to_callback("post_linebreak_filter",detectdoublewords,"detectdoublewords")
luatexbase.add_to_callback("stop_run",printdoublewords,"printdoublewords")
}
}
\def\dosomethingfunny{
%% should execute one of the “funny” commands, but randomly. So every compilation is completely different. Maybe a list of commands could be specified to exclude total nonesense-functions. Maybe also on a per-paragraph-basis?
}
\def\dubstepenize{
\chickenize
\directlua{
chickenstring[1] = "WOB"
chickenstring[2] = "WOB"
chickenstring[3] = "WOB"
chickenstring[4] = "BROOOAR"
chickenstring[5] = "WHEE"
chickenstring[6] = "WOB WOB WOB"
chickenstring[7] = "WAAAAAAAAH"
chickenstring[8] = "duhduh duhduh duh"
chickenstring[9] = "BEEEEEEEEEW"
chickenstring[10] = "DDEEEEEEEW"
chickenstring[11] = "EEEEEW"
chickenstring[12] = "boop"
chickenstring[13] = "buhdee"
chickenstring[14] = "bee bee"
chickenstring[15] = "BZZZRRRRRRROOOOOOAAAAA"
chickenizefraction = 1
}
}
\let\dubstepize\dubstepenize
\def\explainbackslashes{ %% inspired by xkcd #1638
{\tt\noindent
\textbackslash escape character\\
\textbackslash\textbackslash line end or escaped escape character in tex.print("")\\
\textbackslash\textbackslash\textbackslash real, real backslash\\
\textbackslash\textbackslash\textbackslash\textbackslash line end in tex.print("")\\
\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash elder backslash \\
\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash backslash which escapes the screen and enters your brain\\
\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash backslash so real it transcends time and space \\
\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash backslash to end all other text\\
\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash\textbackslash... the true name of Ba'al, the soul-eater}
}
\def\francize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",francize,"francize")}}
\def\unfrancize{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter",francize)}}
% \end{macrocode}
% Game of life – did you expect something else? lol.
% \begin{macrocode}
\def\gameoflife{
Your Life Is Tetris. Stop Playing It Like Chess.
}
% \end{macrocode}
% This is just the activation of the command, the typesetting is done in the Lua code/loop as explained below. Use this macro \emph{after} |\begin{document}|. Remember that |graphicx| and |placeat| are required!
% \begin{macrocode}
\def\gameofchicken#1{\directlua{
GOCrule_live = {2,3}
GOCrule_spawn = {3}
GOCrule_antilive = {2,3}
GOCrule_antispawn = {3}
GOCcellcode = "\\scalebox{0.03}{\\drawchicken}"
GOCcellcode = "\\scalebox{0.03}{\\drawcov}"
GOCx = 100
GOCy = 100
GOCiter = 150
GOC_console = false
GOC_pdf = true
GOCsleep = 0
GOCdensity = 100
#1
gameofchicken()
if (GOCmakegif == true) then
luatexbase.add_to_callback("wrapup_run",make_a_gif,"makeagif")
end
}}
\let\gameofchimken\gameofchicken % yeah, that had to be.
\def\guttenbergenize{ %% makes only sense when using LaTeX
\AtBeginDocument{
\let\grqq\relax\let\glqq\relax
\let\frqq\relax\let\flqq\relax
\let\grq\relax\let\glq\relax
\let\frq\relax\let\flq\relax
%
\gdef\footnote##1{}
\gdef\cite##1{}\gdef\parencite##1{}
\gdef\Cite##1{}\gdef\Parencite##1{}
\gdef\cites##1{}\gdef\parencites##1{}
\gdef\Cites##1{}\gdef\Parencites##1{}
\gdef\footcite##1{}\gdef\footcitetext##1{}
\gdef\footcites##1{}\gdef\footcitetexts##1{}
\gdef\textcite##1{}\gdef\Textcite##1{}
\gdef\textcites##1{}\gdef\Textcites##1{}
\gdef\smartcites##1{}\gdef\Smartcites##1{}
\gdef\supercite##1{}\gdef\supercites##1{}
\gdef\autocite##1{}\gdef\Autocite##1{}
\gdef\autocites##1{}\gdef\Autocites##1{}
%% many, many missing … maybe we need to tackle the underlying mechanism?
}
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",guttenbergenize_rq,"guttenbergenize_rq")}
}
\def\hammertime{
\global\let\n\relax
\directlua{hammerfirst = true
luatexbase.add_to_callback("pre_linebreak_filter",hammertime,"hammertime")}}
\def\unhammertime{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","hammertime")}}
\let\hendlnize\chickenize % homage to Hendl/Chicken
\let\unhendlnize\unchickenize % may the soldering strength always be with him
\def\italianizerandwords{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",italianizerandwords,"italianizerandwords")}}
\def\unitalianizerandwords{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","italianizerandwords")}}
\def\italianize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",italianize,"italianize")}}
\def\unitalianize{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","italianize")}}
% \def\itsame{
% \directlua{drawmario}} %%% does not exist
\def\kernmanipulate{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",kernmanipulate,"kernmanipulate")}}
\def\unkernmanipulate{
\directlua{lutaexbase.remove_from_callback("pre_linebreak_filter",kernmanipulate)}}
\def\leetspeak{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",leet,"1337")}}
\def\unleetspeak{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","1337")}}
\def\leftsideright#1{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",leftsideright,"leftsideright")}
\directlua{
leftsiderightindex = {#1}
leftsiderightarray = {}
for _,i in pairs(leftsiderightindex) do
leftsiderightarray[i] = true
end
}
}
\def\unleftsideright{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","leftsideright")}}
\def\letterspaceadjust{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",letterspaceadjust,"letterspaceadjust")}}
\def\unletterspaceadjust{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","letterspaceadjust")}}
\def\listallcommands{
\directlua{
for name in pairs(tex.hashtokens()) do
print(name)
end}
}
\let\stealsheep\letterspaceadjust %% synonym in honor of Paul
\let\unstealsheep\unletterspaceadjust
\let\returnsheep\unletterspaceadjust
\def\matrixize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",matrixize,"matrixize")}}
\def\unmatrixize{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","matrixize")}}
\def\milkcow{ %% FIXME %% to be implemented
\directlua{}}
\def\unmilkcow{
\directlua{}}
\def\medievalumlaut{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",medievalumlaut,"medievalumlaut")}}
\def\unmedievalumlaut{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","medievalumlaut")}}
\def\pancakenize{
\directlua{luatexbase.add_to_callback("stop_run",pancaketext,"pancaketext")}}
\def\rainbowcolor{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",randomcolor,"rainbowcolor")
rainbowcolor = true}}
\def\unrainbowcolor{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","rainbowcolor")
rainbowcolor = false}}
\let\nyanize\rainbowcolor
\let\unnyanize\unrainbowcolor
\def\randomchars{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",randomchars,"randomchars")}}
\def\unrandomchars{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomchars")}}
\def\randomcolor{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",randomcolor,"randomcolor")}}
\def\unrandomcolor{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomcolor")}}
\def\randomerror{ %% FIXME
\directlua{luatexbase.add_to_callback("post_linebreak_filter",randomerror,"randomerror")}}
\def\unrandomerror{ %% FIXME
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomerror")}}
\def\randomfonts{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",randomfonts,"randomfonts")}}
\def\unrandomfonts{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomfonts")}}
\def\randomuclc{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",randomuclc,"randomuclc")}}
\def\unrandomuclc{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","randomuclc")}}
\def\relationship{%
\directlua{luatexbase.add_to_callback("post_linebreak_filter",cutparagraph,"cut paragraph")
luatexbase.add_to_callback("stop_run",missingcharstext,"charsmissing")
relationship()
}
}
\let\rongorongonize\boustrophedoninverse
\let\unrongorongonize\unboustrophedoninverse
\def\scorpionize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",scorpionize_color,"scorpionize_color")}}
\def\unscorpionize{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","scorpionize_color")}}
\def\shownodes#1{
\directlua{
shownodes_var = "#1"
luatexbase.add_to_callback("#1",shownodes,"shownodes")}}
\def\spankmonkey{ %% to be implemented
\directlua{}}
\def\unspankmonkey{
\directlua{}}
\def\substitutewords{
\directlua{luatexbase.add_to_callback("process_input_buffer",substitutewords,"substitutewords")}}
\def\unsubstitutewords{
\directlua{luatexbase.remove_from_callback("process_input_buffer","substitutewords")}}
\def\addtosubstitutions#1#2{
\directlua{addtosubstitutions("#1","#2")}
}
\def\suppressonecharbreak{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",suppressonecharbreak,"suppressonecharbreak")}}
\def\unsuppressonecharbreak{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","suppressonecharbreak")}}
\def\tabularasa{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",tabularasa,"tabularasa")}}
\def\untabularasa{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","tabularasa")}}
\def\tanjanize{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",tanjanize,"tanjanize")}}
\def\untanjanize{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","tanjanize")}}
\def\uppercasecolor{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",uppercasecolor,"uppercasecolor")}}
\def\unuppercasecolor{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","uppercasecolor")}}
\def\upsidedown#1{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",upsidedown,"upsidedown")}
\directlua{
upsidedownindex = {#1}
upsidedownarray = {}
for _,i in pairs(upsidedownindex) do
upsidedownarray[i] = true
end
}
}
\def\unupsidedown{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","upsidedown")}}
\def\variantjustification{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",variantjustification,"variantjustification")}}
\def\unvariantjustification{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","variantjustification")}}
\def\zebranize{
\directlua{luatexbase.add_to_callback("post_linebreak_filter",zebranize,"zebranize")}}
\def\unzebranize{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","zebranize")}}
% \end{macrocode}
% Now the setup for the |\text|-versions. We utilize Lua\TeX s attributes to mark all nodes that should be manipulated. The macros should be |\long| to allow arbitrary input.
% \begin{macrocode}
\newattribute\leetattr
\newattribute\letterspaceadjustattr
\newattribute\randcolorattr
\newattribute\randfontsattr
\newattribute\randuclcattr
\newattribute\tabularasaattr
\newattribute\uppercasecolorattr
\long\def\textleetspeak#1%
{\setluatexattribute\leetattr{42}#1\unsetluatexattribute\leetattr}
\long\def\textletterspaceadjust#1{
\setluatexattribute\letterspaceadjustattr{42}#1\unsetluatexattribute\letterspaceadjustattr
\directlua{
if (textletterspaceadjustactive) then else % -- if already active, do nothing
luatexbase.add_to_callback("pre_linebreak_filter",textletterspaceadjust,"textletterspaceadjust")
end
textletterspaceadjustactive = true % -- set to active
}
}
\let\textlsa\textletterspaceadjust
\long\def\textrandomcolor#1%
{\setluatexattribute\randcolorattr{42}#1\unsetluatexattribute\randcolorattr}
\long\def\textrandomfonts#1%
{\setluatexattribute\randfontsattr{42}#1\unsetluatexattribute\randfontsattr}
\long\def\textrandomfonts#1%
{\setluatexattribute\randfontsattr{42}#1\unsetluatexattribute\randfontsattr}
\long\def\textrandomuclc#1%
{\setluatexattribute\randuclcattr{42}#1\unsetluatexattribute\randuclcattr}
\long\def\texttabularasa#1%
{\setluatexattribute\tabularasaattr{42}#1\unsetluatexattribute\tabularasaattr}
\long\def\textuppercasecolor#1%
{\setluatexattribute\uppercasecolorattr{42}#1\unsetluatexattribute\uppercasecolorattr}
% \end{macrocode}
% Finally, a macro to control the setup. So far, it's only a wrapper that allows \TeX-style comments to make the user feel more at home.
% \begin{macrocode}
\def\chickenizesetup#1{\directlua{#1}}
% \end{macrocode}
% \subsection{drawchicken}\label{sec:drawchicken}
% The following is the very first try of implementing a small drawing language in Lua. It draws a beautiful (?) chicken. TODO: Make it scalable by giving relative sizes. Also: Allow it to look to the other side if wanted.
% \begin{macrocode}
\long\def\luadraw#1#2{%
\vbox to #1bp{%
\vfil
\latelua{pdf_print("q") #2 pdf_print("Q")}%
}%
}
\long\def\drawchicken{
\luadraw{90}{
chickenhead = {200,50} % chicken head center
chickenhead_rad = 20
neckstart = {215,35} % neck
neckstop = {230,10} %
chickenbody = {260,-10}
chickenbody_rad = 40
chickenleg = {
{{260,-50},{250,-70},{235,-70}},
{{270,-50},{260,-75},{245,-75}}
}
beak_top = {185,55}
beak_front = {165,45}
beak_bottom = {185,35}
wing_front = {260,-10}
wing_bottom = {280,-40}
wing_back = {275,-15}
sloppycircle(chickenhead,chickenhead_rad) sloppyline(neckstart,neckstop)
sloppycircle(chickenbody,chickenbody_rad)
sloppyline(chickenleg[1][1],chickenleg[1][2]) sloppyline(chickenleg[1][2],chickenleg[1][3])
sloppyline(chickenleg[2][1],chickenleg[2][2]) sloppyline(chickenleg[2][2],chickenleg[2][3])
sloppyline(beak_front,beak_top) sloppyline(beak_front,beak_bottom)
sloppyline(wing_front,wing_bottom) sloppyline(wing_back,wing_bottom)
}
}
% \end{macrocode}
% \subsection{drawcov}\label{sec:drawcov}
% This draws a corona virus since I had some time to work on this package due to the shutdown caused by COVID-19.
% \begin{macrocode}
\long\def\drawcov{
\luadraw{90}{
covbody = {200,50}
covbody_rad = 50
covcrown_rad = 5
crownno = 13
for i=1,crownno do
crownpos = {covbody[1]+1.4*covbody_rad*math.sin(2*math.pi/crownno*i),covbody[2]+1.4*covbody_rad*math.cos(2*math.pi/crownno*i)}
crownconnect = {covbody[1]+covbody_rad*math.sin(2*math.pi/crownno*i),covbody[2]+covbody_rad*math.cos(2*math.pi/crownno*i)}
sloppycircle(crownpos,covcrown_rad)
sloppyline(crownpos,crownconnect)
end
covcrown_rad = 6
crownno = 8
for i=1,crownno do
crownpos = {covbody[1]+0.8*covbody_rad*math.sin(2*math.pi/crownno*i),covbody[2]+0.8*covbody_rad*math.cos(2*math.pi/crownno*i)}
crownconnect = {covbody[1]+0.5*covbody_rad*math.sin(2*math.pi/crownno*i),covbody[2]+0.5*covbody_rad*math.cos(2*math.pi/crownno*i)}
sloppycircle(crownpos,covcrown_rad)
sloppyline(crownpos,crownconnect)
end
covcrown_rad = 8
sloppycircle(covbody,covcrown_rad)
sloppycircle(covbody,covbody_rad)
sloppyline(covbody,covbody)
}
}
% \end{macrocode}
% \subsection{drawhorse}\label{sec:drawhorse}
% Well … guess what this does.
% \begin{macrocode}
\long\def\drawhorse{
\luadraw{90}{
horsebod = {100,-40}
sloppyellipsis(horsebod,50,20)
horsehead = {20,0}
sloppyellipsis(horsehead,25,15)
sloppyline({35,-10},{50,-40})
sloppyline({45,5},{80,-25})
sloppyline({60,-50},{60,-90})
sloppyline({70,-50},{70,-90})
sloppyline({130,-50},{130,-90})
sloppyline({140,-50},{140,-90})
sloppyline({150,-40},{160,-60})
sloppyline({150,-38},{160,-58})
sloppyline({150,-42},{160,-62})
sloppyline({-5,-10},{10,-5})
sloppyellipsis({30,5},5,2) %% it's an eye, aye?
sloppyline({27,15},{34,25})
sloppyline({34,25},{37,13})
}
}
% \end{macrocode}
% There's also a version with a bit more … meat to the bones:
% \begin{macrocode}
\long\def\drawfathorse{
\luadraw{90}{
horsebod = {100,-40}
sloppyellipsis(horsebod,50,40)
horsehead = {20,0}
sloppyellipsis(horsehead,25,15)