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.04k stars 318 forks source link

Add an option to delete commands but keep their wrapped text #60

Closed andylin-hao closed 2 years ago

andylin-hao commented 2 years ago

Motivation

I add a command-line option (--commands_only_to_delete) to delete user-defined LaTeX commands but retain the text wrapped in the commands. This is useful for commands that are meant to temporarily change text colors and formats (e.g., some user-defined \red command that makes the text red), which are common in collaborative writing to highlight different people's texts. Such commands should be removed upon submissions but the text within ought to be retained.

Usage

Usages are exactly the same as --commands_to_delete. Note that if the commands listed here duplicate that after commands_to_delete, the default action will be retaining the wrapped text.

Modification

  1. __main__.py: add an option and related help text.
  2. arxiv_latex_cleaner.py: add an optional parameter to the _remove_command function, and keep (or not) the text accordingly.
  3. arxiv_latex_cleaner_test.py: add unit test cases for test_remove_command
  4. tex/main.tex: add integration test.

Btw, I fix a small bug regarding the _search_reference function. I find that picture references in LaTeX are allowed to be in different cases compared to the actual file names. So it's safer to add a re.IGNORECASE when doing re.search.

jponttuset commented 2 years ago

Thanks @andylin-hao!