# Clean comment.cut file with latexmk

latexmk -C does not remove the temporary auxiliary comment.cut file created by the comment package. How can this functionality be achieved?

MWE:

$latexmk --version Latexmk, John Collins, 25 October 2018. Version 4.61$ cat test.tex
\documentclass{article}
\usepackage{comment}
\specialcomment{smalltt}{\begingroup}{\endgroup}
\begin{document}
\begin{smalltt}
test
\end{smalltt}
\end{document}

$latexmk && latexmk -C [...]$ ls
comment.cut  test.tex


Setting $clean_full_ext='cut'; in ~/.latexmkrc does not work: $ cat ~/.latexmkrc
$clean_full_ext='cut';$ ls
test.tex

$(latexmk && latexmk -C) &> /dev/null && ls comment.cut test.tex  I tried other extensions and they seem to work fine: $ cat ~/.latexmkrc
$clean_full_ext='jpg'$ echo abc > test.jpg && ls
test.jpg  test.tex

$(latexmk && latexmk -C) &> /dev/null && ls comment.cut test.tex  • Add $clean_full_ext='cut'; to the .latexmkrc file
– user185617
Apr 12 '19 at 12:34
• @user185617 Interestingly, this does not work $rm -f comment.cut && cat ~/.latexmkrc$clean_full_ext='cut'; $latexmk &> /dev/null && latexmk -C && ls Latexmk: This is Latexmk, John Collins, 25 October 2018, version: 4.61. comment.cut test.tex. I tried other extensions and they seem to work fine. Apr 12 '19 at 13:18 • @MiBr your last comment is not very clear as to what is commands and what is output, could you update your question with that information instead? Apr 12 '19 at 13:30 • Note that AFAIK latexmk only cleans files that has the same base name as the document being worked on. comment.cut does not share the basename Apr 12 '19 at 13:34 • @daleif I updated my question. But you're right, the jpg extension test only works because i call the file test.jpg, otherwise latexmk does not attempt deletion. Apr 12 '19 at 13:39 ## 1 Answer Latexmk maintainer here: What you have found is the actual situation in the current version of latexmk. Originally the $clean_full_ext variable was to specify extensions of the files to be deleted in a cleanup, with the base name being the same as that of the .tex file. I extended it to allow more general patterns, with wildcards, but with a requirement that the pattern contain the placeholder %R, which gets replaced by the base name of the .tex file. That was needed in practice.

But I felt nervous about a more general wildcarding pattern, since a minor error in configuration could have rather dangerous consequences. Even so, it would be useful to have a way of deleting specific files like comment.cut. I'll take this as a feature request.

Meanwhile, the easiest way to solve your problem is simply to configure things so that the comment file does not have a fixed name, but is the base name of the .tex file followed by the extension .cut. This can be done by putting

\def\DefaultCutFileName{\def\CommentCutFile{\jobname.cut}}
\DefaultCutFileName


in the preamble of your document, and then setting

$clean_full_ext = 'cut';  in a .latexmkrc file. Better is to do $clean_ext .= ' cut';


which appends one item and so does not undo previous settings.

• Thank you for your answer. Couldn't latexmk use the information in the .fls file for cleanups? It lists comment.cut as an output of the compilation process in my case. Seems like a pretty fail-safe way to do more complete cleanups or am I missing something? Apr 16 '19 at 14:33