[latex3-commits] [git/LaTeX3-latex3-xxetex] main: character classes (6c37523)

David Carlisle d.p.carlisle at gmail.com
Sat Jan 28 11:23:52 CET 2023


Repository : https://github.com/latex3/xxetex
On branch  : main
Link       : https://github.com/latex3/xxetex/commit/6c375235f818328a8f8e347a3920ae0638f6c8cc

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

commit 6c375235f818328a8f8e347a3920ae0638f6c8cc
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Sat Jan 28 10:23:52 2023 +0000

    character classes


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

6c375235f818328a8f8e347a3920ae0638f6c8cc
 classes.tex => examples/test-charclass1.tex | 44 +++++------------
 xxclasses.lua                               | 62 -----------------------
 xxetex.lua                                  | 64 ++++++++++++++++++++++++
 xxetex.tex                                  | 76 ++++++++++++++++++++++++-----
 4 files changed, 140 insertions(+), 106 deletions(-)

diff --git a/classes.tex b/examples/test-charclass1.tex
similarity index 58%
rename from classes.tex
rename to examples/test-charclass1.tex
index b12577d..d71d715 100644
--- a/classes.tex
+++ b/examples/test-charclass1.tex
@@ -10,40 +10,14 @@
 
 \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@
-
-
+\ifdefined\directlua
+\input{xxetex.tex}
 \fi
-\makeatother
+
 
 \begin{document}
 
-\XeTeXinterchartokenstate = 1
+
 
 \newXeTeXintercharclass \mycharclassa
 \newXeTeXintercharclass \mycharclassA
@@ -65,9 +39,17 @@
 % between "B" and "B":
 \XeTeXinterchartoks \mycharclassB \mycharclassB = {.}
 
-aAa A a B aBa BB x
 
 
+aAa A a B aBa BB 
+
+\XeTeXinterchartokenstate = 1
+
+aAa A a B aBa BB 
+
+\XeTeXinterchartokenstate = 0
+
+aAa A a B aBa BB 
 
 
 \end{document}
diff --git a/xxclasses.lua b/xxclasses.lua
deleted file mode 100644
index 56dd8cb..0000000
--- a/xxclasses.lua
+++ /dev/null
@@ -1,62 +0,0 @@
-
-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
-    xxflag=-1
-    for n in node.traverse(head) do
-    local a = 4095
-    local b = 4095
-    if xxflag==n then xxflag=-1 end
-    if xxflag ==-1 then
-    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])
-	    xxflag=1
-	    if n.next then xxflag=n.next end
-	    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
-    end
-    return head
-end
-
-luatexbase.add_to_callback("pre_linebreak_filter", xxinterchartoks,"xx hmm")
\ No newline at end of file
diff --git a/xxetex.lua b/xxetex.lua
index cbc7c85..63720f9 100644
--- a/xxetex.lua
+++ b/xxetex.lua
@@ -134,6 +134,68 @@ local function XeTeXglyphbounds()
     end
 end
 
+
+-- Character Classes
+
+
+local xxetexclasses={}
+local xxetexclasstoks={}
+
+local function XeTeXcharclass()
+local a = token.scan_int()
+local b = token.scan_int()
+xxetexclasses[a]=b
+end
+local func = luatexbase.new_luafunction 'XeTeXcharclass'
+token.set_lua('XeTeXcharclass', func , "protected")
+lua.get_functions_table()[func] = XeTeXcharclass
+
+local 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)
+xxetexclasstoks[a .. "/" .. b]=c
+end
+local func = luatexbase.new_luafunction 'XeTeXinterchartoks'
+token.set_lua('XeTeXinterchartoks', func , "protected")
+lua.get_functions_table()[func] = XeTeXinterchartoks
+
+
+
+
+local function xxetexinterchartoks(head)
+    if not (tex.count.XXeTeXinterchartokenstate > 0) then
+        return head
+    end
+    local glyphid=node.id"glyph"
+    local xxetexflag=-1
+    for n in node.traverse(head) do
+    local a = 4095
+    local b = 4095
+    if xxetexflag==n then xxetexflag=-1 end
+    if xxetexflag ==-1 then
+    if n.id==glyphid then
+     a = xxetexclasses[n.char] or 0
+    end
+    if n.next and n.next.id==glyphid then
+     b = xxetexclasses[n.next.char] or 0
+    end
+        if xxetexclasstoks[a .. "/" .. b] then
+	    xxetexflag=-1
+	    if n.next then xxetexflag=n.next end
+	    tex.scantoks(xxetexinterchartoksnum,0,xxetexclasstoks[a .. "/" .. b])
+            tex.runtoks("xxetexruninterchartoks")
+            local box = tex.getbox("xxetex at intercharbox")
+            node.insert_after(head, n, node.copy_list(box))	
+        end
+    end
+    end
+    return head
+end
+
 return {
     XeTeXfonttype      = XeTeXfonttype,
     XeTeXfirstfontchar = XeTeXfirstfontchar,
@@ -144,4 +206,6 @@ return {
     XeTeXglyphindex    = XeTeXglyphindex,
     XeTeXcharglyph     = XeTeXcharglyph,
     XeTeXglyphbounds   = XeTeXglyphbounds,
+    --
+    xxetexinterchartoks = xxetexinterchartoks,
 }
diff --git a/xxetex.tex b/xxetex.tex
index 26bf672..38a69e6 100644
--- a/xxetex.tex
+++ b/xxetex.tex
@@ -7,11 +7,9 @@
 %\catcode`\{=1
 %\catcode`\}=2
 \catcode`\@=11
-\catcode`\!=11
 %\catcode`\_=11
 %\catcode`\:=11
 
-\let\@@!directlua\directlua %\let\directlua\undefined
 
 \chardef\XeTeXversion=0
 \def\XeTeXrevision{.99999}%
@@ -21,17 +19,69 @@
 
 \let\XeTeXmathcode\Umathcode
 
-\@@!directlua{xxetex = xxetex or require("xxetex.lua")}
-
-\protected\def\XeTeXfonttype     {\@@!directlua{xxetex.XeTeXfonttype()}}
-\protected\def\XeTeXfirstfontchar{\@@!directlua{xxetex.XeTeXfirstfontchar()}}
-\protected\def\XeTeXlastfontchar {\@@!directlua{xxetex.XeTeXlastfontchar()}}
-          \def\XeTeXglyph        {\@@!directlua{xxetex.XeTeXglyph()}}
-\protected\def\XeTeXcountglyphs  {\@@!directlua{xxetex.XeTeXcountglyphs()}}
-          \def\XeTeXglyphname    {\@@!directlua{xxetex.XeTeXglyphname()}}
-\protected\def\XeTeXglyphindex   {\@@!directlua{xxetex.XeTeXglyphindex()}}
-\protected\def\XeTeXcharglyph    {\@@!directlua{xxetex.XeTeXcharglyph()}}
-\protected\def\XeTeXglyphbounds  {\@@!directlua{xxetex.XeTeXglyphbounds()}}
+\directlua{xxetex = xxetex or require("xxetex.lua")}
+
+%% Font related commands
+\protected\def\XeTeXfonttype     {\directlua{xxetex.XeTeXfonttype()}}
+\protected\def\XeTeXfirstfontchar{\directlua{xxetex.XeTeXfirstfontchar()}}
+\protected\def\XeTeXlastfontchar {\directlua{xxetex.XeTeXlastfontchar()}}
+          \def\XeTeXglyph        {\directlua{xxetex.XeTeXglyph()}}
+\protected\def\XeTeXcountglyphs  {\directlua{xxetex.XeTeXcountglyphs()}}
+          \def\XeTeXglyphname    {\directlua{xxetex.XeTeXglyphname()}}
+\protected\def\XeTeXglyphindex   {\directlua{xxetex.XeTeXglyphindex()}}
+\protected\def\XeTeXcharglyph    {\directlua{xxetex.XeTeXcharglyph()}}
+\protected\def\XeTeXglyphbounds  {\directlua{xxetex.XeTeXglyphbounds()}}
+
+
+
+
+%% interchartoks (approximated by internode toks)
+
+
+
+%
+\newcount\XXeTeXinterchartokenstate 
+\def\XeTeXinterchartokenstateON{\directlua{
+if not(luatexbase.in_callback("pre_linebreak_filter",
+                              "xxetex interchartoks")) then
+luatexbase.add_to_callback("pre_linebreak_filter",
+                           xxetex.xxetexinterchartoks,
+                           "xxetex interchartoks")
+end}}
+\def\XeTeXinterchartokenstateOFF{\directlua{
+if luatexbase.in_callback("pre_linebreak_filter",
+                          "xxetex interchartoks") then
+luatexbase.remove_from_callback("pre_linebreak_filter",
+                                "xxetex interchartoks")
+end
+}}
+% avoid registering the callback if \XeTeXinterchartokenstate is not used
+\protected\def\XeTeXinterchartokenstate{%
+   \XeTeXinterchartokenstateON\XXeTeXinterchartokenstate}
+
+\newtoks\xxetex at interchartoks
+
+\directlua{xxetexinterchartoksnum=\the\allocationnumber}
+\newbox\xxetex at intercharbox
+\newtoks\xxetexruninterchartoks
+\directlua{xxetexruninterchartoksnum=\the\allocationnumber}
+\xxetexruninterchartoks={%
+  \global\setbox\xxetex at intercharbox\hpack{\the\xxetex at interchartoks}}
+
+
+
+\ifx\newXeTeXintercharclass\@undefined
+% from latex.ltx
+\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
+
 
 %\catcode`\{=12
 %\catcode`\{=12





More information about the latex3-commits mailing list.