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

changed print functions to add support for python3. modified README.md #51

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
latex2sympy parses LaTeX math expressions and converts it into the
equivalent SymPy form.

## Requirements
$ pip install antlr-python3-runtime #for python3

or

$ pip install antlr-python2-runtime #for python2
## Installation

[ANTLR](http://www.antlr.org/) is used to generate the parser:
Expand All @@ -13,12 +19,12 @@ $ antlr4 PS.g4 -o gen

## Usage

In Python 2.7:
In Python 2.7 or 3.7:

```python
from process_latex import process_sympy

process_sympy("\\frac{d}{dx} x^{2}")
process_sympy(r"\frac{d}{dx} x^{2}")
# => "diff(x**(2), x)"
```

Expand All @@ -27,10 +33,10 @@ process_sympy("\\frac{d}{dx} x^{2}")
|LaTeX|Image|Generated SymPy|
|-----|-----|---------------|
|`x^{3}`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20x%5E%7B3%7D)| `x**3`|
|`\frac{d}{dx} |t|x`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%5Cfrac%7Bd%7D%7Bdx%7D%20%7Ct%7Cx)|`Derivative(x*Abs(t), x)`|
|`\frac{d}{dx} \|t\|x`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%5Cfrac%7Bd%7D%7Bdx%7D%20%7Ct%7Cx)|`Derivative(x*Abs(t), x)`|
|`\sum_{i = 1}^{n} i`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%5Csum_%7Bi%20%3D%201%7D%5E%7Bn%7D%20i)|`Sum(i, (i, 1, n))`|
|`\int_{a}^{b} \frac{dt}{t}`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%5Cint_%7Ba%7D%5E%7Bb%7D%20%5Cfrac%7Bdt%7D%7Bt%7D)|`Integral(1/t, (t, a, b))`|
|`(2x^3 - x + z)|_{x=3}`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%282x%5E3%20-%20x%20+%20z%29%7C_%7Bx%3D3%7D)|`z + 51`
|`(2x^3 - x + z)\|_{x=3}`|![](https://latex.codecogs.com/gif.latex?%5CLARGE%20%282x%5E3%20-%20x%20+%20z%29%7C_%7Bx%3D3%7D)|`z + 51`

## Contributing

Expand Down
33 changes: 17 additions & 16 deletions process_latex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sympy
import antlr4
from antlr4.error.ErrorListener import ErrorListener
Expand Down Expand Up @@ -497,22 +498,22 @@ def get_differential_var_str(text):
return text

def test_sympy():
print process_sympy("e^{(45 + 2)}")
print process_sympy("e + 5")
print process_sympy("5 + e")
print process_sympy("e")
print process_sympy("\\frac{dx}{dy} \\int y x^2 dy")
print process_sympy("\\frac{dx}{dy} 5")
print process_sympy("\\frac{d}{dx} \\int x^2 dx")
print process_sympy("\\frac{dx}{dy} \\int x^2 dx")
print process_sympy("\\frac{d}{dy} x^2 + x y = 0")
print process_sympy("\\frac{d}{dy} x^2 + x y = 2")
print process_sympy("\\frac{d x^3}{dy}")
print process_sympy("\\frac{d x^3}{dy} + x^3")
print process_sympy("\\int^{5x}_{2} x^2 dy")
print process_sympy("\\int_{5x}^{2} x^2 dx")
print process_sympy("\\int x^2 dx")
print process_sympy("2 4 5 - 2 3 1")
print(process_sympy("e^{(45 + 2)}"))
print(process_sympy("e + 5"))
print(process_sympy("5 + e"))
print(process_sympy("e"))
print(process_sympy("\\frac{dx}{dy} \\int y x^2 dy"))
print(process_sympy("\\frac{dx}{dy} 5"))
print(process_sympy("\\frac{d}{dx} \\int x^2 dx"))
print(process_sympy("\\frac{dx}{dy} \\int x^2 dx"))
print(process_sympy("\\frac{d}{dy} x^2 + x y = 0"))
print(process_sympy("\\frac{d}{dy} x^2 + x y = 2"))
print(process_sympy("\\frac{d x^3}{dy}"))
print(process_sympy("\\frac{d x^3}{dy} + x^3"))
print(process_sympy("\\int^{5x}_{2} x^2 dy"))
print(process_sympy("\\int_{5x}^{2} x^2 dx"))
print(process_sympy("\\int x^2 dx"))
print(process_sympy("2 4 5 - 2 3 1"))

if __name__ == "__main__":
test_sympy()