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

Closed
5 tasks done
Omikhleia opened this issue Oct 22, 2024 · 2 comments
Closed
5 tasks done

Math operators: stretchy or not stretchy #2148

Omikhleia opened this issue Oct 22, 2024 · 2 comments
Assignees
Labels
bug Software bug issue
Milestone

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:

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?" 🌵 )

@Omikhleia
Copy link
Member Author

Standalone atoms are forced to stretchy=false

Well, I don't think we should do this...
Right, TeX doesn't stretch parentheses on delimiters without a \left...\right construct.
But it does seem to me, reading carefully The TeXbook, that's is merely because TeX is not trying to re-pair (pun intended) these delimiters. It would require, as we do it, checking the inner content (= equivalent to some kind on look-ahead if it was done in the parsing syntax), and it's not that obvious to do with raw TeX construct or under the memory-limited constraints Knuth faced at the time... Our Lua implementation builds a lot of intermediary lists, loops over them at several places, so heh. We don't really have those constraints.
It's a small deviation vs. what TeX would generate for the same markup, but the result was bad anyhow, with too small delimiters (hence the introduction by Knuth of the \left...\right construct, very likely...). Our way of doing it is not only acceptable, it might even be better (... and you wouldn't see me saying this kind of things very often, I hold Knuth in high regards).

@Omikhleia Omikhleia added this to the v0.15.7 milestone Nov 24, 2024
@alerque alerque modified the milestones: v0.15.7, v0.15.8 Nov 25, 2024
@Omikhleia Omikhleia modified the milestones: v0.15.8, v0.15.7 Nov 27, 2024
@Omikhleia
Copy link
Member Author

See above comment - Considered closed.

@github-project-automation github-project-automation bot moved this from In progress to Done in Math Nov 27, 2024
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: Done
Development

No branches or pull requests

3 participants
@alerque @Omikhleia and others