Skip to content

Commit

Permalink
bugfix for latexencode braces-after-macro mode, fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
phfaist committed Sep 9, 2020
1 parent f7e8927 commit 0674048
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylatexenc/latexencode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def _apply_protection_braces_all(self, repl):
return '{' + repl + '}'
def _apply_protection_braces_after_macro(self, repl):
k = repl.rfind('\\')
if k > 0 and repl[k+1:].isalpha():
if k >= 0 and repl[k+1:].isalpha():
# has dangling named macro, apply protection.
return repl + '{}'
return repl
Expand Down
5 changes: 5 additions & 0 deletions test/test_latexencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def test_basic_2(self):
input = "\"\N{LATIN CAPITAL LETTER A WITH GRAVE} votre sant\N{LATIN SMALL LETTER E WITH ACUTE}!\" s'exclama le ma\N{LATIN SMALL LETTER I WITH CIRCUMFLEX}tre de maison \N{LATIN SMALL LETTER A WITH GRAVE} 100%."
self.assertEqual(u.unicode_to_latex(input),
"''\\`A votre sant\\'e!'' s'exclama le ma\\^\\i{}tre de maison \\`a 100\\%.")
def test_basic_2a(self):
# Issue #44
u = UnicodeToLatexEncoder(replacement_latex_protection='braces-after-macro')
input = "Jabłoński, François, ⟨.⟩, ~"
self.assertEqual(u.unicode_to_latex(input), "Jab\\l{}o\\'nski, Fran\\c{c}ois, \\ensuremath{\\langle}.\\ensuremath{\\rangle}, \\textasciitilde{}")

def test_basic_2b(self):
u = UnicodeToLatexEncoder(replacement_latex_protection='none')
Expand Down

0 comments on commit 0674048

Please sign in to comment.