Skip to content

Conversation

@d-torrance
Copy link
Member

@d-torrance d-torrance commented Jan 7, 2026

Currently, we have:

i1 : mathML Matrix
stdio:1:6:(3): error: recursion limit of 300 exceeded

What's going on?

i2 : code (mathML, Type)

o2 = -- code for method: mathML(Type)
     /usr/share/Macaulay2/Core/mathml.m2:167:24-167:80: --source code:
     mathML ImmutableType := R -> if R.?mathML then R.mathML else mathML expression R

i3 : peek expression Matrix

o3 = Holder{Matrix}

i4 : code (mathML, Holder)

o4 = -- code for method: mathML(Holder)
     /usr/share/Macaulay2/Core/mathml.m2:40:17-40:32: --source code:
     mathML Holder := v -> mathML v#0

Since there's no Matrix.mathML, we just bounce back and forth between mathML(Type) and mathML(Holder).

We fix this by just removing mathML(Type) and using inheritance so it calls mathML(MutableHashTable) (and also setting this to be mathML(ImmutableType)), which does the expected thing:

i1 : mathML Matrix

o1 = <mi>Matrix</mi>

@d-torrance d-torrance requested a review from antonleykin January 7, 2026 03:32
@d-torrance
Copy link
Member Author

This (kind of) broke mathML for polynomial rings. This is the current behavior:

i1 : mathML(QQ[a,c,e])

o1 = <mi>ℚ</mi> <mrow><mo>[</mo><mrow><mi>a</mi><mo>,</mo><mi>c</mi><mo>,</mo><
     mi>e</mi></mrow><mo>]</mo></mrow>

Which renders as:

ℚ [a,c,e]

(Yay GitHub can render mathml in comments!)

But notice that I used variable names that aren't adjacent alphabetically. When we do that:

i2 : mathML(QQ[a,b,c])
stdio:2:6:(3): error: mathML conversion for expression class BinaryOperation not implemented yet

That's because expression inserts a .. operator between a and c, and mathML chokes on that.

With just the first commit from this PR, we get the following silly thing:

i1 : mathML(QQ[a,b,c])

o1 = <mrow><mi>PolynomialRing</mi><mtext>{...55...}</mtext></mrow>

So we add mathML(EngineRing) and mathML(BinaryOperation), giving us the expected result:

i1 : mathML(QQ[a,b,c])

o1 = <mi>ℚ</mi> <mrow><mo>[</mo><mrow><mrow><mi>a</mi><mo>..</mo><mi>c</mi></
     mrow></mrow><mo>]</mo></mrow>

This renders as:

ℚ [a..c]

Just use inheritance since mathML(MutableHashTable) will do what we
want in most cases.

Also drop mathML(ImmutableType).  The only immutables types is Module,
and it already has its own mathML method.  None of the other text
formatting methods are installed for ImmutableType.
Plus mathML(BinaryOperation), which we need since we often have the
.. operator between variables.
@d-torrance
Copy link
Member Author

I ended up just dropping mathML(ImmutableType) completely. It was redundant since Module is the only child of ImmutableType and mathML(Module) is defined elsewhere. None of the other text formatting methods are installed for ImmutableType either.

@d-torrance
Copy link
Member Author

Discussed with Mike

@d-torrance d-torrance merged commit d1cc613 into Macaulay2:development Jan 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant