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

2d print #1155

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

2d print #1155

wants to merge 13 commits into from

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Nov 5, 2024

This is a kind of experiment. In WMA, in opposition to InputForm which produces an "inline" representation of an expression, OutputForm consists in a "2D" text-like representation of an expression. There are some examples:

In[1]:= a/b                                                                     

        a
Out[1]= -
        b

In[2]:= Sqrt[a]                                                                 

Out[2]= Sqrt[a]

In[3]:= Integrate[f[x],x]                                                       

Out[3]= Integrate[f[x], x]

In[4]:= Sqrt[a]^q                                                               

         q/2
Out[4]= a

In[5]:= MatrixForm[Table[i*j,{i,2},{j,2}]]                                      

Out[5]//MatrixForm= 1   2

                    2   4

In this way, the output in OutputForm is formatted in a similar way to the prettyprint format of Sympy.

This PR provides a way to partially reproduce this behavior when an expression is wrapped by OutputForm, and a variable $Use2DOutputForm is set to True.

The support is not complete, and probably can be improved using the code in sympy.prettyprint. Also, it currently does not work in Mathics-Django, because it is not able to print strings with line breaks.

Here are some examples in Mathics, under this branch:

In[1]:=  $Use2DOutputForm=True
Out[1]= True

In[2]:= OutputForm[a/b]
Out[2]= 
         a 
        ---
         b 

In[3]:= OutputForm[Sqrt[a]]
Out[3]= 
        __
        |a

In[4]:= Integrate[F[x],x]^2//OutputForm
Out[4]= 
                   2
         /+         
         |  F[x] dx 
        +/          

In[5]:= MatrixForm[Table[i*j,{i,2},{j,2}]]
Out[5]//MatrixForm= 1   2
                    
                    2   4

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