summaryrefslogtreecommitdiff
path: root/tex/plain
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-02-21 10:42:08 +0100
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-02-21 10:42:08 +0100
commit7477a9e3c3e955307558d7ed0ae47d68d24d156d (patch)
treef104156d547001b92ac43204ada8f56c16fd01bf /tex/plain
downloadenigma-7477a9e3c3e955307558d7ed0ae47d68d24d156d.tar.gz
initial commit: Plain module functional
Diffstat (limited to 'tex/plain')
-rw-r--r--tex/plain/enigma/enigma.tex83
1 files changed, 83 insertions, 0 deletions
diff --git a/tex/plain/enigma/enigma.tex b/tex/plain/enigma/enigma.tex
new file mode 100644
index 0000000..6827878
--- /dev/null
+++ b/tex/plain/enigma/enigma.tex
@@ -0,0 +1,83 @@
+\input{luatexbase.sty}
+%D \startsection[title=Prerequisites]
+%D \startparagraph
+%D Package loading and the namespacing issue are commented on in
+%D \identifier{enigma.lua}.
+%D \stopparagraph
+\directlua{%
+ packagedata = packagedata or { }
+ dofile(kpse.find_file"enigma.lua")
+}
+
+%D \startparagraph
+%D First, create somthing like \CONTEXT’s asciimode. We found
+%D \texmacro{\newluatexcatcodetable} in \identifier{luacode.sty} and it
+%D seems to get the job done.
+%D \stopparagraph
+\newluatexcatcodetable \enigmasetupcatcodes
+\bgroup
+ \def\escapecatcode {0}
+ \def\begingroupcatcode {1}
+ \def\endgroupcatcode {2}
+ \def\spacecatcode {10}
+ \def\lettercatcode {11}
+ \setluatexcatcodetable\enigmasetupcatcodes {
+ \catcode`\^^I = \spacecatcode % tab
+ \catcode`\ = \spacecatcode
+ \catcode`\{ = \begingroupcatcode
+ \catcode`\} = \endgroupcatcode
+ \catcode`\^^L = \lettercatcode % form feed
+ \catcode`\^^M = \lettercatcode % eol
+ }
+\egroup
+%D \stopsection
+
+%D \startsection[title=Setups]
+%D \startparagraph
+%D Once the proper catcodes are in place, the setup macro
+%D \texmacro{do-setup_enigma} doesn’t to anything besides passing stuff
+%D through to Lua.
+%D \stoppparagraph
+\def\do_setup_enigma#1{%
+ \directlua{
+ local enigma = packagedata.enigma
+ local current_args = enigma.parse_args([====[\detokenize{#1}]====])
+ enigma.current = enigma.new_callback(enigma.new_machine(current_args, "aaa"))
+ }%
+ \egroup%
+}
+
+%D The module setup \texmacro{setupenigma} expects key=value, notation.
+%D All the logic is at the Lua end, not much to see here …
+\def\setupenigma{%
+ \bgroup
+ \luatexcatcodetable \enigmasetupcatcodes
+ \do_setup_enigma%
+}
+%D \stopsection
+
+%D \startsection[title=Encoding Macros]
+%D \startparagraph
+%D The environment of \texmacro{\startenigma} and \texmacro{\stopenigma}
+%D allow enabling of Enigma encoding in different parts of the document.
+%D \stopparagraph
+
+\def\startenigma{%
+ \bgroup%
+ \directlua{%
+ if packagedata.enigma and packagedata.enigma.current then
+ luatexbase.add_to_callback("pre_linebreak_filter",
+ packagedata.enigma.current,
+ "enigma")
+ end
+ }%
+}
+
+\def\stopenigma{%
+ \directlua{luatexbase.remove_from_callback("pre_linebreak_filter", "enigma")
+ packagedata.enigma.current_machine:processed_chars()}%
+ \egroup%
+}
+%D \stopsection
+
+% vim:ft=tex:sw=2:ts=2:expandtab:tw=72