[latex3-commits] [git/LaTeX3-latex3-xxetex] main: character class experiment (42ae7a3)

David Carlisle d.p.carlisle at gmail.com
Fri Jan 27 00:12:40 CET 2023


Repository : https://github.com/latex3/xxetex
On branch  : main
Link       : https://github.com/latex3/xxetex/commit/42ae7a3dc6c5c9ff8999ea3e96d0a75ed0c50681

>---------------------------------------------------------------

commit 42ae7a3dc6c5c9ff8999ea3e96d0a75ed0c50681
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Thu Jan 26 23:12:40 2023 +0000

    character class experiment


>---------------------------------------------------------------

42ae7a3dc6c5c9ff8999ea3e96d0a75ed0c50681
 classes.tex   | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xxclasses.lua | 57 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)

diff --git a/classes.tex b/classes.tex
new file mode 100644
index 0000000..451578f
--- /dev/null
+++ b/classes.tex
@@ -0,0 +1,76 @@
+% xetex character classes from xetex manual.
+
+% see also
+% https://chat.stackexchange.com/transcript/41?m=49002020#49002020
+
+% \XeTeXinterchartoks 4095 \mycharclassB case not working (loops)
+
+% note this runs in pre_linebreak_filter so inserting a font change
+% will not affect the following characters.
+
+\documentclass{article}
+\usepackage{color}
+
+\makeatletter
+\ifx\directlua\undefined\else
+
+
+
+
+\newcount\XeTeXinterchartokenstate 
+
+
+\newtoks\xxinterchartoks
+\directlua{xxinterchartoksnum=\the\allocationnumber print("AAa" .. xxinterchartoksnum)}
+\newbox\xxintercharbox
+\newtoks\xxruninterchartoks
+\directlua{xxruninterchartoksnum=\the\allocationnumber print("AAa" .. xxruninterchartoksnum)}
+\xxruninterchartoks={\global\setbox\xxintercharbox\hpack{\the\xxinterchartoks}}
+\directlua{require("xxclasses")}
+
+\chardef\e at alloc@intercharclass at top=4095
+
+\def\newXeTeXintercharclass{%
+ \e at alloc\XeTeXcharclass
+   \chardef\xe at alloc@intercharclass\m at ne\e at alloc@intercharclass at top}
+
+  \countdef\xe at alloc@intercharclass=257
+  \xe at alloc@intercharclass=\z@
+
+
+\fi
+\makeatother
+
+\begin{document}
+
+\XeTeXinterchartokenstate = 1
+
+\newXeTeXintercharclass \mycharclassa
+\newXeTeXintercharclass \mycharclassA
+\newXeTeXintercharclass \mycharclassB
+
+\XeTeXcharclass `\a \mycharclassa
+\XeTeXcharclass `\A \mycharclassA
+\XeTeXcharclass `\B \mycharclassB
+
+% between "a" and "A":
+\XeTeXinterchartoks \mycharclassa \mycharclassA = {[\itshape}
+\XeTeXinterchartoks \mycharclassA \mycharclassa = {\upshape]}
+
+% between " " and "B":
+%\XeTeXinterchartoks 4095 \mycharclassB = {\bgroup\color{blue}(}
+%\XeTeXinterchartoks \mycharclassB 4095 = {)\egroup}
+
+%\XeTeXinterchartoks 4095 \mycharclassB = {(}% this one loops
+\XeTeXinterchartoks \mycharclassB 4095 = {)}
+
+% between "B" and "B":
+\XeTeXinterchartoks \mycharclassB \mycharclassB = {.}
+
+aAa A a B aBa BB
+
+
+
+
+\end{document}
+
diff --git a/xxclasses.lua b/xxclasses.lua
new file mode 100644
index 0000000..3abd89c
--- /dev/null
+++ b/xxclasses.lua
@@ -0,0 +1,57 @@
+
+xxclasses={}
+xxclasstoks={}
+
+function XeTeXcharclass()
+local a = token.scan_int()
+local b = token.scan_int()
+xxclasses[a]=b
+end
+local func = luatexbase.new_luafunction 'XeTeXcharclass'
+token.set_lua('XeTeXcharclass', func , "protected")
+lua.get_functions_table()[func] = XeTeXcharclass
+
+function XeTeXinterchartoks()
+local a = token.scan_int()
+local b = token.scan_int()
+token.scan_keyword(' ')
+token.scan_keyword('=')
+token.scan_keyword(' ')
+local c = token.scan_argument(false)
+xxclasstoks[a .. "/" .. b]=c
+end
+local func = luatexbase.new_luafunction 'XeTeXinterchartoks'
+token.set_lua('XeTeXinterchartoks', func , "protected")
+lua.get_functions_table()[func] = XeTeXinterchartoks
+
+
+glyphid=node.id"glyph"
+
+local function xxinterchartoks(head)
+    if not (tex.count.XeTeXinterchartokenstate > 0) then
+        return head
+    end
+
+    for n in node.traverse(head) do
+    local a = 4095
+    local b = 4095
+    if n.id==glyphid then
+     a = xxclasses[n.char] or 0
+    end
+    if n.next and n.next.id==glyphid then
+     b = xxclasses[n.next.char] or 0
+    end
+        if xxclasstoks[a .. "/" .. b] then
+	print("AAb" .. xxruninterchartoksnum)
+	print(a,b)
+	print("AAc" .. xxclasstoks[a .. "/" .. b])
+	    tex.scantoks(xxinterchartoksnum,0,xxclasstoks[a .. "/" .. b])
+            tex.runtoks("xxruninterchartoks")
+            local box = tex.getbox("xxintercharbox")
+            node.insert_after(head, n, node.copy_list(box))
+        end
+    end
+    return head
+end
+
+luatexbase.add_to_callback("pre_linebreak_filter", xxinterchartoks,"xx hmm")
\ No newline at end of file





More information about the latex3-commits mailing list.