add support for replacing unicode

This commit is contained in:
Maximilian Keßler 2022-02-16 17:23:29 +01:00
parent f54b569e26
commit 6929d13dcd
2 changed files with 21 additions and 1 deletions

View File

@ -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'
}

View File

@ -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