summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/math-pre.lmt
blob: d10f80cfede4270a00da2926d8125b0fc60489f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
if not modules then modules = { } end modules ['math-pre'] = {
    version   = 1.001,
    optimize  = true,
    comment   = "companion to math-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local type = type
local gmatch = string.gmatch

local h1 = table.swapped(tex.getmathparametervalues())
local h2 = table.swapped(tex.getmathstylenamevalues())

local axis = h1.axis

local getmath = tex.getmath
local setmath = tex.setmath

function setmathparameters(t)
    if t then
        for i=1,#t do
            local ti     = t[i]
            local list   = ti.list
            local factor = ti.factor or 1
            local styles = ti.styles
            local value  = ti.value
            local unit   = ti.unit

            local function set(li,si,value)
                if value then
                    setmath(li,si,value)
                elseif factor == 0 then
                    setmath(li,si,0)
                elseif unit == "axis" then
                    setmath(li,si,factor * getmath(axis,i))
                else
                    setmath(li,si,factor * getmath(li,i))
                end
            end

            for i=1,#list do
                local li = h1[list[i]]
                if li then
                    if styles == "all" then
                        for si=0,7 do
                            set(li,si,value)
                        end
                    elseif type(styles) == "string" then
                        local si = h2[styles]
                        if si then
                            set(li,si,value)
                        end
                    else
                        for s=1,#styles do
                            local si = h2[styles[s]]
                            if si then
                                set(li,si,value)
                            end
                        end
                    end
                end
            end
        end
    end
end

local stacklist = {
    "fractionnumvgap",
    "fractiondenomvgap",
    "fractionnumup",
    "fractiondenomdown",
    "stackdenomdown",
    "stacknumup",
    "stackvgap",
}

local presets = {
    less = {
        {
            factor = .5,
         -- factor = 0,
         -- value  = 655360,
         -- unit   = "axis",
            list   = stacklist,
         -- styles = { "display" },
         -- styles = "display",
            styles = "all"
        },
    },
    more = {
        {
            factor = 2,
            list   = stacklist,
            styles = "all"
        },
    },
    zero = {
        {
            factor = 0,
            list   = stacklist,
            styles = "all"
        },
    },
}

mathematics.presets = presets

function mathematics.preset(list)
    for s in gmatch(list,"[%S,]+") do
        setmathparameters(presets[s])
    end
end

interfaces.implement {
    name      = "presetmathematics",
    public    = true,
    protected = true,
    arguments = "optional",
    actions   = mathematics.preset,
}