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

Math operators: stretchy or not stretchy #2148

Open
3 of 6 tasks
Omikhleia opened this issue Oct 22, 2024 · 1 comment
Open
3 of 6 tasks

Math operators: stretchy or not stretchy #2148

Omikhleia opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
bug Software bug issue

Comments

@Omikhleia
Copy link
Member

Omikhleia commented Oct 22, 2024

Let's take again the Schwinger-Dyson equation, from some Joe's test page which gives both a TeX formula and a MathML one...

Expectation:

image

Current SILE results (SILE 0.15.5 + most of my previous math-related PRs, notably #2146 slightly extended)

MathML:

image

TeX-like = the TeX formula with the \left and \right commands set to nothing.

image

Analysis

On the bright side, we are quite close in both cases. But the some operators are not stretched (in both cases); and (in the TeX-like case) some are stretched while they shouldn't.

  • MathML:

    • The operator that are stretched are those having an explicit "symbolDefaults" override in packages/math/unicode-symbols.lua (a small list)
      • The square brackets are there too, but stretching occurs within the context of the surrounding mrow, which is expected.
      • The vertical bar is here too but is not marked as stretchy
      • The angle brackets are missing
    • So our problem concerns the angle brackets and the vertical bar... and a large number of other symbols actually. The MathML guys were kind enough to provide a non-normative but good list of such symbols, see especially the table in §C.4....
  • TeX-like

    • The issue is very similar and part of the solution is the same...
    • ... But with a few extra considerations if we target a reasonable support of TeX math
      • In TeX many of these symbols are not stretchy by default, and this is where \left and \right come into play.
      • TeX knows at parsing (i.e. using something similar to our "symbols" table) which atoms are mathopen/mathclose etc., and can use that to wrap the content in a box... And Pandoc knows that too, actually.
        • Running with -d texmath, we see that we converted the TeX to ...\mi{F}\mo{[}\mo{ϕ}\mo{]}...
          i.e. <mi>F</mi><mo>[</mo><mo>ϕ</mo><mo>]</mo>
        • Compare with Pandoc:
          <mi>F</mi><mrow><mo stretchy="true" form="prefix">[</mo><mi>ϕ</mi><mo stretchy="true" form="postfix">]</mo></mrow> -- see, besides the correct handling of stretchy etc., the extra <mrow> there?

Conclusion

To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles (...)

I'd say it's a bug (= incompleteness of the implementation but leading to an unexpected output)

The steps would be clear:

  • Properly implement the suggested "pre-defined" table from MathML app. C.4 --> see feat(math): Support the MathML operator dictionary and many TeX-like aliases #2167
  • Also support explicit stretchy=bool on MathML elements... --> see Math more fixes and features #2151
  • Improve our TeX-like parser to be closer to what TeX/Pandoc etc. understand. Without being exhaustive or fully right (it's just a quick analysis on this point:
    • Standalone atoms are forced to stretchy=false
    • Paired of open/close atom are forced in a mrow (and are possibly stretchy=true there) --> see Math more fixes and features #2151
    • Paired \left and \right might be considered too (and this does also affect the stretchy flag, and in addition allows for some of the left or right symbols to be something other than a natural mathopen/mathclose pair.)

EDIT: Not discussed here, but since it also occurs in the above examples, there's another topic on unary/binary operators (#1642)...

EDIT: The aforementioned MathML table also has indications for spacing around operators (which we implement with an hard-coded thin/med/thick TeX-inspired logic. It's not the topic here, but spacing issue can also be noticed in the above examples (... "How many issues do you want me to open?" 🌵 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Software bug issue
Projects
Status: In progress
Development

No branches or pull requests

2 participants
@Omikhleia and others