0

So a little bit of background: I'm fairly new to LaTeX, I've been writing up homework in it for 3 years and that's it. I'm writing my undergrad thesis with it because it's a departmental requirement, and for part of my thesis, I wrote a Python program. My advisor would like me to include the full code of the program as an appendix to the paper. Since I personally have a ton of trouble reading code that isn't highlighted, I'm attempting to use the minted package to import the code from the .py file directly and add highlighting.

The first roadblock that I hit with this was that I was doing my thesis in ShareLaTeX originally, so in order to use Pygments, which as I understand it from my research is the Python package that allows minted to highlight the code, I had to switch to an offline application, since ShareLaTeX doesn't support that. I spent the last couple hours wrestling with installing and configuring TeXStudio so that I could get my thesis to actually build at all, and at last I have most of it working--except for importing the .py file!

What I've found is that when I comment out the line that imports the .py file, \small{\inputminted[linenos]{python}{../../../example-file.py}}, in my document, everything runs smoothly, however when I leave the line in, it will start to build the document, sometimes put the warnings from the rest of the document in the log, and then stall out and never finish. By "never finish" I mean that it keeps trying to build it forever and never throws any errors.

I tried importing the exact same file to a blank document, and ended up getting the exact original error message that made me eventually conclude I needed to switch to an offline editor in the first place, saying that I'm missing Pygments. This is after installing Pygments for Python by the way.

Here is the test file that is throwing the error:

\documentclass{report}
\usepackage{minted}

\begin{document}

\small{\inputminted[linenos]{python}{example-file.py}}

\end{document}

And here's a screenshot of the error message:

error message about Pygments

How can I get my Python file to import?

3
  • Can you please specify what error are you getting? Commented Mar 7, 2018 at 11:08
  • using \small like that will make your entire document smal, Size commands do not take an argument, the syntax is {\small stuff} not \small{stuff} Commented Mar 7, 2018 at 15:59
  • Why do you say sharelatex does not support this? I do not have an account, but their documentation has examples sharelatex.com/learn/Code_Highlighting_with_minted Commented Mar 7, 2018 at 16:01

1 Answer 1

2

This error is because minted runs pygments on the background, and to do that it requires that the compiler has access to the shell.

The error message is quite clear:

Package minted Error: You must invoke LaTeX with the -shell-escape flag.

So you'll have to run, for example:

pdflatex -shell-escape my_document.tex
2
  • you mean in the command prompt? Commented Mar 7, 2018 at 11:29
  • Yes, in the command prompt. Depending on the IDE you are using, you can configure it to use this -shell-escape flag. Commented Mar 7, 2018 at 11:48

You must log in to answer this question.

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