tcolorbox minted library with python3 non-determinism

Later versions of the package tcolorbox allows formatting source code with its minted library (which uses the minted package).

When a document is compiled, a temporary file with extension .pyg is generated with LaTeX code created by the pygmentize Python application.

I have noticed that with Python3 this generated file may differ from run to run, with its lines sorted differently each time. The lines are the same at each run, but not necessarily in the same order.

This is making latexmk run indefinitely when compiling a document. That happens because latexmk determines if a new run of the latex compiler is needed based on a checksum of the input files.

This bad behaviour is not seen with Python2.

Here is a minimal working example test.tex:

\documentclass{article}
\usepackage[minted]{tcolorbox}

\begin{document}

\begin{tcblisting}{listing engine=minted, minted language=java}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
\end{tcblisting}

\end{document}


Compilation command:

latexmk -pvc -pdf -latexoption=-shell-escape test


latexmk has in its output message:

Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
Changed files, or newly in use since previous run(s):
'test.pyg'
Latexmk: Maximum runs of pdflatex reached without getting stable files


I am looking for a fix for tcolorbox using Python3.

• I'd say that one must exclude .pyg files from the checks made by latexmk; they are used for the current run, not for the next one, so the fact that they heve changed is irrelevant. – egreg Jan 19 '14 at 16:45
• I think you want to look at %hash_calc_ignore_pattern in the latexmk docs. I expect that a rule something like $hash_calc_ignore_pattern{'pyg'} = '.*'; should work. As far as I can tell, there isn't a way just to ignore files with a particular extension, which would be more efficient. – G. Poore Jan 19 '14 at 17:21 • @G.Poore Your suggestion of adding a rule to make latexmk ignore all lines of all files with the .pyg extension works for me. Maybe you want to add this as an answer. But this is an workaround. The generation of the file should be deterministic, in my opinion. – Romildo Jan 20 '14 at 8:38 1 Answer I think you want to look at %hash_calc_ignore_pattern in the latexmk docs. I expect that a rule something like $hash_calc_ignore_pattern{'pyg'} = '.*'; should work. As far as I can tell, there isn't a way just to ignore files with a particular extension, which would be more efficient.

The .pyg file is a temp file generated by minted. It is meant to be deleted automatically by minted at the end of a compile. It is deleted when I replace the tcblisting environment with minted in the example. But it isn't deleted when the tcblisting environment is used. This is due to the interaction of a bug in minted with the tcolorbox source. Basically, the temp file isn't deleted due to the way that tcolorbox invokes minted. (The \usemintedstyle command neglects to delete its temp file.) This minted bug has been fixed in the development version, which uses a more efficient scheme for deleting temp files. Just having the minted bug fixed might resolve you problems, without the need for the latexmk rule, since all .pyg files will be deleted.

The .pyg file is usually used multiple times per compile, but I think only once in the example (due to the workings of tcolorbox). So if the document hasn't changed, then its contents shouldn't, even at intermediate steps. I'm not sure what Python 3 could be doing differently. Perhaps something in Pygments, though that seems very unlikely.