diff --git a/classes/resilient/book.lua b/classes/resilient/book.lua index fd4a317..1d9beb2 100644 --- a/classes/resilient/book.lua +++ b/classes/resilient/book.lua @@ -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 () @@ -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" }, diff --git a/examples/manual-styling/advanced/other.md b/examples/manual-styling/advanced/other.md index 5de9ad7..2d39b93 100644 --- a/examples/manual-styling/advanced/other.md +++ b/examples/manual-styling/advanced/other.md @@ -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. diff --git a/examples/sile-resilient-manual-styles.yml b/examples/sile-resilient-manual-styles.yml index 9c2f3e1..0393e91 100644 --- a/examples/sile-resilient-manual-styles.yml +++ b/examples/sile-resilient-manual-styles.yml @@ -1,9 +1,3 @@ -md-mark: - style: - decoration: - line: "mark" - color: "orange" - rough: true blockquote: origin: "resilient.book" @@ -173,6 +167,16 @@ epigraph-text: paragraph: align: "justify" +eqno: + origin: "resilient.book" + style: + numbering: + after: + text: ")" + before: + text: "(" + display: "arabic" + fancytoc-base: style: @@ -532,6 +536,13 @@ lists-itemize6: itemize: symbol: "–" +md-mark: + style: + decoration: + color: "orange" + line: "mark" + rough: true + poetry: origin: "resilient.poetry" style: @@ -1050,9 +1061,9 @@ verbatim: origin: "resilient.verbatim" style: paragraph: + after: + skip: "smallskip" align: "obeylines" before: skip: "smallskip" - after: - skip: "smallskip"