math-frc.lua /size: 1728 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['math-frc'] = {
2    version   = 1.001,
3    comment   = "companion to math-frc.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local utfchar   = utf.char
10
11local context   = context
12local variables = interfaces.variables
13
14local v_no      = variables.no
15local v_yes     = variables.yes
16local v_hidden  = variables.hidden
17
18local resolved  = {
19    [0x007B] = "\\{",
20    [0x007D] = "\\}",
21}
22
23table.setmetatableindex(resolved, function(t,k)
24    local v = utfchar(k)
25    t[k] = v
26    return v
27end)
28
29local ctx_normalatop = context.normalatop
30local ctx_normalover = context.normalover
31
32local function mathfraction(how,left,right,width)
33    if how == v_no then
34        if left == 0x002E and right == 0x002E then
35            ctx_normalatop()
36        else
37            context("\\atopwithdelims%s%s",resolved[left],resolved[right])
38        end
39    elseif how == v_yes or how == v_hidden then
40        local norule = how == v_hidden and LUATEXFUNCTIONALITY > 7361 and " norule " or ""
41        if left == 0x002E and right == 0x002E then
42            context("\\normalabove%s%s%ssp",norule,width)
43        else
44            context("\\abovewithdelims%s%s%s%s%ssp",norule,resolved[left],resolved[right],width)
45        end
46    else -- v_auto
47        if left == 0x002E and right == 0x002E then
48            ctx_normalover()
49        else
50            context("\\overwithdelims%s%s",resolved[left],resolved[right])
51        end
52    end
53end
54
55interfaces.implement {
56    name      = "mathfraction",
57    actions   = mathfraction,
58    arguments = { "string", "number", "number", "dimen" }
59}
60