On Wed, Mar 16, 2016 at 3:38 PM, Aman Deep <[email protected]> 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
> 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.
>
>
> On Thursday, 17 March 2016 00:07:24 UTC+5:30, Aaron Meurer wrote:
>>
>> 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
>>
>> On Wed, Mar 16, 2016 at 1:48 PM, Aman Deep <[email protected]> wrote:
>> > 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.
>> >
>> > On Tuesday, 15 March 2016 01:58:47 UTC+5:30, Aaron Meurer wrote:
>> >>
>> >> 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
>> >>
>> >>
>> >> On Fri, Mar 11, 2016 at 7:21 AM, Aman Deep <[email protected]> wrote:
>> >> > 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.
>> >> > https://www.mathtowebonline.com/
>> >> >
>> >> > On Friday, 11 March 2016 17:20:48 UTC+5:30, Aman Deep wrote:
>> >> >>
>> >> >> 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.
>> >> >>
>> >> >> On Friday, 11 March 2016 16:01:17 UTC+5:30, Francesco Bonazzi wrote:
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> 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.
>> >> >
>> >> > --
>> >> > 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 [email protected].
>> >> > To post to this group, send email to [email protected].
>> >> > 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.
>> >> >
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > 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/c5014bc3-7f9f-4e00-82b2-0670a9e594c3%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/1a4cc716-4a6b-4e8b-a43c-6265711aecc5%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
To post to this group, send email to [email protected].
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/CADDwiVCAk7ctDsymYntPqdAfLvwq8EPBNOqNGDcEYFcU1vAQkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.