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

LaTex Parsing for /frac #76

Merged
merged 2 commits into from
Dec 14, 2018
Merged
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
9 changes: 8 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from visma.io.checks import getVariables, areTokensEqual, isTokenInToken
from visma.io.parser import tokensToString
from visma.io.tokenize import getTerms
from visma.io.tokenize import getTerms, normalize
from visma.functions.operator import Operator, Plus
from visma.functions.structure import Expression
from tests.tester import getTokens
Expand Down Expand Up @@ -101,3 +101,10 @@ def test_getTerms():

assert getTerms("[1,0;0,1]") == ['[', '1', ',', '0', ';', '0', ',', '1', ']']
assert getTerms("2*[2,3;2,3]+[1,2;1,2]") == ['2', '*', '[', '2', ',', '3', ';', '2', ',', '3', ']', '+', '[', '1', ',', '2', ';', '1', ',', '2', ']']

assert getTerms(r"$\frac {3}{x}-\frac{x}{y}$") == ['frac', '{', '3', '}', '{', 'x', '}', '-', 'frac', '{', 'x', '}', '{', 'y', '}']


def test_normalize():

assert normalize(['frac', '{', '3', '}', '{', 'x', '}', '-', 'frac', '{', 'x', '}', '{', 'y', '}']) == ['3', '/', 'x', '-', 'x', '/', 'y']
27 changes: 26 additions & 1 deletion visma/io/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ def getTerms(eqn):
continue
terms.append(eqn[x])

elif eqn[x] == 'f':
i = x
buf = eqn[x]
while (i - x) < len("rac"):
i += 1
if i < len(eqn):
buf += eqn[i]
if buf == "frac":
terms.append(buf)
x = i + 1
continue
terms.append(eqn[x])

elif eqn[x] == 'e':
terms.append('exp')

Expand Down Expand Up @@ -331,10 +344,22 @@ def normalize(terms):
Returns:
terms {list} -- Greek input terms
"""
for term in terms:
for index, term in enumerate(terms):
for i, x in enumerate(inputLaTeX):
if x == term:
term = inputGreek[i]
if term == 'frac':
8hantanu marked this conversation as resolved.
Show resolved Hide resolved
terms.remove(terms[index])
terms.remove(terms[index])
j = index
while terms[j] is not '}':
j += 1
terms.remove(terms[j])
terms.insert(j, '/')
terms.remove(terms[j+1])
while terms[j] is not '}':
j += 1
terms.remove(terms[j])
return terms


Expand Down