add converting of tex-style script styles like \em

This commit is contained in:
Maximilian Keßler 2022-03-31 23:57:02 +02:00
parent 70439bfeb9
commit e97995310d
2 changed files with 28 additions and 1 deletions

View file

@ -49,3 +49,7 @@ UTF8_REPLACEMENTS = {
r'{\ss}': 'ß',
r'{ß}': 'ß',
}
TEX_SCRIPTSTYLES = {
r'\em' : r'\emph'
}

View file

@ -2,7 +2,7 @@ from constants import *
import re
from pathlib import Path
def migrate_old_utf8_escape(line:str):
def migrate_old_utf8_escape(line: str):
for old, new in UTF8_REPLACEMENTS.items():
while True:
old = old.replace('\\', r'\\')
@ -13,6 +13,27 @@ def migrate_old_utf8_escape(line:str):
line = line[:m.start()] + new + line[m.end():]
return line
def migrate_tex_script_styles(line: str):
for old, new in TEX_SCRIPTSTYLES.items():
while True:
old = old.replace('\\', r'\\')
m = re.search(r'{' + old + r' *(.*?)}', line)
if m is None:
break
else:
line = line[:m.start()] + new + '{' + m.groups()[0] + '}' + line[m.end():]
return line
def migrate_old_quotes(line: str):
while True:
m = re.search(r',,(.*?)``', line)
if m is None:
break
else:
line = line[:m.start()] + r'\enquote{' + m.groups()[0] + r'}' + line[m.end():]
print(line)
return line
def _migrate_lazy_math_alphabet(line: str, letters: str, short: str, alph: str):
for letter in letters:
@ -71,6 +92,8 @@ def optimize_line(line: str) -> str:
line = migrate_deprecated(line)
line = replace_unicode(line)
line = migrate_old_utf8_escape(line)
line = migrate_old_quotes(line)
line = migrate_tex_script_styles(line)
return line