Skip to content

Commit

Permalink
Merge faaaf0c into 652e732
Browse files Browse the repository at this point in the history
  • Loading branch information
leorosa committed Jul 4, 2023
2 parents 652e732 + faaaf0c commit 24919e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
29 changes: 27 additions & 2 deletions packages/math/init.lua
Expand Up @@ -16,6 +16,7 @@ function package:_init ()
return value * SILE.settings:get("math.font.size") / 18
end
})
self:loadPackage("counters")
end

function package.declareSettings (_)
Expand Down Expand Up @@ -67,16 +68,28 @@ function package:registerCommands ()
xpcall(function()
mbox = self:ConvertMathML(content, mbox)
end, function(err) print(err); print(debug.traceback()) end)
self:handleMath(mbox, mode)
self:handleMath(mbox, mode, nil)
end)

self:registerCommand("math", function (options, content)
local mode = (options and options.mode) and options.mode or "text"
local mbox
local counter = (options and options.numbered) and "equation"
counter = (options and options.counter) and options.counter or counter
xpcall(function()
mbox = self:ConvertMathML(self:compileToMathML({}, self:convertTexlike(content)))
end, function(err) print(err); print(debug.traceback()) end)
self:handleMath(mbox, mode)
self:handleMath(mbox, mode, counter)
end)

self:registerCommand("math-counterstyle", function (options, _)
SILE.typesetter:typeset("(")
SILE.call("show-counter", { id=options.id })
SILE.typesetter:typeset(")")
end)

self:registerCommand("equation", function (_, content)
SILE.call("math", {mode="display", counter="equation"}, content)
end)

end
Expand Down Expand Up @@ -344,6 +357,18 @@ Finally, here is a little secret. This notation:
\noindent In other words, the notation using \code{&} and \code{\\\\} is only a syntactic sugar for a two-dimensional array constructed with braces.
\paragraph{Equations numbering}
Equations can be numbered in display mode adding the options \code{numbering} and \code{counter}.
When \code{numbering=true}, the equations are numbered using a default "equation" counter.
A different counter may be set by using the option \code{counter=id}, and this setting will also enable numbering.
The default numbering format is '(xx)', but this style may be overriden by defining a custom math-counterstyle function, e.g.
\begin[type=autodoc:codeblock]{raw}
\define[command=math-counterstyle]{(\show-counter[id="equation"])}
\end{raw}
There is also a \code{\\equation{...}}, that is an alias to \code{\\math[mode=display,counter=equation]{...}}
\paragraph{Missing features}
This package still lacks support for some mathematical constructs, but hopefully we’ll get there.
Among unsupported constructs are: decorating symbols with so-called accents, such as arrows or hats, “over” or “under” braces, and line breaking inside a formula.
Expand Down
14 changes: 10 additions & 4 deletions packages/math/typesetter.lua
Expand Up @@ -126,7 +126,7 @@ function ConvertMathML (_, content)
end
end

local function handleMath (_, mbox, mode)
local function handleMath (_, mbox, mode, counter)
if mode == 'display' then
mbox.mode = b.mathMode.display
elseif mode == 'text' then
Expand All @@ -144,9 +144,15 @@ local function handleMath (_, mbox, mode)
if mode == "display" then
SILE.typesetter:endline()
SILE.typesetter:pushExplicitVglue(SILE.settings:get("math.displayskip"))
SILE.call("center", {}, function()
SILE.typesetter:pushHorizontal(mbox)
end)
SILE.typesetter:pushGlue(SILE.nodefactory.hfillglue())
SILE.typesetter:pushHorizontal(mbox)
SILE.typesetter:pushGlue(SILE.nodefactory.hfillglue())
if counter then
SILE.call("increment-counter", { id=counter } )
SILE.call("math-counterstyle", { id=counter } )
else
SILE.call("hbox")
end
SILE.typesetter:endline()
SILE.typesetter:pushExplicitVglue(SILE.settings:get("math.displayskip"))
else
Expand Down

0 comments on commit 24919e4

Please sign in to comment.