diff --git a/proto/cheby/print_latex.py b/proto/cheby/print_latex.py index e9b8d0c1..a80a9af3 100644 --- a/proto/cheby/print_latex.py +++ b/proto/cheby/print_latex.py @@ -14,15 +14,27 @@ def escape_printable(text): # Remove whitespaces at start and end of string text = text.strip() - # Escape special characters - SPECIAL_CHARS = ['\\', '&', '%', '$', '#', '_', '{', '}', '~', '^'] - for char in SPECIAL_CHARS: - text = text.replace(char, '\\' + char) - - # Allow line breaks after '_' and '.' in long strings - ALLOW_BREAK_CHARS = ['.', '_'] - for char in ALLOW_BREAK_CHARS: - text = text.replace(char, char + '\\allowbreak{}') + # Escape text only if not between two `$` signs (i.e., an equation) + pattern = r'(?