1

Ok so basically I am just trying to get some code shown in my document. I usually use windows but i have been trying to get latex to work properly on my debian install. I have created a minimal working example to demonstrate my problem.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, breakable}
\usemintedstyle{emacs}

\newenvironment{testbox}
{\tcblisting{listing only,colback=blue!10, breakable, colframe=blue!10, width = 1.1\textwidth, center, top=0pt, bottom=0pt, left=25pt,listing engine=minted, minted language=python, minted style=emacs, minted options={autogobble, fontsize=\footnotesize, python3, tabsize=2, linenos, frame=none
}}}
{\endtcblisting}

\begin{document}

\par\noindent This one doesn't work...

\begin{testbox}
a = 10
print('hello world')
print(a)
\end{testbox}


\end{document}

When this is compiled with --shell-escape, I get the following error: error message

The documentation here is less than helpful, it says that a file is missing but I'm not sure this applies here. This exact code does compile on my windows install of latex, so not sure why its not working here.

For added confusion, when I replace the testbox with

\begin{minted}{python}
print('hello world')
\end{minted}

it compiles just fine no errors whatsoever. If it helps I have some extra information about my tex installs:

On windows I have miktex installed, where I had a lot of errors with minted as well (other errors) related to the path of my python install.

On debian I have texlive installed, but because the standard minted environment runs fine I dont think its a path issue.

All help is greatly appreciated! I also wouldn't mind changing the way I display the code in the document, I just want a way to add a background color, line numbers and have working page breaks etc.

2
  • Define environment testbox by \newtcblisting instead of \newenvironment. Like all otherverbatim-like envs, \end{tcblisting} is so special that it cannot be used in replacement text of other macros. Sep 17 '21 at 0:18
  • @muzimuzhiZ, unfortunately this doesnt solve my problem, exact same error :(
    – Ruben deV
    Sep 17 '21 at 11:19
1

If you correctly implement @muzimuzhi's suggestion with --shell-escape flag; it should produce a correct output. I suspect that you have used \newtcblisting with the same definition. You need to change it a bit according to the syntax of the command in use. See the following code.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, breakable}
\usemintedstyle{emacs}

\newtcblisting{testbox}{%
  listing only,%
  colback=blue!10,%
  breakable,%
  colframe=blue!10,%
  width = 1.1\textwidth,%
  center,%
  top=0pt,%
  bottom=0pt,%
  left=25pt,%
  listing engine=minted,%
  minted language=python,%
  minted style=emacs,%
  minted options={%
    autogobble,%
    fontsize=\footnotesize,%
    python3,%
    tabsize=2,%
    linenos,%
    frame=none%
  }%
}

\begin{document}
This one works!

\begin{testbox}
a = 10
print('hello world')
print(a)
\end{testbox}
\end{document}

It produces:

1

2
  • Then maybe there is something wrong with my install and that is causing the problem. I tried your code but it still throws the same error, this is my output. When I use \begin{minted}{python} I get this output. I just dont understand Why one would work but the other one doesn't
    – Ruben deV
    Sep 17 '21 at 20:23
  • Ok so weirdly enough after just playing around a bit I got it to work, no idea how or what exactly has changed, Ill put my new tcb listing in an answer
    – Ruben deV
    Sep 17 '21 at 20:37
1

So I was playing around a bit and now it works no problem for some reason. To be honest I have no idea why but it works. For someone in the future with the same problem, maybe this works.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{xcolor}

%\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, breakable}
\usemintedstyle{emacs}

\definecolor{backcolour}{HTML}{2F1E2E}

\newtcblisting[auto counter]{pymint}[1]{
  listing only, colback=backcolour, colframe=red!75!black, breakable,  listing engine=minted, center, width=1.1\textwidth, top=0pt, bottom=0pt, left=25pt, minted language=python, minted style=paraiso-dark, fonttitle=\normalsize,title =Listing \thetcbcounter:  #1 , minted options={ fontsize=\footnotesize, python3, tabsize=2, linenos, frame=none}
}

\begin{document}
This one works!

\begin{pymint}{}
a = 10
print('hello world')
print(a)
\end{pymint}
\end{document}

I think adding a top heading part to the box fixed it somehow but I wouldn't know why or how. The pdf produces this output:

enter image description here

Also thank you for taking the time to help me! I greatly appreciate it.

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.