1

ArXiv requires uploading TeX sources. The justifications they give for this are rather weak IMHO, but that is beside the point.

What is the easiest way to clean up an article for submission? ArXiv suggests to automatically delete all lines starting with %, but of course this vastly understates the possibilities of LaTex: Many of my files contain complex \if statements, \iffalse-\fi blocks, not all % symbols mark comments, etc.

Is there a good automatic way to prepare a file for submission?

During the compilation, clearly at some point LaTeX must decide which parts to ignore and which to compile, what to do with the conditionals etc. Is there a way to send the result of this into a file?

Or are there any other good ideas of how to approach this problem?

  • I assume 'cleaning up' just implies that the source is readable and does not contain unnecessary packages etc. It does not mean to make it as simplified as possible. Things to avoid are dependencies on external tools, use pdflatex only (so no XeLaTeX or LuaLaTeX or ConTeXt), precompile bbl and ind files, precompile minted listings, pythontex, gnuplottex etc. But considering standard TeX/LaTeX syntax such as if-statements there should not be a problem at all for ArXiv to compile it. – Marijn Jul 16 at 11:01
  • No, that is not what I mean by cleaning up. I mean removing comments, outcommented old content, outcommented content cut from the article that is meant to be published in the future, etc. What should remain is exactly as much source code as is needed to generate the article as it looks as PDF. – rmh Jul 16 at 11:57
  • That is what I mean by 'making the source readable', i.e., removing commented content et cetera. That was maybe not clear, sorry. However, for ArXiv I don't think even this kind of cleaning up is very important, they just want to make sure that the document can be compiled with their setup. As long as you provide a source that does this then it's ok. Alternatively, if your reason for cleaning up is more personal (i.e., you want the file you submit to be as clean as possible) then you are also the person that decides what should be cleaned and what shouldn't. – Marijn Jul 16 at 12:28
  • 1
    in answer to your specific question about whether you can output the intermediate latex expansion then no, latex interleaves parsing the source file and execution, it just reads the source file character by character stripping comments and evaluating conditionals as it goes, so it never constructs (or is able to output) an equivalent file with such constructs removed. – David Carlisle Jul 16 at 13:01
  • @ David Carlisle: Thanks for that clarification! That makes the source code requirement of ArXiv even more unreasonable than I thought. OK, well then, no ArXiv submission from me. – rmh Jul 16 at 14:22
2

Pandoc has an option to clean the source code:

  pandoc withcomments.tex -o withoutcomments.tex
1

latexindent.pl can help with this, using its -rr switch.

For example, if you start with

% my comment
\documentclass{article} % trailing comment

%comment
\begin{document}
\begin{equation}
x^2
\end{equation} % more comments
% leading comment
\end{document}

and the following settings in rmh.yaml

replacements:
    -
        substitution: s/^%.*\R//mg

and run the command:

latexindent.pl -rr -l=rmh.yaml myfile.tex

then you receive

\documentclass{article} % trailing comment

\begin{document}
\begin{equation}
x^2
\end{equation} % more comments
\end{document}

The above has left in trailing comments. If you want these removed as well, then you can explore

replacements:
    -
        substitution: s/%.*\R//mg

If you'd like more subtle replacements, we'll have to see a before and after in your question :)

  • As I said, I also want the content of any false conditionals automatically stripped. But apparently that is hopeless, so I will just have to do it manually. – rmh Jul 17 at 9:19
  • If you can provide a complete example of before and after, I might be able to help – cmhughes Jul 17 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.