Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbered equations #1821

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions packages/math/init.lua
Original file line number Diff line number Diff line change
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 @@ -64,21 +65,35 @@ function package:registerCommands ()
self:registerCommand("mathml", function (options, content)
local mode = (options and options.mode) and options.mode or 'text'
local mbox
local counter = SU.boolean(options.numbered, false) and "equation"
counter = options.counter or counter -- overrides the default "equation" counter
xpcall(function()
mbox = self:ConvertMathML(content, mbox)
end, function(err) print(err); print(debug.traceback()) end)
self:handleMath(mbox, mode)
self:handleMath(mbox, mode, counter)
end)

self:registerCommand("math", function (options, content)
local mode = (options and options.mode) and options.mode or "text"
local mbox
local counter = SU.boolean(options.numbered, false) and "equation"
counter = options.counter or counter -- overrides the default "equation" 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:numberingstyle", function (options, _)
SILE.typesetter:typeset("(")
SILE.call("show-counter", { id=options.id })
SILE.typesetter:typeset(")")
end)





Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Lots of extra blank lines inserted!

end

package.documentation = [[
Expand Down Expand Up @@ -344,6 +359,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{Numbered equations}
Equations can be numbered in display mode adding the options \autodoc:parameter{numbered} and \autodoc:parameter{counter}.
When \autodoc:parameter{numbered=true}, the equations are numbered using a default "equation" counter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: "example" --> “example” with curly typographical quote marks.

A different counter may be set by using the option \autodoc:parameter{counter=id}, and this setting will also enable numbering.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: \autodoc:parameter{counter=id} --> \autodoc:parameter{counter=<id>}
The angle brackets are replaced with nice brackets and the content is shown in a different color when autodoc.autodoc.highlighting is enabled. (And italic would possibly be used, although maybe the Hack Italic font is not installed in regular builds, IIRC)

The default numbering format is "(xx)", but this style may be overriden by defining a custom \autodoc:command{\math:numberingstyle} function, e.g.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"(xx)" --> I would suggest \autodoc:example{(xx)}` so that it is typeset in the example font (Cormorant Infant currently) as other examples of "rendered content". We could avoid the quote marks here, then: no need for double marking! (But if we want to keep them, then use typographical quote marks.


\begin[type=autodoc:codeblock]{raw}
\define[command=math:numberingstyle]{(\show-counter[id="equation"])}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fond of the example using a macro, because macros can't use options, so here this example would always use the "equation" counter regardless of what the user passed to the \math command. I'd suggest removing the example, and just expanding the description as follows (my changes in bold):

... this style may be overridden by defining a custom \autodoc:command{\math:numberingstyle} command. The counter id is passed as parameter to this hook.

(By the way, overridden takes two -d-, I think)

\end{raw}



\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
12 changes: 8 additions & 4 deletions packages/math/typesetter.lua
Original file line number Diff line number Diff line change
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,13 @@ 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:pushExplicitGlue(SILE.nodefactory.hfillglue())
if counter then
SILE.call("increment-counter", { id=counter } )
SILE.call("math:numberingstyle", { id=counter } )
end
SILE.typesetter:endline()
SILE.typesetter:pushExplicitVglue(SILE.settings:get("math.displayskip"))
else
Expand Down
Loading