From 6929d13dcd2eafa27b0663abd9eed285564b4d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 16 Feb 2022 17:23:29 +0100 Subject: [PATCH] add support for replacing unicode --- constants.py | 11 +++++++++++ latex_legacy_converter.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/constants.py b/constants.py index e0c710d..a51636b 100644 --- a/constants.py +++ b/constants.py @@ -20,3 +20,14 @@ DEPRECATED = { r'\sm': r'\setminus', r'\st': r'^{\ast}', } + +UNICODE = { + '∃': r'\exists', + '∀': r'\forall', + 'ℕ': r'\mathbb{N}', + 'ℤ': r'\mathbb{Z}', + 'Λ': r'\Lambda', + '⇔': r'\iff', + '⇒': r'\implies', + '⇐': r'\impliedby' +} diff --git a/latex_legacy_converter.py b/latex_legacy_converter.py index 8a57dfd..34c0e50 100644 --- a/latex_legacy_converter.py +++ b/latex_legacy_converter.py @@ -1,4 +1,4 @@ -from constants import ENVIRONMENTS, ALPHABETS, DEPRECATED +from constants import * import re from pathlib import Path @@ -28,6 +28,8 @@ def migrate_lazy_math_alphabets(line: str) -> str: def migrate_deprecated(line: str) -> str: + if '∃' in line: + foo = 2 for old, new in DEPRECATED.items(): while True: old = old.replace('\\', r'\\') @@ -39,6 +41,12 @@ def migrate_deprecated(line: str) -> str: return line +def replace_unicode(line: str) -> str: + for old, new in UNICODE.items(): + line = line.replace(old, r'\ensuremath{%s}' % new) + return line + + def migrate_environments(line: str) -> str: for old_env, new_env in ENVIRONMENTS.items(): line = line.replace(r'\begin{%s}' % old_env, r'\begin{%s}' % new_env) @@ -50,6 +58,7 @@ def optimize_line(line: str) -> str: line = migrate_environments(line) line = migrate_lazy_math_alphabets(line) line = migrate_deprecated(line) + line = replace_unicode(line) return line