From 8bde7a7bf62d0ae8ddd0e43ff73e3b43183ac389 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 18 Sep 2012 23:39:07 +0000 Subject: chickenize (18sep12) git-svn-id: svn://tug.org/texlive/trunk@27720 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/luatex/chickenize/chickenize.lua | 60 ++++++++++++++++++-- .../tex/luatex/chickenize/chickenize.sty | 5 +- .../tex/luatex/chickenize/chickenize.tex | 65 +++++++++++++++++++++- 3 files changed, 118 insertions(+), 12 deletions(-) (limited to 'Master/texmf-dist/tex/luatex/chickenize') diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua b/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua index 670ec02b2e5..18337fcffb8 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua @@ -11,7 +11,7 @@ -- This package is copyright © 20012 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 ‘author-maintained’. +-- ance status ‘maintained’. local nodenew = node.new local nodecopy = node.copy @@ -20,6 +20,7 @@ local nodeinsertafter = node.insert_after local noderemove = node.remove local nodeid = node.id local nodetraverseid = node.traverse_id +local nodeslide = node.slide Hhead = nodeid("hhead") RULE = nodeid("rule") @@ -36,7 +37,7 @@ color_pop.cmd = 2 chicken_pagenumbers = true chickenstring = {} -chickenstring[1] = "Chicken" -- chickenstring is a table, please remeber this! +chickenstring[1] = "chicken" -- chickenstring is a table, please remeber this! chickenizefraction = 0.5 -- set this to a small value to fool somebody, or to see if your text has been read carefully. This is also a great way to lay easter eggs for your own class / package … @@ -48,7 +49,6 @@ local shrink = tbl.parameters.space_shrink local stretch = tbl.parameters.space_stretch local match = unicode.utf8.match chickenize_ignore_word = false - chickenize_real_stuff = function(i,head) while ((i.next.id == 37) or (i.next.id == 11) or (i.next.id == 7) or (i.next.id == 0)) do --find end of a word i.next = i.next.next @@ -81,7 +81,7 @@ chickenize_real_stuff = function(i,head) j = j+1 end - node.slide(chicken[1]) + nodeslide(chicken[1]) lang.hyphenate(chicken[1]) chicken[1] = node.kerning(chicken[1]) -- FIXME: does not work chicken[1] = node.ligaturing(chicken[1]) -- dito @@ -89,12 +89,19 @@ chickenize_real_stuff = function(i,head) nodeinsertbefore(head,i,chicken[1]) chicken[1].next = chicken[2] -- seems to be necessary … to be fixed chicken[string.len(chickenstring_tmp)].next = i.next + + -- shift lowercase latin letter to uppercase if the original input was an uppercase + if (chickenize_capital and (chicken[1].char > 96 and chicken[1].char < 123)) then + chicken[1].char = chicken[1].char - 32 + end + return head end chickenize = function(head) for i in nodetraverseid(37,head) do --find start of a word if (chickenize_ignore_word == false) then -- normal case: at the beginning of a word, we jump into chickenization + if (i.char > 64 and i.char < 91) then chickenize_capital = true else chickenize_capital = false end head = chickenize_real_stuff(i,head) end @@ -129,6 +136,18 @@ nicetext = function() texiowrite_nl(separator) end end + +countglyphs = function(head) + for line in nodetraverseid(0,head) do + for glyph in nodetraverseid(37,line.head) do + glyphnumber = glyphnumber + 1 + end + end + return head +end +printglyphnumber = function() + texiowrite_nl("Number of glyphs in this document: "..glyphnumber) +end local quotestrings = { [171] = true, [172] = true, [8216] = true, [8217] = true, [8218] = true, @@ -266,6 +285,19 @@ letterspaceadjust = function(head) end return head end +textletterspaceadjust = function(head) + for glyph in node.traverse_id(node.id"glyph", head) do + if node.has_attribute(glyph,luatexbase.attributes.letterspaceadjustattr) then + if glyph.prev and (glyph.prev.id == node.id"glyph" or glyph.prev.id == node.id"disc") then + local g = node.copy(letterspace_glue) + node.insert_before(head, glyph, g) + node.insert_before(head, g, node.copy(letterspace_pen)) + end + end + end + luatexbase.remove_from_callback("pre_linebreak_filter","textletterspaceadjust") + return head +end matrixize = function(head) x = {} s = nodenew(nodeid"disc") @@ -299,9 +331,11 @@ pancaketext = function() texiowrite_nl("(This goes by document, not compilation.)") texiowrite_nl(separator.."\n\n") texiowrite_nl("Looking forward for my pancake! :)") + texiowrite_nl("\n\n") end -local randomfontslower = 1 -local randomfontsupper = 0 + +randomfontslower = 1 +randomfontsupper = 0 randomfonts = function(head) local rfub if randomfontsupper > 0 then -- fixme: this should be done only once, no? Or at every paragraph? @@ -400,6 +434,20 @@ randomcolor = function(head) end return head end +substitutewords_strings = {} + +addtosubstitutions = function(input,output) + substitutewords_strings[#substitutewords_strings + 1] = {} + substitutewords_strings[#substitutewords_strings][1] = input + substitutewords_strings[#substitutewords_strings][2] = output +end + +substitutewords = function(head) + for i = 1,#substitutewords_strings do + head = string.gsub(head,substitutewords_strings[i][1],substitutewords_strings[i][2]) + end + return head +end tabularasa_onlytext = false tabularasa = function(head) diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty b/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty index 18ef07d7c50..612b931d0b1 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty @@ -11,11 +11,10 @@ %% This package is copyright © 20012 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 ‘author-maintained’. +%% ance status ‘maintained’. \ProvidesPackage{chickenize}% - [2012/05/20 v0.1 chickenize package] + [2012/09/16 v0.1a chickenize package] \input{chickenize} - %% We want to “chickenize” figures, too. So … \iffalse \DeclareDocumentCommand\includegraphics{O{}m}{ \fbox{Chicken} %% actually, I'd love to draw an MP graph showing a chicken … diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex b/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex index d47e345380c..0e6da86fedb 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex @@ -11,10 +11,33 @@ %% This package is copyright © 20012 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 ‘author-maintained’. +%% ance status ‘maintained’. \input{luatexbase.sty} \directlua{dofile(kpse.find_file("chickenize.lua"))} +\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\chickenize{ \directlua{luatexbase.add_to_callback("pre_linebreak_filter",chickenize,"chickenize") luatexbase.add_to_callback("start_page_number", @@ -39,6 +62,13 @@ \def\uncolorstretch{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","stretch_expansion")}} +\def\countglyphs{ + \directlua{glyphnumber = 0 + luatexbase.add_to_callback("post_linebreak_filter",countglyphs,"countglyphs") + luatexbase.add_to_callback("stop_run",printglyphnumber,"printglyphnumber") + } +} + \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? } @@ -114,6 +144,13 @@ \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 @@ -146,9 +183,9 @@ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomcolor")}} \def\randomerror{ %% FIXME - \directlua{luatexbase.add_to_callback("post_linebreak_filter",randomcolor,"randomcolor")}} + \directlua{luatexbase.add_to_callback("post_linebreak_filter",randomerror,"randomerror")}} \def\unrandomerror{ %% FIXME - \directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomcolor")}} + \directlua{luatexbase.remove_from_callback("post_linebreak_filter","randomerror")}} \def\randomfonts{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",randomfonts,"randomfonts")}} @@ -170,6 +207,15 @@ \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\tabularasa{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",tabularasa,"tabularasa")}} \def\untabularasa{ @@ -185,6 +231,7 @@ \def\unzebranize{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","zebranize")}} \newluatexattribute\leetattr +\newluatexattribute\letterspaceadjustattr \newluatexattribute\randcolorattr \newluatexattribute\randfontsattr \newluatexattribute\randuclcattr @@ -193,6 +240,18 @@ \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% -- cgit v1.2.3