Skip to content

Commit

Permalink
Update replace-delimiters.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
victorliu5296 committed Sep 25, 2024
1 parent e9025c7 commit 236f2fe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions replace-delimiters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ replace_delimiters() {
sub process_math {
my ($content) = @_;
# Escape backslashes if not preceded by a backslash
$content =~ s/(?<!\\)\\/\\\\/g;
# Escape double backslashes
$content =~ s/\\\\/\\\\\\\\/g;
# Only escape \begin and \end if they are not already escaped
$content =~ s/(?<!\\\\)\\begin/\\\\begin/g;
$content =~ s/(?<!\\\\)\\end/\\\\end/g;
# Double-escape commas
$content =~ s/\\\\,/\\,/g;
# Escape underscores if not already escaped
$content =~ s/(?<!\\)_/\\_/g;
# Only escape rendered curly brackets
$content =~ s/\\left\\\{/\\left\\\\\{/g;
$content =~ s/\\right\\\}/\\right\\\\\}/g;
return $content;
}
Expand Down

0 comments on commit 236f2fe

Please sign in to comment.