From f54b569e262613ed8093a7d4e67d4ea94cebeea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 16 Feb 2022 16:57:13 +0100 Subject: [PATCH] fix bad regexes --- latex_legacy_converter.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/latex_legacy_converter.py b/latex_legacy_converter.py index d1c6e14..8a57dfd 100644 --- a/latex_legacy_converter.py +++ b/latex_legacy_converter.py @@ -1,13 +1,14 @@ from constants import ENVIRONMENTS, ALPHABETS, DEPRECATED import re -import pathlib from pathlib import Path def _migrate_lazy_math_alphabet(line: str, letters: str, short: str, alph: str): for letter in letters: while True: - m = re.search(r'\\%s%s(?=![a-zA-Z@])' % (short, letter), line) + if r'\fS' in line: + pass + m = re.search(r'\\%s%s(?![a-zA-Z@])' % (short, letter), line) if m is None: break else: @@ -16,7 +17,7 @@ def _migrate_lazy_math_alphabet(line: str, letters: str, short: str, alph: str): def migrate_lazy_math_alphabets(line: str) -> str: - for short, alph in ALPHABETS: + for short, alph in ALPHABETS.items(): if short == '': line = _migrate_lazy_math_alphabet(line, 'NZQRCFK', '', alph) else: @@ -30,7 +31,7 @@ def migrate_deprecated(line: str) -> str: for old, new in DEPRECATED.items(): while True: old = old.replace('\\', r'\\') - m = re.search(old + '(?=![a-zA-Z@])', line) + m = re.search(old + '(?![a-zA-Z@])', line) if m is None: break else: @@ -64,6 +65,7 @@ def convert(path: Path): if __name__ == "__main__": - here = Path('.') - for file in here.rglob('*.tex'): + here = Path('.').resolve() + files = here.rglob('*.tex') + for file in files: convert(Path(file))