GSoC '16: Implementation of GUI for Sympy.

1,470 views
Skip to first unread message

Aman Deep

unread,
Mar 7, 2016, 11:26:51 AM3/7/16
to sympy
Hello Developers,

I am Aman Deep, a second year student studying Information Technology at National Institute of Technology, Dugrapur, India.

I am eager to work for Sympy this GSoC.

I would like to make a gui interface for sympy for making it more user friendly. I would like to use Tkinter module for it since it is cross-platform and I already have experience with it.

Please let me know, how should I proceed.

Ondřej Čertík

unread,
Mar 7, 2016, 11:59:34 AM3/7/16
to sympy
On Mon, Mar 7, 2016 at 9:26 AM, Aman Deep <amande...@gmail.com> wrote:
> Hello Developers,
>
> I am Aman Deep, a second year student studying Information Technology at
> National Institute of Technology, Dugrapur, India.
>
> I am eager to work for Sympy this GSoC.
>
> I would like to make a gui interface for sympy for making it more user
> friendly. I would like to use Tkinter module for it since it is
> cross-platform and I already have experience with it.

What kind of GUI where you imagining? Tkinter looks ugly on linux.

The best GUI that I like is simply the Jupyter notebook with SymPy. I
think we should concentrate on that.

What would be cool is perhaps some interactive plots in the Jypyter
notebooks, integrated with sympy. The current plots are static. There
are probably some other things that would be useful to do with the
Jupyter notebooks.

Ondrej

Kasper Peeters

unread,
Mar 7, 2016, 2:22:01 PM3/7/16
to Aman Deep, sympy
Hi Aman,

> I would like to make a *gui* interface for sympy for making it more
> user friendly. I would like to use *Tkinter* module for it since it
> is cross-platform and I already have experience with it.

If you, or anyone, is seriously considering this, may I suggest to
have a peek at my Cadabra,

http://cadabra.science/

This is a GUI for a computer algebra system in development, which has
sympy as one of its dependencies, but the GUI part could easily be
split off and packaged by itself. In fact you can use it to do your
sympy stuff right now if you want to, see e.g. the notebook

http://cadabra.science/notebooks/scalar_manipulations.html

It's written in C++ using gtkmm, but even if you want a Python solution
using a different GUI toolkit you may want to see how I did various
things (like maths typesetting or the client/server separation).

I'd be happy to collaborate on this to make it better fit sympy users'
needs.

The alternative, as Ondřej already pointed out, is to focus on
enhancing Jupyter. However, that forces you to do everything inside a
browser, which is not everyone's preferred choice.

Cheers,
Kasper

Aman Deep

unread,
Mar 7, 2016, 6:00:43 PM3/7/16
to sympy
Well what you suggested requires the user to input an expression in a particular format, which i guess is not very user friendly.

Well my idea is to make the user experience more easier.

The idea is to make a kind of Interactive GUI calculator that uses sympy.

so, What i thought is that user will choose a function from the buttons given. For example:  let's say he chooses integration

so he will be presented with a standard integration sign with input boxes for entering the upper & lower limit and the function which he wants to integrate.

So basically what I want is that the user gets to enter expressions like we actually do with pen & paper.


Sorry for my bad English.

Jason Moore

unread,
Mar 7, 2016, 6:14:41 PM3/7/16
to sy...@googlegroups.com
Your idea sounds similar to what MathCAD does. I've used it years ago and it was nice and many people like that concept. I moved away from it for the same reason I moved away from the equation editor in Word, it takes too long to fill in the templates for the expressions. There may be SymPy users that would like this functionality. I would recommend using a different toolkit than TKinter though. For native apps, maybe Qt is a good option, but if you made it a web app it could run on any platform, even phones, etc.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/29548d80-42a0-4446-a594-861ecf37503a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Aman Deep

unread,
Mar 8, 2016, 9:24:49 AM3/8/16
to sympy
Thank you everyone for your suggestions..

I just checked out mathCAD.. I would like to implement something like that which uses sympy. I don't have much experience with C++. So, how about using PyQt instead of Qt?

How should I begin working on this idea?

Francesco Bonazzi

unread,
Mar 8, 2016, 10:38:01 AM3/8/16
to sympy
I would suggest to work on Jupyter/IPython notebook integration instead of an independent GUI from scratch.

Some reasons:
  • There are far many more HTML/Javascript programmers than specific widget engines (Qt, GTK, Tkinter, and so on).
  • Jupyter notebooks are becoming a de facto standard, they are used by lots of different projects across multiple programming languages.
  • An independent project started by few people may end up dead if there's no following, Jupyter is already quite influential and has a lot of funding.

It may be hard to integrate the tools you have devised into Jupyter.


For SymPy, there is a javascript library that transforms SymPy's LaTeX printer into well-formatted HTML. It would be great if someone could add javascript actions to the generated HTML to perform manual editing.


I am not familiar with their code, but I strongly suggest to go the Jupyter way.

Ondřej Čertík

unread,
Mar 8, 2016, 11:43:01 AM3/8/16
to sympy
On Tue, Mar 8, 2016 at 8:38 AM, Francesco Bonazzi
<franz....@gmail.com> wrote:
> I would suggest to work on Jupyter/IPython notebook integration instead of
> an independent GUI from scratch.
>
> Some reasons:
>
> There are far many more HTML/Javascript programmers than specific widget
> engines (Qt, GTK, Tkinter, and so on).
> Jupyter notebooks are becoming a de facto standard, they are used by lots of
> different projects across multiple programming languages.
> An independent project started by few people may end up dead if there's no
> following, Jupyter is already quite influential and has a lot of funding.
>
> It may be hard to integrate the tools you have devised into Jupyter.
>
>
> For SymPy, there is a javascript library that transforms SymPy's LaTeX
> printer into well-formatted HTML. It would be great if someone could add
> javascript actions to the generated HTML to perform manual editing.
>
>
> I am not familiar with their code, but I strongly suggest to go the Jupyter
> way.

Exactly. I also strongly suggest going the Jupyter way.

Ondrej

Jason Moore

unread,
Mar 8, 2016, 12:30:09 PM3/8/16
to sy...@googlegroups.com
My two cents: You should find a cross platform gui toolkit (could be a web app like jupyter or something native like Qt) and choose one that already has nice libraries for the features you need. For example, it'd be preferable to use and existing gui style equation editor (LibreOffice Math Equations has one, for example) so that you don't have to reinvent the wheel. Then you can focus on having that interface communicate properly with SymPy. You will have to write some kind of parser that converts the backend form of the gui equations to sympy. That will likely be a lot of work in itself (unless you can find an existing tool that already does this). My opinion is that you will get wider adoption if you make a web app, because then people don't have to figure out how to install it.
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Aman Deep

unread,
Mar 9, 2016, 5:15:58 AM3/9/16
to sympy
Hello Developers,

As you all suggested, I have started working on Jupyter as the Gui with sympy.

As Ondrej suggested to make some interactive plots using sympy in Jupyter notebook since the current plots are static.

So After going through some online resources , I was able to make some interactive plots using mathplotlib and sympy plotting module.

Here is the link to the Jupyter notebook file that I made https://drive.google.com/file/d/0B_yUvrIaXV4lR2IwWVhIUHpFOEk/view?usp=sharing
I have also included comments in the notebook using markdown before each code block.

Please let me know if its fine.

On Monday, 7 March 2016 21:56:51 UTC+5:30, Aman Deep wrote:

Ondřej Čertík

unread,
Mar 9, 2016, 10:47:10 AM3/9/16
to sympy
On Wed, Mar 9, 2016 at 3:15 AM, Aman Deep <amande...@gmail.com> wrote:
> Hello Developers,
>
> As you all suggested, I have started working on Jupyter as the Gui with
> sympy.
>
> As Ondrej suggested to make some interactive plots using sympy in Jupyter
> notebook since the current plots are static.
>
> So After going through some online resources , I was able to make some
> interactive plots using mathplotlib and sympy plotting module.
>
> Here is the link to the Jupyter notebook file that I made
> https://drive.google.com/file/d/0B_yUvrIaXV4lR2IwWVhIUHpFOEk/view?usp=sharing
> I have also included comments in the notebook using markdown before each
> code block.

Use nbivewer.jupyter.org to show notebooks, so that people can see
them. Like this:

http://nbviewer.jupyter.org/gist/certik/93bd15ac659b693985ce

I ran the notebook. No window appears for me. I assume that I don't
have some kind of a backend installed. My idea is to make this work
inside the browser itself, so that it works for everybody (and myself
too). So this would mean:

* investigating what javascript libraries are available
* how to integrate with jupyter
* writing code for sympy and/or perhaps some kind of a jupyter
extension to make this all work (perhaps both)

I searched around a bit, and it turns out there is already:

%matplotlib notebook

and it provides an interactive matplotlib plot! Both 2D and 3D works!
That's actually amazing, I didn't know they implemented this.

It's a bit flaky, e.g. it only works the first time, if I reexecute
the cell, it disappears and never shows again until I restart the
notebook. So this would need to be fixed. So a good project would be
to improve this matplotlib / jupyter interaction. It's not even really
related to sympy, but I'll be happy to get somebody from matplotlib to
help us mentor this. I think this would be very useful. There could be
sympy bits to improve too. E.g. perhaps sympy documentation and more
examples how to do 2D and 3D plots, perhaps adding some more
functionality.

So a project like this would be very useful to lots of people.

Ondrej

>
> Please let me know if its fine.
>
> On Monday, 7 March 2016 21:56:51 UTC+5:30, Aman Deep wrote:
>>
>> Hello Developers,
>>
>> I am Aman Deep, a second year student studying Information Technology at
>> National Institute of Technology, Dugrapur, India.
>>
>> I am eager to work for Sympy this GSoC.
>>
>> I would like to make a gui interface for sympy for making it more user
>> friendly. I would like to use Tkinter module for it since it is
>> cross-platform and I already have experience with it.
>>
>> Please let me know, how should I proceed.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/d112c69c-a56f-4e2e-993d-adb1026fb6cd%40googlegroups.com.

Sartaj Singh

unread,
Mar 9, 2016, 11:06:58 AM3/9/16
to sy...@googlegroups.com
> I ran the notebook. No window appears for me
.
I also ran the notebook, the plot window appears for me though. The plots are interactive :).

> My idea is to make this work inside the browser itself, so that it works for everybody (and myself too).
 
I agree with ondrej that it is better to be inside the browser itself.

> I searched around a bit, and it turns out there is already:
>
> %matplotlib notebook

I also tried this with:

%matplotlib inline

The plots appear fine, although they are not interactive. However, they do appear when I re-executive the cell. Maybe we need the best of both. :)

> So a good project would be
> to improve this matplotlib / jupyter interaction. It's not even really
> related to sympy, but I'll be happy to get somebody from matplotlib to
> help us mentor this. I think this would be very useful. There could be
> sympy bits to improve too. E.g. perhaps sympy documentation and more
> examples how to do 2D and 3D plots, perhaps adding some more
> functionality.

I agree. I will also try to investigate what possible features can be added. 



For more options, visit https://groups.google.com/d/optout.



--
Regards
Sartaj Singh

Mathematics and Computing,
Indian Institute of Technology,
Varanasi - 221 005 INDIA

Jason Moore

unread,
Mar 9, 2016, 11:10:20 AM3/9/16
to sy...@googlegroups.com
Note that you can simply type "%matplotlib notebook" if you want interactive plots from matplotlib in the notebook.

Bokeh and mpld3 also give this functionality.

Ondřej Čertík

unread,
Mar 9, 2016, 2:11:27 PM3/9/16
to sympy
On Wed, Mar 9, 2016 at 9:06 AM, Sartaj Singh <singhs...@gmail.com> wrote:
>> I ran the notebook. No window appears for me
> .
> I also ran the notebook, the plot window appears for me though. The plots
> are interactive :).
>
>> My idea is to make this work inside the browser itself, so that it works
>> for everybody (and myself too).
>
> I agree with ondrej that it is better to be inside the browser itself.
>
>> I searched around a bit, and it turns out there is already:
>>
>> %matplotlib notebook
>
> I also tried this with:
>
> %matplotlib inline
>
> The plots appear fine, although they are not interactive. However, they do
> appear when I re-executive the cell. Maybe we need the best of both. :)


Yes, I've been using "%matplotlib inline" (or "%pylab inline" in fact,
though I should switch to the former) for many years and that works
robustly. But it's not interactive.

Ondrej
> https://groups.google.com/d/msgid/sympy/CAC%2BH8-HOvYTVGaa9AbQueA5quT0Noe75JGXaMfF9VLYtkuS-kQ%40mail.gmail.com.

Aman Deep

unread,
Mar 9, 2016, 2:57:06 PM3/9/16
to sympy
Hi Jason,

I tried "%matplotlib notebook" and it gives me interactive plots within the notebook!!
I have been trying to do it.

Thankyou very much!
Message has been deleted

Aman Deep

unread,
Mar 9, 2016, 5:00:00 PM3/9/16
to sympy
Hi Ondrej,

As Jason Suggested to include "%matplotlib notebook" 
Now Interactive plots are shown in the browser itself.

Link : http://nbviewer.jupyter.org/gist/hiamandeep/4501ce5ae2a21caffd7c

Note: In nbviewer the plots are shown static. so the ipynb file must be downloaded and run in jupyter to see the interactive plots.

Aman Deep

unread,
Mar 9, 2016, 5:09:16 PM3/9/16
to sympy
Sorry, that I didn't mention you for suggesting the "%matplotlib notebook" idea.

When I reexecute that cell. there doesn't seem to be any probem. The plots do reappear.


On Wednesday, 9 March 2016 21:17:10 UTC+5:30, Ondřej Čertík wrote:

Francesco Bonazzi

unread,
Mar 9, 2016, 5:10:31 PM3/9/16
to sympy
Jupyter notebooks use MathJax to display LaTeX formulae. MathJax is a Javascript library that renders LaTeX code into HTML.

I would be nice to have the MathJax HTML generation in order to add HTML events to the displayed formula.

If you succeed to do it, you could also create an IPython widget for formula editing.

Jason Moore

unread,
Mar 9, 2016, 6:20:14 PM3/9/16
to sy...@googlegroups.com
I think that creating a formula input widget for Jupyter would be a solid project to work on for GSoC. That would open up a lot of possibilities.

Ondřej Čertík

unread,
Mar 9, 2016, 7:23:52 PM3/9/16
to sympy
On Wed, Mar 9, 2016 at 4:19 PM, Jason Moore <moore...@gmail.com> wrote:
> I think that creating a formula input widget for Jupyter would be a solid
> project to work on for GSoC. That would open up a lot of possibilities.

Indeed. In general, any improvements like these I would be very happy
to support as part of GSoC. Essentially anything, that makes sympy
easier to use, as part of the wider scientific Python ecosystem. I
think there are more things that could be done in this manner, we just
need to brainstorm a bit.

Ondrej
> https://groups.google.com/d/msgid/sympy/CAP7f1AhkXce0V7%3DT9v5TCMcW2HYTi7MncbVe%2BhbPDTNtB9Jocw%40mail.gmail.com.

Francesco Bonazzi

unread,
Mar 10, 2016, 4:12:01 AM3/10/16
to sympy


On Thursday, 10 March 2016 00:20:14 UTC+1, Jason Moore wrote:
I think that creating a formula input widget for Jupyter would be a solid project to work on for GSoC. That would open up a lot of possibilities.
 

I'd suggest to get in touch with the MathJax community and ask them whether it's feasible to hack MathJax in order to make it work like an editor.

Maybe there's already someone who has adapted MathJax to work as an editor.

The integration in an IPython/Jupyter widget is much easier than creating the editor itself.

Francesco Bonazzi

unread,
Mar 10, 2016, 4:25:05 AM3/10/16
to sympy
I had some googling around. This one looks interesting:

http://mathquill.com/

Their source code is on github:

https://github.com/mathquill/mathquill

They use the Mozilla Public License.

What could be done:
  • integrate it in an IPython widget.
  • figure out a way to convert the Javascript data-structure expression to a SymPy expression.

Ashutosh Saboo

unread,
Mar 10, 2016, 10:02:45 AM3/10/16
to sympy
Hi.

I have been looking to work on this since some time now. I did some googling to find the best possible alternatives. 

For entering math equations input like the Wolfram Alpha equation input, I managed to find these free, open source alternatives-:

1. Stack Edit - https://stackedit.io/ - which is one good choice. 

2. CK Editor - which provides an editor to add math equations - http://ckeditor.com/addon/mathedit

3. MathJax - https://www.mathjax.org/ - 

4. Mathquill - http://mathquill.com/ - as Francesco suggested above!

5. TexMacs - http://texmacs.org/tmweb/home/welcome.en.html

6. https://github.com/mathjax/MathJax-docs/wiki/List-of-web-based-math-editors - This link also gives some math based editors. 

We can use either of these for the equation input.

Also, just as an alternative how about if we use Kivy - https://kivy.org/#home - to make the GUI. Many high level apps have been built using Kivy, so it would be relatively easier, as well as efficient, and moreover we could add more features to the GUI, if we use this. Although, I am not sure about, whether it has funds and all (that were discussed above in this thread). 

Ondrej, Your views on this?

Aman Deep

unread,
Mar 10, 2016, 2:05:35 PM3/10/16
to sympy
Hi, Developers,

Thanks Francesco, for introducing me to 'mathquill' :)
I found it very useful. I have been looking for something like this. I really liked the user friendly formatted input that it takes.

Here is something I have thought about the widget.

1. user will input the expression using mathquill
2. and mathquill will generate the corresponding latex expression.
3. latex expression should be then converted to sympy expression.

Here is something I found for conversion of a latex expression to sympy expression.

https://github.com/augustt198/latex2sympy

referring to its readme, it should be installed with antlr4
But I installed it using antlr3 since I couldn't install antlr4 due to some reason

But when I tried
>>> from process_latex import process_sympy

I got this import error.
ImportError: No module named PSParser

So, maybe I am doing something wrong or maybe the the package has a bug.

Can someone look into it?

So, I have started working on mathquill to work with sympy on Jupyter and I will post as soon as I get some working prototype.

Thanks.

Thanks.

Jason Moore

unread,
Mar 10, 2016, 2:11:27 PM3/10/16
to sy...@googlegroups.com
If the software requires ANTLR4, then installing ANTLR3 is likely the issue. You need to figure out how to install ANTLR4. Maybe ask on their mailing list.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Francesco Bonazzi

unread,
Mar 10, 2016, 3:38:18 PM3/10/16
to sympy


On Thursday, 10 March 2016 20:05:35 UTC+1, Aman Deep wrote:
Here is something I have thought about the widget.

1. user will input the expression using mathquill
2. and mathquill will generate the corresponding latex expression.
3. latex expression should be then converted to sympy expression.


I'd skip the latex step.

Apparently there's an open issue on mathquill:
https://github.com/mathquill/mathquill/issues/456

Aman Deep

unread,
Mar 10, 2016, 4:58:09 PM3/10/16
to sympy
I was able to use mathquill inside jupyter notebook using html & javascript.

Here is the code.
http://nbviewer.jupyter.org/gist/hiamandeep/52ccdce87c40fb021048 

So, If I skip the latex part then what should be my approach to convert text in input area to sympy expression?

Thanks.

Francesco Bonazzi

unread,
Mar 11, 2016, 5:31:17 AM3/11/16
to sympy


On Thursday, 10 March 2016 22:58:09 UTC+1, Aman Deep wrote:
I was able to use mathquill inside jupyter notebook using html & javascript.

Here is the code.
http://nbviewer.jupyter.org/gist/hiamandeep/52ccdce87c40fb021048 


Excellent.
 
So, If I skip the latex part then what should be my approach to convert text in input area to sympy expression?
 
Have a look at this conversation:
https://github.com/mathquill/mathquill/issues/456

Otherwise, you could try to parse the javascript expression tree of mathquill.

Try to contact the mathquill developers, maybe they can better advise us.

Aman Deep

unread,
Mar 11, 2016, 6:50:48 AM3/11/16
to sympy
I have asked them about it on their irc channel irc://irc.freenode.net/mathquill 
Waiting for their reply.. Meanwhile I am trying to make latex work with sympy.

Thanks.

Aman Deep

unread,
Mar 11, 2016, 7:21:10 AM3/11/16
to sympy
If I am able to convert the latex expression to MathML.
Will it be easier to parse MathML to sympy expression?

Here Is something I found which converts latex to MathML.

Francesco Bonazzi

unread,
Mar 11, 2016, 3:40:59 PM3/11/16
to sympy


On Friday, 11 March 2016 13:21:10 UTC+1, Aman Deep wrote:
If I am able to convert the latex expression to MathML.
Will it be easier to parse MathML to sympy expression?


Mathquill appears to have other export formats and exporting SymPy compatible strings is marked as an issue on their tracker.

Anyway, I would try to see which Javascript data structure they use to store the expression tree.

If you can access the expression tree from Python, you won't need any parser at all, just a depth-first search visit to the expression tree.

I'm not familiar with IPython widgets, but there has to be a way to access the widget's DOM or Javascript variables.

Aman Deep

unread,
Mar 12, 2016, 9:02:15 PM3/12/16
to sympy
Hi Developers,

After doing a lot of online research, I was finally able to make a widget of MathQuill input expression box for Jupyter notebook!!

Ipython widgets use backbone.js (MVC framework). back-end widget code is written in python and front-end widget is written in js.

I simply passed the sting containing the MathQuill  Html & js code from backend to frontend, where it was rendered using jquery html function. 
while running the MyWidget python class there are some Deprecation Warning, have to figure out how to fix them.

In the process I learned some new stuffs, like some backbone.js basics and brushed up my MVC (model view controller ) concepts.

But, the conversion from Mathquill to a sympy expression is yet left to do.
I am still figuring a way to make it work. 

Here is the link to the notebook code.

Francesco Bonazzi

unread,
Mar 14, 2016, 4:06:46 AM3/14/16
to sympy
Maybe you could ask for help on the IPython/Jupyter conversation.

Aaron Meurer

unread,
Mar 14, 2016, 4:28:47 PM3/14/16
to sy...@googlegroups.com
There are two types of MathML, Presentation MathML and Content MathML.
Presentation MathML is a markup for formatting expressions, similar to
LaTeX. Content MathML has some knowledge of the mathematical
expressions they represent. Content MathML is easier to parse to SymPy
because it represents an expression tree. Most LaTeX -> MathML
converters convert to Presentation MathML, since LaTeX is itself a
presentation language.

To convert to SymPy, you really need any kind of expression tree, or
AST. Converting from that to SymPy would just be a matter of walking
the syntax tree and converting it to Python. Content MathML is a good
choice for this, but so would many other formats (like a Lisp
expression, or some internal format in the Javascript). Presentation
MathML and LaTeX are poorer choices, because they don't represent
mathematical expressions, they represent 2D rendering of symbols. So
for example, if you have x + y, you want something that represents
that as an Add node with "x" and "y" subnodes. LaTeX represents this
as the string "x + y". But you can also have nonsense LaTeX
expressions, like "x + / ^ -" or "\frac{+}{3}". These are valid LaTeX
because they represent a valid 2D rendering, but they aren't valid
math because there are operators (nodes) that don't have proper syntax
(e.g., the + "operator" should have a left and right child,
mathematically it doesn't make sense by itself in a fraction).

LaTeX is also bad because it's very easy to be ambiguous with it (like
"\sin xy", which could mean sin(x*y) or sin(x)*y). While you could
probably be careful and only generate unambiguous LaTeX, you still
have to reparse that into its own expression tree anyway, in order to
do the conversion to SymPy. With that being said, it is useful for an
equation editor to be able to export to LaTeX, so you can get the
exact representation of what you inputted.

Note that unless you design the equation input system so that it's
impossible to enter invalid expressions (e.g., when you enter ∫ it
immediately requires you to enter an expression and a variable), you
will have to have some way to translate from "presentation" to
"content".

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/6b30bb95-b052-4eeb-9a4e-63cac27f77bd%40googlegroups.com.

Aman Deep

unread,
Mar 16, 2016, 1:48:57 PM3/16/16
to sympy
Thanks for replying Aaron!, That is very useful information!

How about using SnuggleTex for converting Latex to Content MathML?

SnuggleTex is a java library for converting Latex to Content MathML. It is issued under 3-clause BSD license.

Thanks.

Aaron Meurer

unread,
Mar 16, 2016, 2:37:24 PM3/16/16
to sy...@googlegroups.com
It looks like it could be useful. You'd have to play around with it
with larger expressions to see how well it works. Ideally the library
would be in Python, but if SnuggleTex works well it might be worth
using.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/c5014bc3-7f9f-4e00-82b2-0670a9e594c3%40googlegroups.com.

Aman Deep

unread,
Mar 16, 2016, 5:38:42 PM3/16/16
to sympy
I am able to convert latex expression to sympy expression using latex2sympy (https://github.com/augustt198/latex2sympy)
It uses antlr4 to generate the parser.

I got this latex for entered quadractic root equation in MathQuill.

\frac{-b\pm\sqrt{b^2-4ac}}{2a}
I modified it a little to make it work with latex2sympy (given below)

>>> process_sympy("\\frac{-b+\sqrt{b^{2}-4ac}}{2a}")
ANTLR runtime and generated code versions disagree: 4.5.2.1!=4.4
ANTLR runtime and generated code versions disagree: 4.5.2.1!=4.4
u'((-b + sqrt(b**(2) - 4*a*c)) / (2*a))'
>>> 

like Aaron said that latex may be different formats and may be mathematically incorrect.

I guess, the expressions generated by MathQuill are mathematically correct but there are some issues with latex2sympy like:

before frac mathquill puts only one backslash (\), but latex2sympy requires double (\\). if there are brackets in the expression then MathQuill puts 'left' and 'right' to make the brackets of the same size of the expression. and there are some symbols eg: \pm (plus minus) aren't recognized by latex2sympy.

example latex produced by mathquill: \frac{1}{\left(a+b\right)}

if I simply remove '\left' and '\right' and put one more '\' before frac , It works fines in latex2sympy and give me an equivalent sympy expression.

Can We make some changes in latex2sympy to make it work with mathquill?
please give suggestions.

Thanks.

Ondřej Čertík

unread,
Mar 16, 2016, 6:16:08 PM3/16/16
to sympy
On Wed, Mar 16, 2016 at 3:38 PM, Aman Deep <amande...@gmail.com> wrote:
> I am able to convert latex expression to sympy expression using latex2sympy
> (https://github.com/augustt198/latex2sympy)
> It uses antlr4 to generate the parser.
>
> I got this latex for entered quadractic root equation in MathQuill.
>
> \frac{-b\pm\sqrt{b^2-4ac}}{2a}
> I modified it a little to make it work with latex2sympy (given below)
>
>>>> process_sympy("\\frac{-b+\sqrt{b^{2}-4ac}}{2a}")
> ANTLR runtime and generated code versions disagree: 4.5.2.1!=4.4
> ANTLR runtime and generated code versions disagree: 4.5.2.1!=4.4
> u'((-b + sqrt(b**(2) - 4*a*c)) / (2*a))'
>>>>
>
> like Aaron said that latex may be different formats and may be
> mathematically incorrect.
>
> I guess, the expressions generated by MathQuill are mathematically correct
> but there are some issues with latex2sympy like:
>
> before frac mathquill puts only one backslash (\), but latex2sympy requires
> double (\\).

Isn't this just how Python parses \ in a string?

In [7]: print r"\frac"
\frac

In [8]: print "\frac"

rac

In [9]: print "\\frac"
\frac


Just put 'r' in front of the string and you can use a single \.

Ondrej
> https://groups.google.com/d/msgid/sympy/1a4cc716-4a6b-4e8b-a43c-6265711aecc5%40googlegroups.com.

Aman Deep

unread,
Mar 17, 2016, 7:01:56 AM3/17/16
to sympy
So, the extra backslash is used for escaping the special character.
Didn't think of that! :)

Thanks for the help, Ondrej!

Francesco Bonazzi

unread,
Mar 17, 2016, 12:45:22 PM3/17/16
to sympy
If you are still concentrating on importing MathQuill expressions, I would recommend not to make things too complicated.

Web browsers like Chrome and Firefox support Javascript debugging. I would recommend to follow MathQuill's .latex() method with the debugger and see how the tree traversal occurs.

It would be good to get some simple data structures back, like the expression tree in JSON.

JSON declares arrays and dictionaries in a similar way to Python. If you got the expression tree in JSON, you could convert it to Python with eval( ).

Aman Deep

unread,
Mar 21, 2016, 6:31:02 PM3/21/16
to sympy
Should I submit the Wiki link of my proposal or a Google doc in draft proposal in Gsoc website?

Jason Moore

unread,
Mar 21, 2016, 6:44:28 PM3/21/16
to sy...@googlegroups.com
You need to submit the document (not a link) as requested in the GSoC website.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Aman Deep

unread,
Mar 21, 2016, 7:04:50 PM3/21/16
to sympy
Hi Jason,

But, for draft submission google asked for a link of google docs or any other link.  There is only a link field shown and not file upload option.

quoted from withgoogle.com
 

Start a draft proposal.

Students who receive feedback on their proposals early end up with better proposals and are more likely to get accepted. Make sure you read SymPy's "How to work with us" for proposal prerequisites and requirements.

In step 2 you will give it a title and write an abstract.

Your proposal will not be shared with SymPy until you click "READY FOR REVIEW" in step 3.


It says, for final submission a pdf file is to be submitted.

Upload a final PDF which SymPy will see after the deadline.
close

So, I am asking about Draft submission not Final submission.

Aaron Meurer

unread,
Mar 21, 2016, 9:03:15 PM3/21/16
to sy...@googlegroups.com
Either one is fine. If you use Google docs we can comment on it easier.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/ad410c7f-0a96-430d-b3a4-13b0926377b5%40googlegroups.com.

Aman Deep

unread,
Mar 22, 2016, 12:04:55 AM3/22/16
to sympy
           Here is the link: https://docs.google.com/document/d/131CWPgtupa5hG4GvJJF1ruKHz9QPgwhd72wkRPkY4Cw/edit?usp=sharing

            Please Suggest Improvements.

  • At the beginning of the idea discussion, I made an interactive plot using matplotlib in jupyter. So I thought It would be useful to add it to examples in the repo. I have not got any response on this for quite long.
           Please review this Pull Request: #PR 10869

Thanks.

Aman Deep

unread,
Mar 22, 2016, 9:01:55 PM3/22/16
to sympy
Someone Please Suggest Improvements in my proposal!

Francesco Bonazzi

unread,
Mar 23, 2016, 7:04:20 AM3/23/16
to sympy


On Wednesday, 23 March 2016 02:01:55 UTC+1, Aman Deep wrote:
Someone Please Suggest Improvements in my proposal!

Here is the link: https://docs.google.com/document/d/131CWPgtupa5hG4GvJJF1ruKHz9QPgwhd72 wkRPkY4Cw/edit?usp=sharing


The other way round is also interesting: convert a SymPy expression to a MathQuill widget.

Sometimes people have large expressions and you'd wish you could turn into an edit mode to manually edit them.

Aman Deep

unread,
Mar 23, 2016, 7:16:47 AM3/23/16
to sympy
Hi Francesco,

That seems really interesting. I 'll look into it :)

I have made a mathquill prototype widget and using some buttons to make things simpler.

here is the html/js code : https://gist.githubusercontent.com/hiamandeep/77a1877d406a8f76a0ed/raw/34eddabdb9c0c413459c8c742e92a9fcc113ed8a/widget_prototype_amandeep.html

and this is the code in the notebook in a widget form: http://nbviewer.jupyter.org/gist/hiamandeep/bdbf23e83a554d643371

Please, Have a look at it.

Aman Deep

unread,
Mar 23, 2016, 7:37:21 AM3/23/16
to sympy

Aman Deep

unread,
Mar 23, 2016, 8:53:14 AM3/23/16
to sympy
Hi Francesco,

This is my draft proposal wiki : https://github.com/sympy/sympy/wiki/GSoC-2016-Application-Aman-Deep:-Implementing-a-Formula-input-widget-for-Sympy-in-Jupyter-Ipython-Notebook

and also on google docs: https://docs.google.com/document/d/131CWPgtupa5hG4GvJJF1ruKHz9QPgwhd72wkRPkY4Cw/edit?usp=sharing

I would really appreciate, if you could suggest improvements in it. As there are only 2 days left for final submission.
So, I need to make changes fast.

Thank you.


On Wednesday, 23 March 2016 16:34:20 UTC+5:30, Francesco Bonazzi wrote:

Aman Deep

unread,
Mar 24, 2016, 1:46:26 AM3/24/16
to sympy

Hi Everyone,


I was finally able to integrate mathquill with latex2sympy in the Jupyter notebook.


Here is a screenshot showing a Mathematical equation entered in mathquill and its latex is grabbed by pressing the set value and passed to process_sympy function to show the equivalent sympy expression.


Here is the code: http://nbviewer.jupyter.org/gist/hiamandeep/9ac3c1d44b63259a9ebf


Please give suggestions.


Christophe Bal

unread,
Mar 24, 2016, 3:39:24 AM3/24/16
to sympy-list

Hello

As a teacher in a high school, I think that a non modal window would be really useful.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Aman Deep

unread,
Mar 24, 2016, 9:13:44 PM3/24/16
to sympy
Hi Christophe,
Thanks for your suggestion. I will look into it.

Aman Deep

unread,
Mar 24, 2016, 10:36:31 PM3/24/16
to sympy
Hi Developers,

Here is my draft proposal: https://docs.google.com/document/d/131CWPgtupa5hG4GvJJF1ruKHz9QPgwhd72wkRPkY4Cw/edit?usp=sharing

I have made a working prototype and given its code link in nbviewer in my proposal : http://nbviewer.jupyter.org/gist/hiamandeep/9edc1f889336b4b1b979

My doubt is :

Just running the notebook code won't work fully, since latex2sympy package is needed for the conversion to sympy.

How should I describe that in my proposal.

I mean, should I explain to first download the latex2sympy package from git and then place it in the directory where the notebook is to be run using the command $jupyter notebook

and also since latex2sympy depends on antlr4,
Do I need to explain how to install antlr4 and generate the parser.

what I basically mean is that the person reading my proposal would definitely want to run and check my prototype.
and simply running the notebook code won't work fully, It will only show the UI of the widget and do latex conversion but won't do the conversion to sympy expression, since the conversion part is dependent on latex2sympy package which is then dependent on antlr4.

For this reason, I have also put a screenshot of my running prototype to explain the conversion. but I guess the reviewer won't consider the screenshot reliable.

So, how do I describe about running the prototype in my proposal?
 
Please go though my proposal and suggest me.

Aman Deep

unread,
Feb 27, 2017, 1:14:58 PM2/27/17
to sympy
Hi,

I would like to take up this idea again, for GSoc '17. I had worked a lot on it for GSoc '16 but unfortunately there were not enough slots for it to get accepted as a project.

what do you guys say?

thanks
Reply all
Reply to author
Forward
0 new messages