Skip to content

Commit

Permalink
Fix optional arg command recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Nov 5, 2023
1 parent 833ea1e commit f8370af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pydetex/_utils_tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ def get_tex_commands_args(
if len(command) == 0:
command.append(s[a + 1:b + 1].strip())
arg = s[c - 1:d + 2]
optional = '[' in arg
command.append((arg[1:-1], optional))
command.append((arg[1:-1], len(arg) != 0 and arg[0] == '['))
if not cont:
if pos:
command.append((a, d + 2))
Expand Down
2 changes: 1 addition & 1 deletion pydetex/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def __str__(self) -> str:
patch = property(lambda self: self[2])


vernum = Version(1, 0, 6)
vernum = Version(1, 0, 7)
ver = str(vernum)
rev = ''
4 changes: 4 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ def test_get_tex_commands_args(self) -> None:
s = 'This is \\subfloat[a title]'
self.assertEqual(ut.get_tex_commands_args(s), (('subfloat', ('a title', True)),))
self.assertEqual(ut.get_tex_commands_args(s, True), (('subfloat', ('a title', True), (8, 26)),))
s = 'This is \\command{[not_optional]}'
self.assertEqual(ut.get_tex_commands_args(s), (('command', ('[not_optional]', False)),))
s = 'This is \\command [optional]'
self.assertEqual(ut.get_tex_commands_args(s), (('command', ('optional', True)),))

def test_find_tex_commands_no_argv(self) -> None:
"""
Expand Down

0 comments on commit f8370af

Please sign in to comment.