def run_arxiv_cleaner(parameters):
  """Core of the code, runs the actual arXiv cleaner."""

  files_to_delete = [ # [STATE] files_to_delete = ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$'] [/STATE]
      r'\.aux$',
      r'\.sh$',
      r'\.blg$',
      r'\.brf$',
      r'\.log$',
      r'\.out$',
      r'\.ps$',
      r'\.dvi$',
      r'\.synctex.gz$',
      '~$',
      r'\.backup$',
      r'\.gitignore$',
      r'\.DS_Store$',
      r'\.svg$',
      r'^\.idea',
      r'\.dpth$',
      r'\.md5$',
      r'\.dep$',
      r'\.auxlock$',
      r'\.fls$',
      r'\.fdb_latexmk$',
  ]

  if not parameters['keep_bib']:
    files_to_delete.append(r'\.bib$') # [STATE] files_to_delete = ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'] [/STATE]

  parameters.update({ # [STATE] parameters = {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$']} [/STATE]
      'to_delete': files_to_delete,
      'figures_to_copy_if_referenced': [
          r'\.png$',
          r'\.jpg$',
          r'\.jpeg$',
          r'\.pdf$',
      ],
  })

  logging.info('Collecting file structure.')
  parameters['output_folder'] = _create_out_folder(parameters['input_folder']) # [STATE] parameters = {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'} [/STATE]

  from_zip = parameters['input_folder'].endswith('.zip') # [STATE] from_zip = False [/STATE]
  tempdir_context = ( # [STATE] tempdir_context = {_exceptions=()} [/STATE]
      tempfile.TemporaryDirectory() if from_zip else contextlib.suppress()
  )

  with tempdir_context as tempdir: # [STATE] tempdir = None [/STATE]

    if from_zip:
      logging.info('Unzipping input folder.')
      shutil.unpack_archive(parameters['input_folder'], tempdir)
      parameters['input_folder'] = tempdir

    splits = _split_all_files(parameters) # [STATE] splits = {'all': ['main.bib', 'main.bbl', 'main.tex', 'main.aux', 'ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'in_root': ['main.bib', 'main.bbl', 'main.tex', 'main.aux'], 'not_in_root': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'to_copy_in_root': ['main.bbl', 'main.tex'], 'to_copy_not_in_root': ['figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'tex_in_root': ['main.tex'], 'tex_not_in_root': ['figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], 'non_tex_in_root': ['main.bbl'], 'non_tex_not_in_root': ['figures/data_not_included.txt', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'external_tikz_figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf'], 'svg_inkscape': []} [/STATE]

    logging.info('Reading all tex files')
    tex_contents = _read_all_tex_contents( # [STATE] tex_contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE]
        splits['tex_in_root'] + splits['tex_not_in_root'], parameters
    )

    for tex_file in tex_contents: #  [STATE] 5 [/STATE]
      logging.info('Removing comments in file %s.', tex_file)
      tex_contents[tex_file] = _remove_comments_and_commands_to_delete( #  [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE] [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE] [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE] [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE] [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE]
          tex_contents[tex_file], parameters
      )

    for tex_file in tex_contents: #  [STATE] 5 [/STATE]
      logging.info('Replacing \\includesvg calls in file %s.', tex_file)
      tex_contents[tex_file] = _replace_includesvg(
          tex_contents[tex_file], splits['svg_inkscape']
      )

    for tex_file in tex_contents: #  [STATE] 5 [/STATE]
      logging.info('Replacing Tikz Pictures in file %s.', tex_file)
      content = _replace_tikzpictures( #  [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE] [STATE] content = '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n' [/STATE] [STATE] content = '' [/STATE] [STATE] content = '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n' [/STATE] [STATE] content = '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n' [/STATE]
          tex_contents[tex_file], splits['external_tikz_figures']
      )
      # If file ends with '\n' already, the split in last line would add an extra
      # '\n', so we remove it.
      tex_contents[tex_file] = content.split('\n') #  [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': ['\ufeff\\includegraphics{ext_tikz/test2.pdf}', ''], 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': ['\ufeff\\includegraphics{ext_tikz/test2.pdf}', ''], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}', '\\addplot{figures/data_included.txt}', '']} [/STATE]

    _keep_only_referenced_tex(tex_contents, splits) # [STATE] splits = {'all': ['main.bib', 'main.bbl', 'main.tex', 'main.aux', 'ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'in_root': ['main.bib', 'main.bbl', 'main.tex', 'main.aux'], 'not_in_root': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'to_copy_in_root': ['main.bbl', 'main.tex'], 'to_copy_not_in_root': ['figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'tex_in_root': ['main.tex'], 'tex_not_in_root': ['figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], 'non_tex_in_root': ['main.bbl'], 'non_tex_not_in_root': ['figures/data_not_included.txt', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'external_tikz_figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf'], 'svg_inkscape': [], 'tex_to_copy': ['figures/figure_included.tex', 'figures/figure_included.tikz', 'main.tex']} [/STATE]
    _add_root_tex_files(splits)

    for tex_file in splits['tex_to_copy']: #  [STATE] 2 [/STATE]
      logging.info('Replacing patterns in file %s.', tex_file)
      content = '\n'.join(tex_contents[tex_file]) #  [STATE] content = '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n' [/STATE] [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
      content = _find_and_replace_patterns(
          content, parameters.get('patterns_and_insertions', list())
      )
      tex_contents[tex_file] = content #  [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': ['\ufeff\\includegraphics{ext_tikz/test2.pdf}', ''], 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE] [STATE] tex_contents = {'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'} [/STATE]
      new_path = os.path.join(parameters['output_folder'], tex_file) #  [STATE] new_path = '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv/figures/figure_included.tex' [/STATE] [STATE] new_path = '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv/figures/figure_included.tikz' [/STATE] [STATE] new_path = '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv/main.tex' [/STATE]
      logging.info('Writing modified contents to %s.', new_path)
      _write_file_content(
          content,
          new_path,
      )

    full_content = '\n'.join( # [STATE] full_content = '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n\n\ufeff\\includegraphics{ext_tikz/test2.pdf}\n\n\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
        ''.join(tex_contents[fn]) for fn in splits['tex_to_copy']
    )
    _copy_only_referenced_non_tex_not_in_root(parameters, full_content, splits)
    for non_tex_file in splits['non_tex_in_root']: #  [STATE] 1 [/STATE]
      logging.info('Copying non-tex file %s.', non_tex_file)
      _copy_file(non_tex_file, parameters)

    _resize_and_copy_figures_if_referenced(parameters, full_content, splits)
    logging.info('Outputs written to %s', parameters['output_folder'])

run_arxiv_cleaner({'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False})

1. def run_arxiv_cleaner(parameters):
2.   """Core of the code, runs the actual arXiv cleaner."""
3.
4.   files_to_delete = [
5.       r'\.aux$',
6.       r'\.sh$',
7.       r'\.blg$',
8.       r'\.brf$',
9.       r'\.log$',
10.       r'\.out$',
11.       r'\.ps$',
12.       r'\.dvi$',
13.       r'\.synctex.gz$',
14.       '~$',
15.       r'\.backup$',
16.       r'\.gitignore$',
17.       r'\.DS_Store$',
18.       r'\.svg$',
19.       r'^\.idea',
20.       r'\.dpth$',
21.       r'\.md5$',
22.       r'\.dep$',
23.       r'\.auxlock$',
24.       r'\.fls$',
25.       r'\.fdb_latexmk$',
26.   ]
27.
28.   if not parameters['keep_bib']:
29.     files_to_delete.append(r'\.bib$')
30.
31.   parameters.update({
32.       'to_delete': files_to_delete,
33.       'figures_to_copy_if_referenced': [
34.           r'\.png$',
35.           r'\.jpg$',
36.           r'\.jpeg$',
37.           r'\.pdf$',
38.       ],
39.   })
40.
41.   logging.info('Collecting file structure.')
42.   parameters['output_folder'] = _create_out_folder(parameters['input_folder'])
43.
44.   from_zip = parameters['input_folder'].endswith('.zip')
45.   tempdir_context = (
46.       tempfile.TemporaryDirectory() if from_zip else contextlib.suppress()
47.   )
48.
49.   with tempdir_context as tempdir:
50.
51.     if from_zip:
52.       logging.info('Unzipping input folder.')
53.       shutil.unpack_archive(parameters['input_folder'], tempdir)
54.       parameters['input_folder'] = tempdir
55.
56.     splits = _split_all_files(parameters)
57.
58.     logging.info('Reading all tex files')
59.     tex_contents = _read_all_tex_contents(
60.         splits['tex_in_root'] + splits['tex_not_in_root'], parameters
61.     )
62.
63.     for tex_file in tex_contents:
64.       logging.info('Removing comments in file %s.', tex_file)
65.       tex_contents[tex_file] = _remove_comments_and_commands_to_delete(
66.           tex_contents[tex_file], parameters
67.       )
68.
69.     for tex_file in tex_contents:
70.       logging.info('Replacing \\includesvg calls in file %s.', tex_file)
71.       tex_contents[tex_file] = _replace_includesvg(
72.           tex_contents[tex_file], splits['svg_inkscape']
73.       )
74.
75.     for tex_file in tex_contents:
76.       logging.info('Replacing Tikz Pictures in file %s.', tex_file)
77.       content = _replace_tikzpictures(
78.           tex_contents[tex_file], splits['external_tikz_figures']
79.       )
80.       # If file ends with '\n' already, the split in last line would add an extra
81.       # '\n', so we remove it.
82.       tex_contents[tex_file] = content.split('\n')
83.
84.     _keep_only_referenced_tex(tex_contents, splits)
85.     _add_root_tex_files(splits)
86.
87.     for tex_file in splits['tex_to_copy']:
88.       logging.info('Replacing patterns in file %s.', tex_file)
89.       content = '\n'.join(tex_contents[tex_file])
90.       content = _find_and_replace_patterns(
91.           content, parameters.get('patterns_and_insertions', list())
92.       )
93.       tex_contents[tex_file] = content
94.       new_path = os.path.join(parameters['output_folder'], tex_file)
95.       logging.info('Writing modified contents to %s.', new_path)
96.       _write_file_content(
97.           content,
98.           new_path,
99.       )
100.
101.     full_content = '\n'.join(
102.         ''.join(tex_contents[fn]) for fn in splits['tex_to_copy']
103.     )
104.     _copy_only_referenced_non_tex_not_in_root(parameters, full_content, splits)
105.     for non_tex_file in splits['non_tex_in_root']:
106.       logging.info('Copying non-tex file %s.', non_tex_file)
107.       _copy_file(non_tex_file, parameters)
108.
109.     _resize_and_copy_figures_if_referenced(parameters, full_content, splits)
110.     logging.info('Outputs written to %s', parameters['output_folder'])
111.
112. run_arxiv_cleaner({'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False})

Question: How many times will the loop on line 105 execute when 'run_arxiv_cleaner({'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False})' is called?

Answer: 1


def _read_all_tex_contents(tex_files, parameters):
  contents = {} # [STATE] contents = {} [/STATE]
  for fn in tex_files: #  [STATE] 5 [/STATE]
    contents[fn] = _read_file_content( #  [STATE] contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n']} [/STATE] [STATE] contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n']} [/STATE] [STATE] contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': []} [/STATE] [STATE] contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}']} [/STATE] [STATE] contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']} [/STATE]
        os.path.join(parameters['input_folder'], fn)
    )
  return contents

_read_all_tex_contents(['main.tex', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})

1. def _read_all_tex_contents(tex_files, parameters):
2.   contents = {}
3.   for fn in tex_files:
4.     contents[fn] = _read_file_content(
5.         os.path.join(parameters['input_folder'], fn)
6.     )
7.   return contents
8.
9. _read_all_tex_contents(['main.tex', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})

Question: How many times will the loop on line 4 execute when '_read_all_tex_contents(['main.tex', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})' is called?

Answer: contents = {'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n']}


def _strip_tex_contents(lines, end_str):
  """Removes everything after end_str."""
  for i in range(len(lines)): #  [STATE] 83 [/STATE]
    if end_str in lines[i]:
      if '%' not in lines[i]:
        return lines[: i + 1]
      elif lines[i].index('%') > lines[i].index(end_str):
        return lines[: i + 1]
  return lines

_strip_tex_contents(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n', '\n', 'This should be ignored.\n'], '\\end{document}')

1. def _strip_tex_contents(lines, end_str):
2.   """Removes everything after end_str."""
3.   for i in range(len(lines)):
4.     if end_str in lines[i]:
5.       if '%' not in lines[i]:
6.         return lines[: i + 1]
7.       elif lines[i].index('%') > lines[i].index(end_str):
8.         return lines[: i + 1]
9.   return lines
10.
11. _strip_tex_contents(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n', '\n', 'This should be ignored.\n'], '\\end{document}')

Question: How many times will the loop on line 3 execute when '_strip_tex_contents(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n', '\n', 'This should be ignored.\n'], '\\end{document}')' is called?

Answer: 83


def _remove_comments_and_commands_to_delete(content, parameters):
  """Erases all LaTeX comments in the content, and writes it."""
  content = [_remove_comments_inline(line) for line in content] # [STATE] content = ['\\begin{document}\n', 'Text\n', '', '\n', 'Text%\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '', '\\includegraphics{images/im1_included.png}\n', '', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '', '', '', '', '', '\n', '', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '', '\n', '\\input{figures/figure_included.tex}\n', '', '\n', '', '', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '', '\\input{figures/figure_included.tikz}\n', '\n', '', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'] [/STATE]
  content = _remove_environment(''.join(content), 'comment') # [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should\\mytodo{Do this later} not be separated\n\\mytodo{This is a todo command with a nested \\textit{command}.\nPlease remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\nfrom this one.\n\n\\begin{mynote}\n  This is a custom environment that could be excluded.\n\\end{mynote}\n\n\\newif\\ifvar\n\n\\ifvar\n\\if    false\n\\if false\n\\if 0\n\\iffalse\n\\ifvar\nText\n\\fi\n\\fi\n\\fi\n\\fi\n\\fi\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test \\red{hello\ntest \\red{hello}}\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
  content = _remove_iffalse_block(content) # [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should\\mytodo{Do this later} not be separated\n\\mytodo{This is a todo command with a nested \\textit{command}.\nPlease remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\nfrom this one.\n\n\\begin{mynote}\n  This is a custom environment that could be excluded.\n\\end{mynote}\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test \\red{hello\ntest \\red{hello}}\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
  for environment in parameters.get('environments_to_delete', []): #  [STATE] 1 [/STATE]
    content = _remove_environment(content, environment) # [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should\\mytodo{Do this later} not be separated\n\\mytodo{This is a todo command with a nested \\textit{command}.\nPlease remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test \\red{hello\ntest \\red{hello}}\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
  for command in parameters.get('commands_only_to_delete', []): #  [STATE] 1 [/STATE]
    content = _remove_command(content, command, True) # [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should\\mytodo{Do this later} not be separated\n\\mytodo{This is a todo command with a nested \\textit{command}.\nPlease remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
  for command in parameters['commands_to_delete']: #  [STATE] 1 [/STATE]
    content = _remove_command(content, command, False) # [STATE] content = '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n' [/STATE]
  return content

_remove_comments_and_commands_to_delete(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})

1. def _remove_comments_and_commands_to_delete(content, parameters):
2.   """Erases all LaTeX comments in the content, and writes it."""
3.   content = [_remove_comments_inline(line) for line in content]
4.   content = _remove_environment(''.join(content), 'comment')
5.   content = _remove_iffalse_block(content)
6.   for environment in parameters.get('environments_to_delete', []):
7.     content = _remove_environment(content, environment)
8.   for command in parameters.get('commands_only_to_delete', []):
9.     content = _remove_command(content, command, True)
10.   for command in parameters['commands_to_delete']:
11.     content = _remove_command(content, command, False)
12.   return content
13.
14. _remove_comments_and_commands_to_delete(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})

Question: How many times will the loop on line 10 execute when '_remove_comments_and_commands_to_delete(['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], {'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'})' is called?

Answer: 1