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

Conversation

leorosa
Copy link
Contributor

@leorosa leorosa commented Jun 24, 2023

With this PR, a new 'numbered' mode is added in math, in addition to 'display' and 'text'. Equations in this mode have the same appearance of the ones in the 'display' mode, except that a counter is added at the right end of the line.

@leorosa leorosa requested a review from a team as a code owner June 24, 2023 01:19
@alerque alerque added this to the v0.14.10 milestone Jun 24, 2023
@alerque alerque added the enhancement Software improvement or feature request label Jun 24, 2023
packages/math/init.lua Outdated Show resolved Hide resolved
packages/math/init.lua Outdated Show resolved Hide resolved
packages/math/init.lua Outdated Show resolved Hide resolved
packages/math/init.lua Outdated Show resolved Hide resolved
packages/math/init.lua Outdated Show resolved Hide resolved
packages/math/init.lua Outdated Show resolved Hide resolved
SILE.call("increment-counter", { id=counter } )
SILE.call("math-counterstyle", { id=counter } )
else
SILE.call("hbox")
Copy link
Member

@Omikhleia Omikhleia Jul 4, 2023

Choose a reason for hiding this comment

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

I suppose you did that to cancel the fact that regular glues are ignored at an end of line?
If so, i think this empty hbox trick can be avoid, if the glue is made explicit (i.e. on line 149 above, use pushExplicitGlue)

Copy link
Member

Choose a reason for hiding this comment

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

this being said, this approach does work well in ragged (left or right) environment. ❗

Copy link
Member

@Omikhleia Omikhleia Jul 17, 2023

Choose a reason for hiding this comment

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

Checking how LaTeX behaves in justified/raggedleft/raggedright/center - additionally nested in a block (quote)1

image

We should design a test scenario and check how we compare...

Footnotes

  1. problematic with our current implementation of ragged environments (not nesting, not keeping parindent, so basically behaving differently, in a questionable way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pushExplicitGlue suggestion -- I didn't knew that!

As a (really) side note, since you brought the ragged environments topic: when you suggested to use options to number equations in the display environment, I also wondered: what if we had an option to place the number on the left, or on the right side? Playing a bit, I saw that, surprisingly (to me), documents with direction=RTL already place the numbering on the left side (although the equation may be bugged -- eq. 1 is not centered, and parenthesis in equation 2 are wrong)

math-RTL

Since left numbered equations are not my use case, I opted to not add any option in this regard.

Copy link
Member

Choose a reason for hiding this comment

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

So let's craft a regression test similar to my above LaTeX tests. That test eventually should be committed in tests/math-display-numbered.sil and has it's -b debug result also committed as tests/math-display-numbered.expected

math-display-numbered.zip

Before any change:

image

After your changes as of c4db864

image

It breaks expectations with both numbered and unnumbered display math. That tells the importance of having (non-)regressing tests for features. 😸

What I would expect, at least, is:

image

Which I achieved hacking your proposal as follows:
(N.B. it could possibly be simplified, it basically re-implements or rather adapts a raggedright environment, respecting possible nesting)1

  if mode == "display" then
    SILE.typesetter:endline()
    SILE.typesetter:pushExplicitVglue(SILE.settings:get("math.displayskip"))
    SILE.settings:temporarily(function ()
      local lskip = SILE.settings:get("document.lskip") or SILE.nodefactory.glue()
      local rskip = SILE.settings:get("document.rskip") or SILE.nodefactory.glue()
      SILE.settings:set("document.lskip", SILE.nodefactory.hfillglue(lskip.width.length))
      SILE.settings:set("document.rskip", SILE.nodefactory.glue(rskip.width.length))
      SILE.settings:set("document.parindent", SILE.nodefactory.glue())
      SILE.settings:set("current.parindent", SILE.nodefactory.glue())
      SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
      SILE.settings:set("document.spaceskip", SILE.length("1spc"))

      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()
    end)
    SILE.typesetter:pushExplicitVglue(SILE.settings:get("math.displayskip"))

But the devil is in the details, and as you noted it probably doesn't work well in RTL...

Also, what happens if the equation is long and takes up most of the line so the fill and the number cannot fit? This would also call from a dedicated test.

Footnotes

  1. The current implementation of \raggedright in SILE 0.14 is subpar, and I might suggest at some point to go for the re-implementation I made in my silex.sile module. Whatever, here for the purpose of display math, it's probably safer anyway not to depend from it.

@alerque
Copy link
Member

alerque commented Jul 11, 2023

Sorry I haven't been able to jump in with PR review on this yet. I do appreciate the contribution and am pretty confident it will be worth merging. That being said there are a few unresolved comments from @Omikhleia that are worth resolving, and then there will be some commit message cleanup to happen before this is mergable. I am going to bump this one minor patch release cycle because it's holding up a patch release for stuff that's been in master for a while and I kind of need to be available in production.

@alerque
Copy link
Member

alerque commented Aug 22, 2023

Still a bunch of unhandled review comments here that look like they make sense to me. Bumping again...

@alerque alerque modified the milestones: v0.14.11, v0.x.y Aug 22, 2023
@leorosa
Copy link
Contributor Author

leorosa commented Sep 6, 2023

So, I have made a few chances in this PR.
(As I am not very used to github,) Do I need to mark the respective conversations to 'resolved'?
Moreover, there are errors in some checks ('commitlint', 'luacheck', 'test'). How can I resolve them?

@Omikhleia
Copy link
Member

Omikhleia commented Sep 8, 2023

@leorosa

So, I have made a few chances in this PR.

Unless I am not fully awake (which is possible!), I don't see the changes here. Are you sure you pushed them?

Do I need to mark the respective conversations to 'resolved'?

A good practice (that we don't always follow, perhaps) is for the person who made a remark to mark it as resolved after having reviewed the applied changes.

@alerque
Copy link
Member

alerque commented Sep 11, 2023

Live @Omikhleia I'd be happy to give this some more review, but I also don't see any new content. There was a merge commit pushed in the last 2 months but it seems to be all content I expect from a merge, not anything releated to this PR. Are you sure there are not more commits you have locally or even uncommitted stuff locally that needs to get pushed here?

Enable numbering in mathml;
Revert the definition of a '\equation' command;
Fix documentation.
Using 'pushExplicitGlue', as suggested
Renamed the numbering format to 'math:numberingstyle'
@leorosa
Copy link
Contributor Author

leorosa commented Sep 12, 2023

Another try.
(I think that I've pushed these changes to "my master" a week ago, if that makes sense.)

@alerque
Copy link
Member

alerque commented Sep 12, 2023

That's better, now there is something new to review. We'll have to fix the commit messages but don't worry about that yet, we can fix that after everything else is reviewed and ready.

@@ -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.

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.
A different counter may be set by using the option \autodoc:parameter{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 \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.





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!

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

\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)

@Omikhleia
Copy link
Member

Omikhleia commented Oct 5, 2023

Looks quite good to me now - I marked most of my previous remarks as resolved and just opened a few new ones, mostly documentation-oriented.
I just clone your branch locally and will try to perform some tests soon. --> EDIT: Done, and new remarks added.

\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.
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)

@Omikhleia Omikhleia marked this pull request as draft October 7, 2023 10:07
@Omikhleia Omikhleia added the modules:packages Issue relates to core or 3rd party packages label May 6, 2024
@Omikhleia Omikhleia mentioned this pull request May 7, 2024
@Omikhleia
Copy link
Member

Closing this PR (inactive for 7+ months) so as to move forward, see #2020 for an updated/curated version.

@Omikhleia Omikhleia closed this May 7, 2024
@alerque alerque modified the milestones: v0.x.y, v0.15.0 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Software improvement or feature request modules:packages Issue relates to core or 3rd party packages
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants