Skip to content

Avoid crash when a known command's required arg ends a group#190

Open
SAY-5 wants to merge 1 commit into
alvinwan:masterfrom
SAY-5:fix-label-missing-arg-crash
Open

Avoid crash when a known command's required arg ends a group#190
SAY-5 wants to merge 1 commit into
alvinwan:masterfrom
SAY-5:fix-label-missing-arg-crash

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 18, 2026

Copy link
Copy Markdown

Summary

  • Fixes Error parsing #189. TexSoup(r"{\label}") raised TypeError: Malformed argument because \label has a known one-required-argument signature, and when its argument is absent at the end of a group the parser consumed the closing } as the argument, leaving the group unterminated.
  • read_arg_required now skips the fallback "use the next token as the argument" branch when that next token is a closing delimiter (} or ]), so a missing required argument is simply left empty instead of swallowing the delimiter.

The reduced case is {\label}, but the same crash hit the original \tikzmath{\label = 1;} / \node[...] {\label} document in the issue.

Validation

  • python3 -m pytest (190 passed)
  • New regression test test_known_command_missing_arg_at_group_end fails on the current parser and passes with this change.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@lorenzo25832

Copy link
Copy Markdown

This does not seem to fully fix it:

In [90]: TexSoup(r"\foreach \label in {1,2,3,4}{}")
Out[90]: \foreach \label{ in }{1,2,3,4}{}

In [91]: TexSoup(r"\foreach \i in {1,2,3,4}{}")
Out[91]: \foreach \i in {1,2,3,4}{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error parsing

2 participants