summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-02-26 00:29:48 +0000
committerKarl Berry <karl@freefriends.org>2013-02-26 00:29:48 +0000
commitd0fb875485e53d004d0a28def85d2df3c0744295 (patch)
treeead09dcd98050ff2ab7997caf1c9091fc28a4621 /Master/texmf-dist/source
parent0a17a835648c35c1544427e3729a351d0de3887a (diff)
chickenize (25feb13)
git-svn-id: svn://tug.org/texlive/trunk@29232 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r--Master/texmf-dist/source/luatex/chickenize/chickenize.dtx183
1 files changed, 165 insertions, 18 deletions
diff --git a/Master/texmf-dist/source/luatex/chickenize/chickenize.dtx b/Master/texmf-dist/source/luatex/chickenize/chickenize.dtx
index f8441bc442c..63449b4a9d7 100644
--- a/Master/texmf-dist/source/luatex/chickenize/chickenize.dtx
+++ b/Master/texmf-dist/source/luatex/chickenize/chickenize.dtx
@@ -116,7 +116,7 @@ chickenize
\unrainbowcolor
-\centerline{v0.1a}
+\centerline{v0.2}
\centerline{\hspace*{2cm} Arno Trautmann}
\centerline{\href{mailto:arno.trautmann@gmx.de}{arno.trautmann@gmx.de}}
@@ -156,10 +156,12 @@ A small and incomplete overview of the functionalities offered by this package.
\cmidrule(lr){1-2}
\hyperref[sec:colorstretch]{colorstretch} & shows grey boxes that visualise the badness and font expansion of each line\\
\hyperref[sec:letterspaceadjust]{letterspaceadjust} & improves the greyness by using a small amount of letterspacing\\
-\hyperref[sec:substitutewords]{substitutewords} & replaces words by other words (user-controlled!)\\
+\hyperref[sec:substitutewords]{substitutewords} & replaces words by other words (chosen by the user)\\
+\hyperref[sec:variantjustification]{variantjustification} & Justification by using glyph variants\\
\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:leetspeak]{leetspeak} & translates the (latin-based) input into 1337 5p34k\\
\hyperref[sec:randomuclc]{randomuclc} & alternates randomly between uppercase and lowercase\\
@@ -201,24 +203,26 @@ The effect of the commands can be influenced, not with arguments, but only via t
\begin{description}
\def\command#1{\item[\ttfamily \color{blue} \textbackslash#1]}
+\command{boustrophedon} Reverts every second line. This immitates 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 adaptet 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} Counts every printed character that appeared in anything that is a paragraph. Which is quite everything, in fact, \emph{exept} math mode! The total number will be printed at the end of the log file/console output.
\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{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{hammertime} STOP! —— Hammertime!
-\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{leetspeak} Translates the input into 1337 speak. If you don't understand that, lern it, n00b.
+\command{matrixize} Replaces every glyph by a binary representation of its ASCII value.
+\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{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{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{leetspeak} Translates the input into 1337 speak. If you don't understand that, lern it, n00b.
-\command{nyanize} A synonym for |rainbowcolor|.
-\command{matrixize} Replaces every glyph by a binary representation of its ASCII value.
-\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{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 warks with the input 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{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}
@@ -392,6 +396,21 @@ The namespace of the chickenize package is \emph{not} consistent. Please don't t
}
}
+\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\chickenize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",chickenize,"chickenize")
luatexbase.add_to_callback("start_page_number",
@@ -555,6 +574,9 @@ The namespace of the chickenize package is \emph{not} consistent. Please don't t
\def\unrandomuclc{
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter","randomuclc")}}
+\let\rongorongonize\boustrophedoninverse
+\let\unrongorongonize\unboustrophedoninverse
+
\def\scorpionize{
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",scorpionize_color,"scorpionize_color")}}
\def\unscorpionize{
@@ -584,6 +606,11 @@ The namespace of the chickenize package is \emph{not} consistent. Please don't t
\def\unuppercasecolor{
\directlua{luatexbase.remove_from_callback("post_linebreak_filter","uppercasecolor")}}
+\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{
@@ -685,7 +712,7 @@ sloppyline(flugel_vorne,flugel_unten) sloppyline(flugel_hinten,flugel_unten)
% Some code might be implemented to manipulate figures for full chickenization. However, I will \emph{not} load any packages at this place, as loading of expl3 or TikZ or whatever takes too much time for such a tiny package like this one. If you require any of the features presented here, you have to load the packages on your own. Maybe this will change.
% \begin{macrocode}
\ProvidesPackage{chickenize}%
- [2012/09/16 v0.1a chickenize package]
+ [2013/02/24 v0.2 chickenize package]
\input{chickenize}
% \end{macrocode}
% \subsection{Definition of User-Level Macros}
@@ -851,7 +878,79 @@ nicetext = function()
end
end
% \end{macrocode}
-
+% \subsection{boustrophedon}\label{sec:boustrophedon}
+% There are two implementations of the boustrophedon: One reverses every line as a whole, the other one changes the writing direction and reverses glyphs one by one. The latter one might be more reliable, but takes considerably more time.
+%
+% Linewise rotation:
+% \begin{macrocode}
+boustrophedon = function(head)
+ rot = node.new(8,8)
+ rot2 = node.new(8,8)
+ odd = true
+ for line in node.traverse_id(0,head) do
+ if odd == false then
+ w = line.width/65536*0.99625 -- empirical correction factor (?)
+ rot.data = "-1 0 0 1 "..w.." 0 cm"
+ rot2.data = "-1 0 0 1 "..-w.." 0 cm"
+ line.head = node.insert_before(line.head,line.head,node.copy(rot))
+ node.insert_after(line.head,node.tail(line.head),node.copy(rot2))
+ odd = true
+ else
+ odd = false
+ end
+ end
+ return head
+end
+% \end{macrocode}
+% Glyphwise rotation:
+% \begin{macrocode}
+boustrophedon_glyphs = function(head)
+ odd = false
+ rot = nodenew(8,8)
+ rot2 = nodenew(8,8)
+ for line in nodetraverseid(0,head) do
+ if odd==true then
+ line.dir = "TRT"
+ for g in nodetraverseid(37,line.head) do
+ w = -g.width/65536*0.99625
+ rot.data = "-1 0 0 1 " .. w .." 0 cm"
+ rot2.data = "-1 0 0 1 " .. -w .." 0 cm"
+ line.head = node.insert_before(line.head,g,node.copy(rot))
+ node.insert_after(line.head,g,node.copy(rot2))
+ end
+ odd = false
+ else
+ line.dir = "TLT"
+ odd = true
+ end
+ end
+ return head
+end
+% \end{macrocode}
+% Inverse boustrophedon. At least I think, this is the way Rongorongo is written. However, the top-to-bottom direction has to be inverted, too.
+% \begin{macrocode}
+boustrophedon_inverse = function(head)
+ rot = node.new(8,8)
+ rot2 = node.new(8,8)
+ odd = true
+ for line in node.traverse_id(0,head) do
+ if odd == false then
+texio.write_nl(line.height)
+ w = line.width/65536*0.99625 -- empirical correction factor (?)
+ h = line.height/65536*0.99625
+ rot.data = "-1 0 0 -1 "..w.." "..h.." cm"
+ rot2.data = "-1 0 0 -1 "..-w.." "..0.5*h.." cm"
+ line.head = node.insert_before(line.head,line.head,node.copy(rot))
+ node.insert_after(line.head,node.tail(line.head),node.copy(rot2))
+ odd = true
+ else
+ odd = false
+ end
+ end
+ return head
+end
+% \end{macrocode}
+%
% \subsection{countglyphs}\label{sec:countglyphs}
% Counts the glyphs in your documnt. Where “glyph” means every printed character in everything that is a paragraph – formulas do \emph{not} work! However, hyphenations \emph{do} work and the hyphen sign \emph{is counted}! And that is the sole reason for this function – every simple script could read the letters in a doucment, but only after the hyphenation it is possible to count the real number of printed characters – where the hyphen does count.
%
@@ -869,7 +968,7 @@ end
% To print out the number at the end of the document, the following function is registered in the |stop_run| callback. This will prevent the normal message from being printed, informing the user about page and memory stats etc. But I guess when counting characters, everything else does not matter at all? …
% \begin{macrocode}
printglyphnumber = function()
- texiowrite_nl("Number of glyphs in this document: "..glyphnumber)
+ texiowrite_nl("\n Number of glyphs in this document: "..glyphnumber.."\n")
end
% \end{macrocode}
% \subsection{guttenbergenize}\label{sec:guttenbergenize}
@@ -1344,12 +1443,12 @@ colorstretch = function (head)
if colorexpansion then -- if also the font expansion should be shown
local g = line.head
- while not(g.id == 37) do
- g = g.next
- end
- exp_factor = g.width / f[g.char].width
- exp_color = colorstretch_coloroffset + (1-exp_factor)*10 .. " g"
- rule_bad.width = 0.5*line.width -- we need two rules on each line!
+ while not(g.id == 37) and (g.next) do g = g.next end -- find first glyph on line. If line is empty, no glyph:
+ if (g.id == 37) then -- read width only if g is a glyph!
+ exp_factor = g.width / f[g.char].width
+ exp_color = colorstretch_coloroffset + (1-exp_factor)*10 .. " g"
+ rule_bad.width = 0.5*line.width -- we need two rules on each line!
+ end
else
rule_bad.width = line.width -- only the space expansion should be shown, only one rule
end
@@ -1444,6 +1543,53 @@ function scorpionize_color(head)
return head
end
% \end{macrocode}
+% \subsection{variantjustification}\label{sec:variantjustification}
+% The list |substlist| defines which glyphs can be replaced by others. Use the unicode code points for this. So far, only wider variants are possible! Extend the list at will. If you find useful definitions, send me any glyph combination!
+%
+% Some predefined values for hebrew typesetting; the list is not local so the user can change it in a very transparent way (using |\chickenizesetup{}|. This costs runtime, however … I guess … (?)
+% \begin{macrocode}
+substlist = {}
+substlist[1488] = 64289
+substlist[1491] = 64290
+substlist[1492] = 64291
+substlist[1499] = 64292
+substlist[1500] = 64293
+substlist[1501] = 64294
+substlist[1512] = 64295
+substlist[1514] = 64296
+% \end{macrocode}
+% In the function, we need reproduceable randomization so every compilation of the same document looks the same. Else this would make contracts invalid.
+%
+% The last line is excluded from the procedure as it makes no sense to extend it this way. If you really want to typeset a rectangle, use the appropriate way to disable the space at the end of the paragraph (german “Ausgang“).
+% \begin{macrocode}
+function variantjustification(head)
+ math.randomseed(1)
+ for line in nodetraverseid(nodeid"hhead",head) do
+ if (line.glue_sign == 1 and line.glue_order == 0) then -- exclude the last line!
+ substitutions_wide = {} -- we store all “expandable” letters of each line
+ for n in nodetraverseid(nodeid"glyph",line.head) do
+ if (substlist[n.char]) then
+ substitutions_wide[#substitutions_wide+1] = n
+ end
+ end
+ line.glue_set = 0 -- deactivate normal glue expansion
+ local width = node.dimensions(line.head) -- check the new width of the line
+ local goal = line.width
+ while (width < goal and #substitutions_wide > 0) do
+ x = math.random(#substitutions_wide) -- choose randomly a glyph to be substituted
+ oldchar = substitutions_wide[x].char
+ substitutions_wide[x].char = substlist[substitutions_wide[x].char] -- substitute by wide letter
+ width = node.dimensions(line.head) -- check if the line is too wide
+ if width > goal then substitutions_wide[x].char = oldchar break end -- substitute back if the line would be too wide and break out of the loop
+ table.remove(substitutions_wide,x) -- if further substitutions have to be done, remove the just substituted node from the list
+ end
+ end
+ end
+ return head
+end
+% \end{macrocode}
+% That's it. Actually, the function is quite simple and should work out of the box. However, small columns will most probably not work as there typically is not much expandable stuff in a normal line of text.
+%
% \subsection{zebranize}\label{sec:zebranize}
% This function is inspired by a discussion with the Heidelberg regular's table and will change the color of each paragraph linewise. Both the textcolor and background color are changed to create a true zebra like look. If you want to change or add colors, just change the values of |zebracolorarray[]| for the text colors and |zebracolorarray_bg[]| for the background. Do not mix with other color changing functions of this package, as that will turn out ugly or erroneous.
%
@@ -1589,6 +1735,7 @@ end
% \section{To Do's}
% Some things that should be implemented but aren’t so far or are very poor at the moment:
% \begin{description}
+% \item[traversing] Every function that is based on node traversing fails when boxes are involved – so far I have not implemented recursive calling of the functions. I list it here, as it is not really a bug – this package is meant to be as simple as possible!
% \item[countglyphs] should be extended to count anything the user wants to count
% \item[rainbowcolor] should be more flexible – the angle of the rainbow should be easily adjustable.
% \item[pancakenize] should do something funny.
@@ -1608,6 +1755,6 @@ end
% \section{Thanks}
% This package would not have been possible without the help of many people who patiently answered my annoying questions on mailing lists and in personal mails. And of course not without the work of the Lua\TeX\ team!
%
-% Special thanks go to Paul “we could have chickenized the world” Isambert who contributed a lot of ideas, code and bug fixes and made much of the code executable at all. I also think Philipp Gesang who gave me many advices on the Lua code – which I still didn't have time to correct …
+% Special thanks go to Paul “we could have chickenized the world” Isambert who contributed a lot of ideas, code and bug fixes and made much of the code executable at all. I also thank Philipp Gesang who gave me many advices on the Lua code – which I still didn't have time to correct …
% \Finale
% \endinput