Repository: google-research/arxiv-latex-cleaner

Issue:
[Unexpected Behavior] Comments Not Removed on Lines with "auto-ignore"
While fixing issue #91, I discovered that comments in lines containing the word `auto-ignore` are not being removed as expected. This behavior is not documented in either the README or the help message, which may lead to unexpected outcomes for users. 
I suppose there is a specific reason for this behavior as it is also being tested 🤔

## Example
### Input:
```latex
Foo auto-ignore Bar ... % Top Secret Comment
```
### Output:
```latex
Foo auto-ignore Bar ... % Top Secret Comment
```
### Expected Output:
```latex
Foo auto-ignore Bar ... %
```

Hints from issue comments:
@jponttuset: Hi @merajhashemi!
The rationale for this behavior is that arXiv uses this %auto-ignore comment to mark a file as not being the main tex file to be compiled. You can see more info [here](https://info.arxiv.org/help/faq/mistakes.html). We could definitely make the content matching more strict (e.g. there cannot be more text apart from "auto-ignore"), feel free to send a PR if you're up for it :)
@merajhashemi: Hi @jponttuset!
Thanks for letting me know about this! I didn't realize arXiv uses the `%auto-ignore` comment in that way. I've opened a pull request (#96) to tighten the content matching.@jponttuset: I made a small suggestion in the PR not to over-tighten the matching :)

Solution patch:
diff --git a/arxiv_latex_cleaner/arxiv_latex_cleaner.py b/arxiv_latex_cleaner/arxiv_latex_cleaner.py
index 2b83c54..296e698 100644
--- a/arxiv_latex_cleaner/arxiv_latex_cleaner.py
+++ b/arxiv_latex_cleaner/arxiv_latex_cleaner.py
@@ -212,8 +212,10 @@ def _remove_iffalse_block(text):
 
 def _remove_comments_inline(text):
   """Removes the comments from the string 'text' and ignores % inside \\url{}."""
-  if 'auto-ignore' in text:
-    return text
+  auto_ignore_pattern = r'(%\s*auto-ignore).*'
+  if regex.search(auto_ignore_pattern, text):
+    return regex.sub(auto_ignore_pattern, r'\1', text)
+
   if text.lstrip(' ').lstrip('\t').startswith('%'):
     return ''
 


Test patch:
diff --git a/arxiv_latex_cleaner/tests/arxiv_latex_cleaner_test.py b/arxiv_latex_cleaner/tests/arxiv_latex_cleaner_test.py
index 8540e75..34e9488 100644
--- a/arxiv_latex_cleaner/tests/arxiv_latex_cleaner_test.py
+++ b/arxiv_latex_cleaner/tests/arxiv_latex_cleaner_test.py
@@ -278,6 +278,16 @@ class UnitTests(parameterized.TestCase):
           'line_in': '%auto-ignore\n',
           'true_output': '%auto-ignore\n',
       },
+      {
+          'testcase_name': 'auto_ignore_middle',
+          'line_in': 'Foo % auto-ignore Comment\n',
+          'true_output': 'Foo % auto-ignore\n',
+      },
+      {
+          'testcase_name': 'auto_ignore_text_with_comment',
+          'line_in': 'Foo auto-ignore % Comment\n',
+          'true_output': 'Foo auto-ignore %\n',
+      },
       {
           'testcase_name': 'percent',
           'line_in': r'100\% accurate\n',