From e4d411b8412f13e8f2bc9e33c9257f94eb9efc7d Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:21:44 -0700 Subject: [PATCH] UI: fix rendering LaTeX enclosed between \[ and \] --- modules/html_generator.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/html_generator.py b/modules/html_generator.py index c5eba5a8..b3152008 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -72,6 +72,14 @@ def replace_blockquote(m): @functools.lru_cache(maxsize=None) def convert_to_markdown(string): + # Make \[ \] LaTeX equations inline + pattern = r'^\s*\\\[\s*\n([\s\S]*?)\n\s*\\\]\s*$' + replacement = r'\\[ \1 \\]' + string = re.sub(pattern, replacement, string, flags=re.MULTILINE) + + # Escape backslashes + string = string.replace('\\', '\\\\') + # Quote to string = replace_quotes(string)