\def\havemjolisting{1}
-\usepackage{listings}
-\usepackage{tcolorbox}
+\ifx\lstset\undefined
+ \usepackage{listings}
+\fi
+
+\ifx\tcbuselibrary\undefined
+ \usepackage{tcolorbox}
+\fi
% Tell tcolorbox to use ``listings'' within the boxes.
\tcbuselibrary{listings}