Skip to content

Commit

Permalink
Par can be unbalanced
Browse files Browse the repository at this point in the history
  • Loading branch information
belerico committed Apr 20, 2020
1 parent 8f64ae3 commit c186555
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions py_asciimath/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def get_symbols_for(
{"asciimath": "'", "latex": "'", "mathml": "'"},
{"asciimath": "/", "latex": "/", "mathml": "/"},
{"asciimath": "|", "latex": "|", "mathml": "|"},
{"asciimath": "|", "latex": "\\vert", "mathml": "|"},
{"asciimath": "|", "latex": "\\mid", "mathml": "|"},
{"asciimath": ":", "latex": ":", "mathml": ":"},
{"asciimath": "int", "latex": "\\int", "mathml": "∫"},
Expand Down
5 changes: 2 additions & 3 deletions py_asciimath/grammar/latex_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
| s "_" s -> exp_under
| s "^" s -> exp_super
| s "_" s "^" s -> exp_under_super
s: _l start? _r -> exp_par
| "\\left" (_l | /\./ | /\\vert/ | /\\mid/) start? "\\right" (_r | /\./ | /\\vert/ | /\\mid/) -> exp_par
s: "\\left" (_l | /\./ | /\\vert/ | /\\mid/ | /\[/) start? "\\right" (_r | /\./ | /\\vert/ | /\\mid/ | /\]/) -> exp_par
| "\\begin{{matrix}}" row_mat (/\\\\/ row_mat?)* "\\end{{matrix}}" -> exp_mat
| /\\sqrt/ "[" i "]" "{{" start "}}" -> exp_binary
| _u "{{" start "}}" -> exp_unary
| _b "{{" start "}}" "{{" start "}}" -> exp_binary
| /\\sqrt/ "[" start "]" "{{" start "}}" -> exp_binary
| _latex1 -> symbol
| _latex2 -> symbol
| _c -> const
Expand Down
6 changes: 3 additions & 3 deletions py_asciimath/transformer/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ def exp_par(self, items):
left = "{:"
elif left in ["\\vert", "\\mid"]:
left = "|:"
else:
elif left != "[":
left = l2mml_left[items[0].value]
if right == ".":
right = ":}"
elif right in ["\\vert", "\\mid"]:
right = ":|"
else:
elif right != "]":
right = l2mml_right[items[-1].value]
return left + " ".join(items[1:-1]) + right

Expand All @@ -421,7 +421,7 @@ def exp_unary(self, items):

@log
def exp_binary(self, items):
if items[0] == "\\sqrt":
if items[0].startswith("\\sqrt"):
return "root(" + items[1] + ")(" + items[2] + ")"
return l2mml_bin[items[0]] + "(" + items[1] + ")(" + items[2] + ")"

Expand Down
4 changes: 4 additions & 0 deletions py_asciimath/translation/latex2asciimath.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
left_parenthesis = get_symbols_for("left_parenthesis", "asciimath", "latex")
left_parenthesis.pop(".")
left_parenthesis.pop("\\vert")
# left_parenthesis.pop("[")
right_parenthesis = get_symbols_for("right_parenthesis", "asciimath", "latex")
right_parenthesis.pop(".")
right_parenthesis.pop("\\vert")
# right_parenthesis.pop("]")

smb = get_symbols_for("misc_symbols", "asciimath", "latex")
smb.update(get_symbols_for("function_symbols", "asciimath", "latex"))
Expand All @@ -18,4 +20,6 @@
smb.update(get_symbols_for("operation_symbols", "asciimath", "latex"))
smb.update(get_symbols_for("greek_letters", "asciimath", "latex"))
smb.update(get_symbols_for("arrows", "asciimath", "latex"))
smb.update(left_parenthesis)
smb.update(right_parenthesis)
smb = dict(sorted(smb.items(), key=lambda x: (-len(x[0]), x[0])))

0 comments on commit c186555

Please sign in to comment.