Skip to content

OutputForm rebase#1635

Merged
mmatera merged 28 commits into
masterfrom
rebase_1d_OutputForm
Jan 20, 2026
Merged

OutputForm rebase#1635
mmatera merged 28 commits into
masterfrom
rebase_1d_OutputForm

Conversation

@mmatera

@mmatera mmatera commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

This PR rebase #1570, including just the changes required to use the new implementation of OutputForm.

  • Remove rules of the form MakeBoxes[_, OutputForm]
  • Implement eval_makeboxes_outputform
  • use eval_makeboxes_outputform in MakeBoxes[OutputForm[_],_]
  • Modify format_element in a way that use form as the second argument of eval_makeboxes if form is a BoxForm.
  • Update format_test.yaml according to the new results, closer to WMA.

@mmatera mmatera mentioned this pull request Jan 19, 2026
Comment thread mathics/builtin/forms/print.py Outdated

def eval_mathml(self, expr, evaluation) -> Expression:
"MakeBoxes[MathMLForm[expr_], (OutputForm|StandardForm|TraditionalForm)]"
"MakeBoxes[MathMLForm[expr_], Alternatives[StandardForm,TraditionalForm]]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the difference between using | vs Alternatives[]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have seen problems confusing Alternatives with Or, but now I am not able to reproduce it. I can revert it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to change. I was just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have changed all the occurences of Alternatives in favor of using |.

Comment thread mathics/doc/documentation/1-Manual.mdoc Outdated
However, this will not be accepted as input to \Mathics anymore:
>> [1 2 3]
: Expression cannot begin with "[1 2 3]" (line 1 of "<test-Formatting Output-28>").
: Expression cannot begin with "[1 2 3]" (line 1 of "<test-Formatting Output-29>").

@rocky rocky Jan 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use the more general (and probably more robust) "..." instead of 28/29 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Docpipeline works if I replace the whole line with ..., but not just a part.

@rocky rocky Jan 20, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then let's replace the entire line. This is very fragile, and we use other mechanisms for testing output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread mathics/doc/documentation/1-Manual.mdoc Outdated
Base automatically changed from more_on_inputform to master January 19, 2026 23:49
Comment thread mathics/builtin/list/eol.py
Co-authored-by: Juan Mauricio Matera <matera@fisica.unlp.edu.ar>
Comment thread test/format/format_tests.yaml Outdated
latex:
System`InputForm: 1.09*{}^{\wedge}12 + 3.*I
System`OutputForm: 1.09\times 10^{12}\text{ + }3. I
System`OutputForm: '\text{1.09×10${}^{\wedge}$12 + 3. I}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In Wolframscript I am seeing \times used instead of × which I think is more correct. This also occurs many other places in this file.

@rocky rocky Jan 20, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Regarding the recent CI failures, I think if we use plain "*", then TeX and LaTeX will convert this to a nice character operator automatically. And I think I have seen this done in Wolframscript output for TeXForm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When I build the table, I found some problems with the TeXForm and MathMLForm output produced by WMA: sometimes it just shows errors and fails to produce an output, or the produced output does not compile well in LaTeX or render properly in the browser. The partial solution I found was to pick the current output from Mathics, and generate native WMA tests to compare and improve the cases that make sense to improve.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding this particular character, I just committed a patch to produce the right LaTeX command.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I put this in another PR. We can see to load these equivalences from the tables there.

Comment thread test/format/format_tests.yaml Outdated
latex:
System`InputForm: -1.*{}^{\wedge}-6
System`OutputForm: -1.\times 10^{-6}
System`OutputForm: '\text{-1.×10${}^{\wedge}$-6}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In WolframScript, I am seeing grave and * used:

-\text{1.$\grave{ }$*${}^{\wedge}$-6}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the output I get in WolframScript for this test case:

In[1]:= -1. 10^6 //InputForm//TeXForm                                           

Out[1]//TeXForm= \text{-1.*${}^{\wedge}$6}

In[2]:= -1. 10^6 //OutputForm//TeXForm                                          

Out[2]//TeXForm= \text{      6$\backslash $n-1. 10}

In[3]:= -1. 10^6 //StandardForm//TeXForm                                        

Out[3]//TeXForm= -1.\times 10^6

In[4]:= -1. 10^6 //TraditionalForm//TeXForm                                     

Out[4]//TeXForm= -1.\times 10^6

The main difference in OutputForm comes from the pretty-print-like output, which we currently do not support.
\grave{ } is used to mark the tick character, used in StandardForm for 'Real' numbers:

In[1]:= -1. 10^6 //StandardForm
Out[1]//StandardForm= -1.`*^6

However, as can be seen in the example, it is not used in TeXForm.

@rocky

rocky commented Jan 20, 2026

Copy link
Copy Markdown
Member

Overall, there is a big improvement. I am seeing a lot of discrepancies in format_tests.yaml between wolframscript and what we produce.

Let's discuss how to handle.

@rocky

rocky commented Jan 20, 2026

Copy link
Copy Markdown
Member

This is a bit messy, and I think it would have been better to have focused on something smaller, like getting TeXForm working better, before combining that with OutputForm work. However, I think we should commit this and iterate.

@mmatera

mmatera commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

This is a bit messy, and I think it would have been better to have focused on something smaller, like getting TeXForm working better, before combining that with OutputForm work. However, I think we should commit this and iterate.

Again, the goal is to establish a framework that works at least as well as our last version, but that allows to make formatting more compatible with WMA. This is why I tryied to avoid fixing some details in our TeXForm implementation, which in comparison with WMA is not too bad...

@mmatera

mmatera commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

Overall, there is a big improvement. I am seeing a lot of discrepancies in format_tests.yaml between wolframscript and what we produce.

Let's discuss how to handle.

I start to put more on the true output of WS in test/format/format_test-WMA.yaml. See #1639. The content format_tests.yaml should try to be similar or in some cases better than what we see in test/format/format_test-WMA.yaml.

@rocky

rocky commented Jan 20, 2026

Copy link
Copy Markdown
Member

This is a bit messy, and I think it would have been better to have focused on something smaller, like getting TeXForm working better, before combining that with OutputForm work. However, I think we should commit this and iterate.

Again, the goal is to establish a framework that works at least as well as our last version, but that allows to make formatting more compatible with WMA. This is why I tryied to avoid fixing some details in our TeXForm implementation, which in comparison with WMA is not too bad...

The situation though, is that I think some concepts like understanding precedence is missing, and instead we have precedence more hard-coded, which will probably mean there are omissions. And we have hard-coded characters in there. So I expect there will be another pass at this.

But this is a good start. LGTM.

@mmatera

mmatera commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

This is a bit messy, and I think it would have been better to have focused on something smaller, like getting TeXForm working better, before combining that with OutputForm work. However, I think we should commit this and iterate.

Again, the goal is to establish a framework that works at least as well as our last version, but that allows to make formatting more compatible with WMA. This is why I tryied to avoid fixing some details in our TeXForm implementation, which in comparison with WMA is not too bad...

The situation though, is that I think some concepts like understanding precedence is missing, and instead we have precedence more hard-coded, which will probably mean there are omissions. And we have hard-coded characters in there. So I expect there will be another pass at this.

Another pass is coming to handle these aspects.

But this is a good start. LGTM.
Thanks for the large review!

@mmatera mmatera merged commit bfd9708 into master Jan 20, 2026
21 checks passed
@mmatera mmatera deleted the rebase_1d_OutputForm branch January 20, 2026 21:20
@rocky

rocky commented Jan 20, 2026

Copy link
Copy Markdown
Member

Overall, there is a big improvement. I am seeing a lot of discrepancies in format_tests.yaml between wolframscript and what we produce.
Let's discuss how to handle.

I start to put more on the true output of WS in test/format/format_test-WMA.yaml. See #1639. The content format_tests.yaml should try to be similar or in some cases better than what we see in test/format/format_test-WMA.yaml.

Better is good.

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.

2 participants