diff --git a/pydetex/_utils_tex.py b/pydetex/_utils_tex.py index f718c91..8e92406 100644 --- a/pydetex/_utils_tex.py +++ b/pydetex/_utils_tex.py @@ -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)) diff --git a/pydetex/version.py b/pydetex/version.py index 3966b71..e80729d 100644 --- a/pydetex/version.py +++ b/pydetex/version.py @@ -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 = '' diff --git a/test/test_utils.py b/test/test_utils.py index c5f137f..d234572 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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: """