Skip to content

Commit

Permalink
Add latex matrix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
belerico committed Apr 19, 2020
1 parent ab9caee commit d373243
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py_asciimath/grammar/latex_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| s "_" s "^" s -> exp_under_super
s: _l start? _r -> exp_par
| "\\left" (_l | /\./ | /\\vert/) start? "\\right" (_r | /\./ | /\\vert/) -> exp_par
| "\\begin{{matrix}}" row_mat (/\\\\/ row_mat?)* "\\end{{matrix}}" -> exp_mat
| _u "{{" start "}}" -> exp_unary
| _b "{{" start "}}" "{{" start "}}" -> exp_binary
| _latex1 -> symbol
Expand All @@ -30,6 +31,7 @@
!_c: /d[A-Za-z]/
| NUMBER
| LETTER
!row_mat: start ("&" start?)* -> row_mat
!_l: {} // left parenthesis
!_r: {} // right parenthesis
!_b: {} // binary functions
Expand Down
18 changes: 18 additions & 0 deletions py_asciimath/transformer/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,21 @@ def const(self, items):
@log
def q_str(self, items):
return items

@log
def exp_mat(self, items):
s = ""
for i in items:
if i == "\\\\":
i = ","
s = s + i
return "[" + s + "]"

@log
def row_mat(self, items):
s = ""
for i in items:
if i == "&":
i = ","
s = s + i
return "[" + s + "]"

0 comments on commit d373243

Please sign in to comment.