Skip to content

Commit

Permalink
feat: Display math equation numbers now use a resilient style (eqno)
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Sep 28, 2024
1 parent 3ff6c3d commit 0b48447
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,37 @@ function class:_init (options)
self:registerCommand("urlstyle", function (_, content)
SILE.call("style:apply", { name = "url" }, content)
end)

-- Override the standard math:numberingstyle hook to rely on styles,
-- and also to subscribe for cross-references.
-- Package "math" is loaded by the markdown package.
self:registerCommand("math:numberingstyle", function (options, _)
local text
if options.counter then
local fnSty = self:resolveStyle("eqno")
local display = fnSty.numbering and fnSty.numbering.display or "arabic"
-- Enforce the display style for the counter
-- (which might be the default 'equation' counter, or a custom one)
SILE.call("set-counter", { id = options.counter, display = display })
text = self.packages.counters:formatCounter(SILE.scratch.counters[options.counter])
elseif options.number then
text = options.number
else
SU.error("No counter or number provided for math numbering")
end
-- Cross-ref support (from markdown, we can get an id, in most of our packages,
-- we can get a marker, play fair with all)
local mark = options.id or options.marker
if mark then
local labelRefs = self.packages.labelrefs
labelRefs:pushLabelRef(text)
SILE.call("style:apply:number", { name = "eqno", text = text })
SILE.call("label", { marker = mark })
labelRefs:popLabelRef()
else
SILE.call("style:apply:number", { name = "eqno", text = text })
end
end)
end

function class:declareOptions ()
Expand Down Expand Up @@ -382,6 +413,15 @@ function class:registerStyles ()
self:registerStyle("url", { inherit = "code"}, {
})

-- display math equation numberstyle
self:registerStyle("eqno", {}, {
numbering = {
before = { text = "(" },
display = "arabic",
after = { text = ")" }
}
})

-- Special non-standard style for dropcaps (for commands initial-joined and initial-unjoined)
self:registerStyle("dropcap", {}, {
font = { family = "Zallman Caps" },
Expand Down
1 change: 1 addition & 0 deletions examples/manual-styling/advanced/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Readers experienced with SILE’s standard packages also have to be aware that t
For instance, the (standard) **url** package provides a `urlstyle` hook command. While you could override it---that is, redefine that command---, please note that this is what the resilient classes already do, so as to delegate the decision to a style conveniently called `urlstyle` too.[^other-sile-hooks]

[^other-sile-hooks]: The same principle actually applies to page numbers, relying on the standard **folio** package. The latter provides a `foliostyle` hook, which the resilient styling system overrides with its own clever logic.
Likewise, the `math:numberstyle` hook from the **math** package is also redefined, to rely on the `eqno` style for display math equation numbers.

In other terms, even for standard SILE packages, we may already have provided a style-aware version of their original customization hooks.

0 comments on commit 0b48447

Please sign in to comment.