summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-map.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/math-map.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/math-map.lua53
1 files changed, 38 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/context/base/math-map.lua b/Master/texmf-dist/tex/context/base/math-map.lua
index d3e8cc110e4..b6d57bff531 100644
--- a/Master/texmf-dist/tex/context/base/math-map.lua
+++ b/Master/texmf-dist/tex/context/base/math-map.lua
@@ -20,19 +20,24 @@ if not modules then modules = { } end modules ['math-map'] = {
-- maybe: script/scriptscript dynamic,
local type, next = type, next
-local floor = math.floor
+local floor, div = math.floor, math.div
+
+local allocate = utilities.storage.allocate
local texattribute = tex.attribute
local trace_greek = false trackers.register("math.greek", function(v) trace_greek = v end)
-mathematics = mathematics or { }
+local report_remapping = logs.reporter("mathematics","remapping")
+
+mathematics = mathematics or { }
+local mathematics = mathematics
-- we could use one level less and have tf etc be tables directly but the
-- following approach permits easier remapping of a-a, A-Z and 0-9 to
-- fallbacks; symbols is currently mostly greek
-mathematics.alphabets = {
+local alphabets = allocate {
regular = {
tf = {
digits = 0x00030,
@@ -267,7 +272,8 @@ mathematics.alphabets = {
},
}
-local alphabets = mathematics.alphabets
+mathematics.alphabets = alphabets
+
local mathremap = { }
for alphabet, styles in next, alphabets do
@@ -344,12 +350,12 @@ alphabets.serif = alphabets.regular
alphabets.type = alphabets.monospaced
alphabets.teletype = alphabets.monospaced
-function mathematics.to_a_style(attribute)
+function mathematics.tostyle(attribute)
local r = mathremap[attribute]
return r and r.style or "tf"
end
-function mathematics.to_a_name(attribute)
+function mathematics.toname(attribute)
local r = mathremap[attribute]
return r and r.alphabet or "regular"
end
@@ -358,13 +364,13 @@ end
local mathalphabet = attributes.private("mathalphabet")
-function mathematics.sync_a_both(alphabet,style)
+function mathematics.syncboth(alphabet,style)
local data = alphabets[alphabet or "regular"] or alphabets.regular
data = data[style or "tf"] or data.tf
texattribute[mathalphabet] = data and data.attribute or texattribute[mathalphabet]
end
-function mathematics.sync_a_style(style)
+function mathematics.syncstyle(style)
--~ local r = mathremap[mathalphabet]
local r = mathremap[texattribute[mathalphabet]]
local alphabet = r and r.alphabet or "regular"
@@ -372,7 +378,7 @@ function mathematics.sync_a_style(style)
texattribute[mathalphabet] = data and data.attribute or texattribute[mathalphabet]
end
-function mathematics.sync_a_name(alphabet)
+function mathematics.syncname(alphabet)
--~ local r = mathremap[mathalphabet]
local r = mathremap[texattribute[mathalphabet]]
local style = r and r.style or "tf"
@@ -390,7 +396,7 @@ local remapping = {
[3] = { what = "italic", tf = "it", bf = "bi" }, -- italic
}
-function mathematics.remap_alphabets(char,mathalphabet,mathgreek)
+function mathematics.remapalphabets(char,mathalphabet,mathgreek)
if mathgreek > 0 then
local lc, uc = floor(mathgreek/10), mathgreek % 10 -- 2 == upright 3 == italic
if lc > 1 or uc > 1 then
@@ -400,7 +406,7 @@ function mathematics.remap_alphabets(char,mathalphabet,mathgreek)
local alphabet = r and r.alphabet or "regular"
local style = r and r.style or "tf"
if trace_greek then
- logs.report("math","before: char: %05X, alphabet: %s %s, lcgreek: %s, ucgreek: %s",char,alphabet,style,remapping[lc].what,remapping[uc].what)
+ report_remapping("before: char: %05X, alphabet: %s %s, lcgreek: %s, ucgreek: %s",char,alphabet,style,remapping[lc].what,remapping[uc].what)
end
local s = remapping[islc or isuc][style]
if s then
@@ -408,7 +414,7 @@ function mathematics.remap_alphabets(char,mathalphabet,mathgreek)
mathalphabet, style = data and data.attribute or mathalphabet, s
end
if trace_greek then
- logs.report("math","after : char: %05X, alphabet: %s %s, lcgreek: %s, ucgreek: %s",char,alphabet,style,remapping[lc].what,remapping[uc].what)
+ report_remapping("after : char: %05X, alphabet: %s %s, lcgreek: %s, ucgreek: %s",char,alphabet,style,remapping[lc].what,remapping[uc].what)
end
end
end
@@ -420,13 +426,13 @@ function mathematics.remap_alphabets(char,mathalphabet,mathgreek)
-- nothing to remap
elseif char >= 0x030 and char <= 0x039 then
local o = offset.digits
- newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x030 + o)
+ newchar = o and ((type(o) == "table" and (o[char] or char)) or (char - 0x030 + o))
elseif char >= 0x041 and char <= 0x05A then
local o = offset.ucletters
- newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x041 + o)
+ newchar = o and ((type(o) == "table" and (o[char] or char)) or (char - 0x041 + o))
elseif char >= 0x061 and char <= 0x07A then
local o = offset.lcletters
- newchar = (type(o) == "table" and (o[char] or char)) or (char - 0x061 + o)
+ newchar = o and ((type(o) == "table" and (o[char] or char)) or (char - 0x061 + o))
elseif islcgreek[char] then
newchar = offset.lcgreek[char]
elseif isucgreek[char] then
@@ -438,3 +444,20 @@ function mathematics.remap_alphabets(char,mathalphabet,mathgreek)
end
return nil
end
+
+local function checkedcopy(characters,child,parent)
+ for k, v in next, child do
+ if not characters[v] then
+ characters[v] = characters[parent[k]]
+ end
+ end
+end
+
+function mathematics.addfallbacks(main)
+ local characters = main.characters
+ local regular = alphabets.regular
+ checkedcopy(characters,regular.bf.ucgreek,regular.tf.ucgreek)
+ checkedcopy(characters,regular.bf.lcgreek,regular.tf.lcgreek)
+ checkedcopy(characters,regular.bi.ucgreek,regular.it.ucgreek)
+ checkedcopy(characters,regular.bi.lcgreek,regular.it.lcgreek)
+end