diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/char-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/char-ini.lua | 95 |
1 files changed, 64 insertions, 31 deletions
diff --git a/Master/texmf-dist/tex/context/base/char-ini.lua b/Master/texmf-dist/tex/context/base/char-ini.lua index 89f8336f826..244b8d2a70e 100644 --- a/Master/texmf-dist/tex/context/base/char-ini.lua +++ b/Master/texmf-dist/tex/context/base/char-ini.lua @@ -8,14 +8,15 @@ if not modules then modules = { } end modules ['char-ini'] = { -- todo: make two files, one for format generation, one for format use +-- we can remove the tag range starting at 0xE0000 (special applications) + local tex = tex local utf = unicode.utf8 local utfchar, utfbyte, utfvalues = utf.char, utf.byte, string.utfvalues local ustring = unicode.ustring -local concat, unpack = table.concat, table.unpack +local concat, unpack, tohash = table.concat, table.unpack, table.tohash local next, tonumber, type, rawget, rawset = next, tonumber, type, rawget, rawset -local texsprint, texprint = tex.sprint, tex.print local format, lower, gsub, match, gmatch = string.format, string.lower, string.gsub, string.match, string.match, string.gmatch local P, R, lpegmatch = lpeg.P, lpeg.R, lpeg.match @@ -25,11 +26,14 @@ local texsetlccode = tex.setlccode local texsetuccode = tex.setuccode local texsetsfcode = tex.setsfcode local texsetcatcode = tex.setcatcode + +local contextsprint = context.sprint local ctxcatcodes = tex.ctxcatcodes local texcatcodes = tex.texcatcodes + local setmetatableindex = table.setmetatableindex -local trace_defining = false trackers.register("characters.defining", function(v) characters_defining = v end) +local trace_defining = false trackers.register("characters.defining", function(v) characters_defining = v end) local report_defining = logs.reporter("characters") @@ -105,11 +109,11 @@ setmetatableindex(data, function(t,k) if tk == "string" then k = lpegmatch(pattern,k) or utfbyte(k) if k then - local tk = rawget(t,k) - if tk then - return tk + local v = rawget(t,k) + if v then + return v else - -- goes to ranges + tk = "number" -- fall through to range end else return private @@ -121,10 +125,10 @@ setmetatableindex(data, function(t,k) if k >= rr.first and k <= rr.last then local extender = rr.extender if extender then - v = extender(k,v) + local v = extender(k,v) + t[k] = v + return v end - t[k] = v - return v end end end @@ -366,7 +370,7 @@ characters.categorytags = categorytags --~ special : cf (softhyphen) zs (emspace) --~ characters: ll lm lo lt lu mn nl no pc pd pe pf pi po ps sc sk sm so -local is_character = allocate ( table.tohash { +local is_character = allocate ( tohash { "lu","ll","lt","lm","lo", "nd","nl","no", "mn", @@ -375,19 +379,19 @@ local is_character = allocate ( table.tohash { "sm","sc","sk","so" } ) -local is_letter = allocate ( table.tohash { +local is_letter = allocate ( tohash { "ll","lm","lo","lt","lu" } ) -local is_command = allocate ( table.tohash { +local is_command = allocate ( tohash { "cf","zs" } ) -local is_spacing = allocate ( table.tohash { +local is_spacing = allocate ( tohash { "zs", "zl","zp", } ) -local is_mark = allocate ( table.tohash { +local is_mark = allocate ( tohash { "mn", "ms", } ) @@ -416,7 +420,7 @@ setmetatableindex(characters.is_spacing, mt) -- linebreak: todo: hash -- -- normative : BK CR LF CM SG GL CB SP ZW NL WJ JL JV JT H2 H3 --- informative : XX OP CL QU NS EX SY IS PR PO NU AL ID IN HY BB BA SA AI B2 +-- informative : XX OP CL QU NS EX SY IS PR PO NU AL ID IN HY BB BA SA AI B2 new:CP -- east asian width: -- @@ -485,20 +489,28 @@ use the table. After all, we have this information available anyway.</p> --ldx]]-- function characters.makeactive(n,name) -- let ? - texsprint(ctxcatcodes,format("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name)) + contextsprint(ctxcatcodes,format("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name)) -- context("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name) end function tex.uprint(c,n) if n then - -- texsprint(c,charfromnumber(n)) - texsprint(c,utfchar(n)) + -- contextsprint(c,charfromnumber(n)) + contextsprint(c,utfchar(n)) else - -- texsprint(charfromnumber(c)) - texsprint(utfchar(c)) + -- contextsprint(charfromnumber(c)) + contextsprint(utfchar(c)) end end +local temphack = tohash { + 0x00A0, + 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x200C, 0x200D, + 0x202F, + 0x205F, + -- 0xFEFF, +} + function characters.define(tobelettered, tobeactivated) -- catcodetables if trace_defining then @@ -510,7 +522,7 @@ function characters.define(tobelettered, tobeactivated) -- catcodetables for u, chr in next, data do -- these will be commands local fallback = chr.fallback if fallback then - texsprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\checkedchar{",u,"}{",fallback,"}}}") -- no texprint + contextsprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\checkedchar{",u,"}{",fallback,"}}}") a = a + 1 activated[a] = u else @@ -520,17 +532,19 @@ function characters.define(tobelettered, tobeactivated) -- catcodetables if is_character[category] then if chr.unicodeslot < 128 then if is_letter[category] then - texprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,utfchar(u))) + contextsprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,utfchar(u))) -- has no s else - texprint(ctxcatcodes,format("\\chardef\\%s=%s",contextname,u)) + contextsprint(ctxcatcodes,format("\\chardef\\%s=%s",contextname,u)) -- has no s end else - texprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,utfchar(u))) + contextsprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,utfchar(u))) -- has no s end elseif is_command[category] then - texsprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\"..contextname,"}}") -- no texprint +if not temphack[u] then + contextsprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\"..contextname,"}}") a = a + 1 activated[a] = u +end end end end @@ -564,7 +578,9 @@ function characters.define(tobelettered, tobeactivated) -- catcodetables if tobeactivated and nofactivated > 0 then for i=1,nofactivated do local u = activated[i] - report_defining("character 0x%05X is active in sets %s (%s)",u,concat(tobeactivated,","),data[u].description) + if u then + report_defining("character 0x%05X is active in sets %s (%s)",u,concat(tobeactivated,","),data[u].description) + end end local saved = tex.catcodetable for i=1,#tobeactivated do @@ -574,7 +590,10 @@ function characters.define(tobelettered, tobeactivated) -- catcodetables end tex.catcodetable = vector for i=1,nofactivated do - texsetcatcode(activated[i],13) + local u = activated[i] + if u then + texsetcatcode(u,13) + end end end tex.catcodetable = saved @@ -664,7 +683,7 @@ end -- xml support (moved) function characters.remapentity(chr,slot) - texsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr)) + contextsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr)) end characters.activeoffset = 0x10000 -- there will be remapped in that byte range @@ -724,11 +743,21 @@ setmetatableindex(shchars, function(t,u) if u then local c = data[u] c = c and c setmetatableindex(fschars, function(t,u) if u then local c = data[u] c = c and c.fscode c = c and utfstring(c) or (type(u) == "number" and utfchar(u)) or u t[u] = c return c end end) local decomposed = allocate() characters.decomposed = decomposed -- lazy table +local specials = allocate() characters.specials = specials -- lazy table setmetatableindex(decomposed, function(t,u) -- either a table or false if u then local c = data[u] - local s = c and c.decomposed or false + local s = c and c.decomposed or false -- could fall back to specials + t[u] = s + return s + end +end) + +setmetatableindex(specials, function(t,u) -- either a table or false + if u then + local c = data[u] + local s = c and c.specials or false t[u] = s return s end @@ -863,7 +892,7 @@ function characters.flush(n,direct) if direct then return c else - texsprint(c) + contextsprint(c) end end @@ -986,3 +1015,7 @@ if not characters.superscripts then storage.register("characters/subscripts", subscripts, "characters.subscripts") end + +-- interface + +commands.utfchar = tex.uprint |