6

After the massive update of the Miktex distribution, I have observed the collision between the minted package and tcolorbox. Interestingly, the compilation runs successfully if I remove the option most of the tcolorbox library. In other case I have seen the Latex error message:

! LaTeX Error: Command \gather already defined.

MNWE:

\listfiles
\documentclass{scrbook}
\usepackage{minted} 
\show\gather  
\usepackage[most]{tcolorbox}
\show\gather

\begin{document}
  Test
\end{document}

2 Answers 2

8

This is because of package lineno. The current version patches environment gather even, if it has not been defined before. So amsmath cannot be loaded after lineno any longer. So, because tcolorbox with option most loads amsmath, you should load minted (which loads lineno) after tcolorbox:

\listfiles
\documentclass{scrbook}
\usepackage[most]{tcolorbox}
\usepackage{minted} 

\begin{document}
  Test
\end{document}

And because current version of tcolorbox also has a module minted, I would suggest to use:

\listfiles
\documentclass{scrbook}
\usepackage[most,minted]{tcolorbox}

\begin{document}
  Test
\end{document}
1
3

Because of package dependencies, it might not be obvious which package loads what. Using \RequirePackage might be a safer option as it ensures amsmath is always loaded first.

\RequirePackage{amsmath}
\documentclass{scrbook}
\usepackage{minted}   
\usepackage[most]{tcolorbox}

\begin{document}
  Test
\end{document}
2
  • very good idea :) thank yo
    – flymg
    Commented Jan 9, 2023 at 8:39
  • Loading amsmath before the class is IMHO not a documented feature of the package and could fail, if the class defines environments or commands, that have to be redefined by amsmath. Generally only some packages can be loaded before \documentclass others fail. I would not recommend to do so.
    – cabohah
    Commented Jan 11, 2023 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .