summaryrefslogtreecommitdiff
path: root/tex/context/base/cldf-bas.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/cldf-bas.lua')
-rw-r--r--tex/context/base/cldf-bas.lua52
1 files changed, 37 insertions, 15 deletions
diff --git a/tex/context/base/cldf-bas.lua b/tex/context/base/cldf-bas.lua
index 30a9265bc..9cf8dcd4a 100644
--- a/tex/context/base/cldf-bas.lua
+++ b/tex/context/base/cldf-bas.lua
@@ -1,4 +1,4 @@
-if not modules then modules = { } end modules ['cldf-ini'] = {
+if not modules then modules = { } end modules ['cldf-bas'] = {
version = 1.001,
comment = "companion to cldf-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
@@ -22,6 +22,8 @@ if not modules then modules = { } end modules ['cldf-ini'] = {
-- flush(ctxcatcodes,"}")
-- end
+-- maybe use context.generics
+
local type = type
local format = string.format
local utfchar = utf.char
@@ -32,13 +34,16 @@ local generics = context.generics
local variables = interfaces.variables
local new_rule = nodes.pool.rule
+local texcount = tex.count
function context.char(k) -- used as escape too, so don't change to utf
if type(k) == "table" then
- -- for i=1,#k do
- -- context(format([[\char%s\relax]],k[i]))
- -- end
- context([[\char%s\relax]],concat(k,[[\relax\char]]))
+ local n = #k
+ if n == 1 then
+ context([[\char%s\relax]],k[1])
+ elseif n > 0 then
+ context([[\char%s\relax]],concat(k,[[\relax\char]]))
+ end
elseif k then
context([[\char%s\relax]],k)
end
@@ -98,22 +103,22 @@ context.vrule = context.hrule
-- not yet used ... but will get variant at the tex end as well
-function context.sethboxregister (n) context("\\setbox %s\\hbox",n) end
-function context.setvboxregister (n) context("\\setbox %s\\vbox",n) end
+function context.sethboxregister(n) context([[\setbox %s\hbox]],n) end
+function context.setvboxregister(n) context([[\setbox %s\vbox]],n) end
function context.starthboxregister(n)
if type(n) == "number" then
- context("\\setbox%s\\hbox\\bgroup",n)
+ context([[\setbox%s\hbox{]],n)
else
- context("\\setbox\\%s\\hbox\\bgroup",n)
+ context([[\setbox\%s\hbox{]],n)
end
end
function context.startvboxregister(n)
if type(n) == "number" then
- context("\\setbox%s\\vbox\\bgroup",n)
+ context([[\setbox%s\vbox{]],n)
else
- context("\\setbox\\%s\\vbox\\bgroup",n)
+ context([[\setbox\%s\vbox{]],n)
end
end
@@ -122,19 +127,36 @@ context.stopvboxregister = context.egroup
function context.flushboxregister(n)
if type(n) == "number" then
- context("\\box%s ",n)
+ context([[\box%s ]],n)
else
- context("\\box\\%s",n)
+ context([[\box\%s]],n)
end
end
function context.beginvbox()
- context("\\vbox\\bgroup") -- we can do \bvbox ... \evbox (less tokens)
+ context([[\vbox{]]) -- we can do \bvbox ... \evbox (less tokens)
end
function context.beginhbox()
- context("\\hbox\\bgroup") -- todo: use fast one
+ context([[\hbox{]]) -- todo: use fast one
end
context.endvbox = context.egroup
context.endhbox = context.egroup
+
+local function allocate(name,what,cmd)
+ local a = format("c_syst_last_allocated_%s",what)
+ local n = texcount[a] + 1
+ if n <= texcount.c_syst_max_allocated_register then
+ texcount[a] = n
+ end
+ context("\\global\\expandafter\\%sdef\\csname %s\\endcsname %s\\relax",cmd or what,name,n)
+ return n
+end
+
+function context.newdimen (name) return allocate(name,"dimen") end
+function context.newskip (name) return allocate(name,"skip") end
+function context.newcount (name) return allocate(name,"count") end
+function context.newmuskip(name) return allocate(name,"muskip") end
+function context.newtoks (name) return allocate(name,"toks") end
+function context.newbox (name) return allocate(name,"box","mathchar") end