Skip to content

Commit

Permalink
feat(math): Add parameter to draw debug boxes around math components
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole authored and alerque committed Sep 8, 2021
1 parent 4290cee commit 2458d18
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/math.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ local mathScriptConversionTable = {
}

SILE.settings.declare({name = "math.font.family", type = "string", default = "XITS Math"})
-- Whether to show debug boxes around mboxes
SILE.settings.declare({name = "math.debug.boxes", type = "boolean", default = false})

local mathCache

Expand All @@ -102,7 +104,9 @@ local function getMathMetrics(options)
for k,v in pairs(mathTable.mathConstants) do
if type(v) == "table" then v = v.value end
if k:sub(-9) == "ScaleDown" then constants[k] = v / 100
else constants[k] = v * options.size / upem end
else
constants[k] = v * options.size / upem
end
end
local italicsCorrection = {}
for k, v in pairs(mathTable.mathItalicsCorrection) do
Expand Down Expand Up @@ -195,6 +199,14 @@ local function maxLength(...)
return result
end

local function minLength(...)
local args = {...}
for i, v in ipairs(args) do
args[i] = args[i] * (-1)
end
return -maxLength(args)
end

local function getNumberFromLength(length, line)
local number = length.length
if line.ratio and line.ratio < 0 and length.shrink > 0 then
Expand Down Expand Up @@ -275,6 +287,7 @@ local _mbox = _box {
-- Output the node and all its descendants
outputTree = function(self, x, y, line)
self:output(x, y, line)
local debug = SILE.settings.get("math.debug.boxes")
if debug and typeof(self) ~= "Space" then
SILE.outputter.moveTo(getNumberFromLength(x, line), y.length)
SILE.outputter.debugHbox(
Expand Down Expand Up @@ -903,7 +916,6 @@ SILE.nodefactory.math = {

SILE.registerCommand("math", function (options, content)
local mode = (options and options.mode) and options.mode or 'text'
debug = options and options.debug

local mbox = ConvertMathML(content, mbox)

Expand All @@ -924,4 +936,4 @@ SILE.registerCommand("math", function (options, content)

SILE.typesetter:pushHorizontal(mbox)

end)
end)

0 comments on commit 2458d18

Please sign in to comment.