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 7cca8fa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
48 changes: 48 additions & 0 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,45 @@ 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 (opts, _)
local text
local stylename = "eqno"
if opts.counter then
local altname = "eqno-" .. opts.counter
local fnSty = self:resolveStyle(altname, true) -- discardable
if not next(fnSty) then
fnSty = self:resolveStyle(stylename) -- fallback
else
stylename = altname
end

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 = opts.counter, display = display })
text = self.packages.counters:formatCounter(SILE.scratch.counters[opts.counter])
elseif opts.number then
text = opts.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 = opts.id or opts.marker
if mark then
local labelRefs = self.packages.labelrefs
labelRefs:pushLabelRef(text)
SILE.call("style:apply:number", { name = stylename, text = text })
SILE.call("label", { marker = mark })
labelRefs:popLabelRef()
else
SILE.call("style:apply:number", { name = stylename, text = text })
end
end)
end

function class:declareOptions ()
Expand Down Expand Up @@ -382,6 +421,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 (and actually, if it exist and is non-emppty, to the `eqno-⟨counter⟩` style specific to the counter in question, by default `equation`).

In other terms, even for standard SILE packages, we may already have provided a style-aware version of their original customization hooks.
27 changes: 19 additions & 8 deletions examples/sile-resilient-manual-styles.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
md-mark:
style:
decoration:
line: "mark"
color: "orange"
rough: true

blockquote:
origin: "resilient.book"
Expand Down Expand Up @@ -173,6 +167,16 @@ epigraph-text:
paragraph:
align: "justify"

eqno:
origin: "resilient.book"
style:
numbering:
after:
text: ")"
before:
text: "("
display: "arabic"

fancytoc-base:
style:

Expand Down Expand Up @@ -532,6 +536,13 @@ lists-itemize6:
itemize:
symbol: ""

md-mark:
style:
decoration:
color: "orange"
line: "mark"
rough: true

poetry:
origin: "resilient.poetry"
style:
Expand Down Expand Up @@ -1050,9 +1061,9 @@ verbatim:
origin: "resilient.verbatim"
style:
paragraph:
after:
skip: "smallskip"
align: "obeylines"
before:
skip: "smallskip"
after:
skip: "smallskip"

0 comments on commit 7cca8fa

Please sign in to comment.