diff --git a/py_asciimath/const.py b/py_asciimath/const.py index dd39032..28edca9 100644 --- a/py_asciimath/const.py +++ b/py_asciimath/const.py @@ -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": "∫"}, diff --git a/py_asciimath/grammar/latex_grammar.py b/py_asciimath/grammar/latex_grammar.py index 4ca273f..c46dee2 100644 --- a/py_asciimath/grammar/latex_grammar.py +++ b/py_asciimath/grammar/latex_grammar.py @@ -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 diff --git a/py_asciimath/transformer/transformer.py b/py_asciimath/transformer/transformer.py index 9975f9e..d4a32e0 100644 --- a/py_asciimath/transformer/transformer.py +++ b/py_asciimath/transformer/transformer.py @@ -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 @@ -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] + ")" diff --git a/py_asciimath/translation/latex2asciimath.py b/py_asciimath/translation/latex2asciimath.py index a350195..b85c80a 100644 --- a/py_asciimath/translation/latex2asciimath.py +++ b/py_asciimath/translation/latex2asciimath.py @@ -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")) @@ -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])))