Skip to content

Commit

Permalink
no need for compile (it is cached anyway)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk committed Jan 21, 2025
1 parent 92d39b2 commit e602115
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions bibfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def apply_on_expression(x, f):
UNICODE_TO_LATEX = {
key: value for key, value in unicode_to_latex_map.items() if not is_ascii(key)
}
ACCENTS = "".join(re.escape(k) for k in """ = ~ ^ . " ' """.split())
WHITESPACE_RE = re.compile(r"\s+")
ACCENTS_RE = re.compile(r"\{\\([" + ACCENTS + r"])\{([a-zA-Z])\}\}")
# Character class for latex accents.
LATEX_ACCENTS = "".join(re.escape(k) for k in "=~^.\"'")


def cleanup_expression(x):
Expand All @@ -78,8 +77,8 @@ def cleanup_expression(x):
ret.append(UNICODE_TO_LATEX.get(char, char))

res = "".join(ret)
res = WHITESPACE_RE.sub(" ", res)
res = ACCENTS_RE.sub(r"{\\\1\2}", x)
res = re.sub(r"\s+", " ", res)
res = re.sub(r"\{\\([" + LATEX_ACCENTS + r"])\{([a-zA-Z])\}\}", r"{\\\1\2}", x)
return res


Expand Down

0 comments on commit e602115

Please sign in to comment.