Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Parse from latex #38

Open
danielsvane opened this issue Oct 18, 2015 · 6 comments
Open

Parse from latex #38

danielsvane opened this issue Oct 18, 2015 · 6 comments

Comments

@danielsvane
Copy link

I am really impressed with this project.

I'm in need of a way of parsing latex, to the string format used here. It's already possible to parse to latex, so I'm not sure if the other way is possible too. I looked at Jison and stuff, but I'm in way over my head here.

@timrach
Copy link
Collaborator

timrach commented Oct 20, 2015

The string parsing in algebra.js is split into 2 steps:

  • The lexical analysis of the input string, generating a token stream representing the input:
    "2 + 2" is transformed to {type:'Number', value: 2, pos:0},{type:'Operator', value: 'PLUS', pos:2},{type:'Number', value: 2, pos:4}
  • The syntactic analysis (the parser) of the token stream, generating Equations, Expressions, etc..
    {type:'Number', value: 2, pos:0},{type:'Operator', value: 'PLUS', pos:2},{type:'Number', value: 2, pos:4} is transformed to new Expression(2).add(2)

The parser is independent of the used input format, as it operates on the generated token stream.
Therefore, for the support of a new input format e.g. LaTeX, the existing lexer has to be modified or an additional lexer has to be written.

In general, I don't think LaTeX is the best input format as it's purpose is to encode how the input is displayed and not what it represents.
For example: In LaTex the multiplication of two elements can be written in various ways
x \cdot 2, x * 2, x \times 2, 2x.
Also, how would you treat annotated characters like \hat{a}, \dot{a}, \grave{a} ?

To write a lexer that accepts basic LaTeX as input is not too difficult. You could give it a try with the existing lexer as a template or I could write one if others also see a use for it ;)

TL;DR: I think LaTeX is not an appropriate input format but a lexer for it would be not too hard to write.

@danielsvane
Copy link
Author

Thanks for that elaborate reply.

I agree that latex probably isn't the best input format, but I'm getting latex formatted formulas returned from some handwriting recognition service I'm using.

If you could make an example file I could look and and expand, that would be nice.

@viktorstrate
Copy link

I made a package that can parse latex to algebra.js link.

@nicolewhite
Copy link
Owner

Woah awesome @viktorstrate !!! Will get this added to the docs.

@viktorstrate
Copy link

Cool 🎉 Thank you ^^

@Announcement
Copy link

that would be amazing and thank you @viktorstrate

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants