google-research / arxiv-latex-cleaner

arXiv LaTeX Cleaner: Easily clean the LaTeX code of your paper to submit to arXiv
Apache License 2.0
5.16k stars 322 forks source link

ValueError: Unmatched \ifthenelse #101

Closed thwfhk closed 1 month ago

thwfhk commented 1 month ago

Hi, I tried the newest version (1.0.7) and got the following error

Traceback (most recent call last):
  File "/opt/miniconda3/bin/arxiv_latex_cleaner", line 5, in <module>
    from arxiv_latex_cleaner.__main__ import __main__
  File "/opt/miniconda3/lib/python3.12/site-packages/arxiv_latex_cleaner/__main__.py", line 201, in <module>
    run_arxiv_cleaner(final_args)
  File "/opt/miniconda3/lib/python3.12/site-packages/arxiv_latex_cleaner/arxiv_latex_cleaner.py", line 721, in run_arxiv_cleaner
    tex_contents[tex_file] = _remove_comments_and_commands_to_delete(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.12/site-packages/arxiv_latex_cleaner/arxiv_latex_cleaner.py", line 356, in _remove_comments_and_commands_to_delete
    content = _simplify_conditional_blocks(content)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.12/site-packages/arxiv_latex_cleaner/arxiv_latex_cleaner.py", line 235, in _simplify_conditional_blocks
    raise ValueError(f"Unmatched {tree['start'].group()}")
ValueError: Unmatched \ifthenelse

However, the version 1.0.6 succeeded. I would expect there is some new bug introduced by the newest version.

jponttuset commented 1 month ago

Thanks for reporting this issue. Could you please provide a minimal example that makes the tool break?

jponttuset commented 1 month ago

@michael-markl Do you think this might be caused by your PR #99?

michael-markl commented 1 month ago

Yes, the fact that an error is thrown is probably caused by my PR. However, the previous implementation also did not properly support commands that start with \if that are not Tex primitive conditionals (such as the \ifthenelse command).

I have added support for some of these well known third party non-tex-primitive-conditionals-commands that start with \if in https://github.com/google-research/arxiv-latex-cleaner/commit/f0ac9cc9c9bd5093de8db1e5cab8f5f65761e5e6 but haven't filed a PR yet (as tests are missing).

thwfhk commented 1 month ago

Thanks for reporting this issue. Could you please provide a minimal example that makes the tool break?

Sure. Simply any example which uses \ifthenelse, e.g.

\ifthenelse{\equal{37}{42}}{No}{Yes}