LaTeX Printing Code from Python in Latex via "minted"

Click For Summary
The discussion centers on importing Python code into LaTeX using the "minted" package, with a specific error related to the need for the -shell-escape flag. The user initially encounters difficulties and seeks help. An alternative method for including Python code in LaTeX is suggested, but the user prefers minted for its aesthetic appeal. Ultimately, the issue is resolved by running the LaTeX command from Terminal with the appropriate flag, allowing the user to successfully include their Python code.
member 428835
Hi PF!

I am trying to import code written in Python into Latex via the "minted" package. However, I am getting the error:

Package minted error: you must invoke latex with the -shell-escape flag.

I tried googling help but I can't figure it out. I'm using Python 2.7 on mac OSX sierra. Any help is greatly appreciated!
 
Physics news on Phys.org
If I understand you correctly, you want to show your Python code in \LaTeX as shown below?

I am not familiar with the minted package you mention, but if you are open to other suggestions I'll tell you what I do: When I have to include e.q. Python code in \LaTeX I use the code found here: https://www.quora.com/What-is-the-optimal-way-to-include-Python-code-in-a-LaTeX-document

If you want other colors for let's say the print function, you can easily customize it to fit your needs at the start of the code. Let me know if you need any help using the code.
main-qimg-3fa6adccc1dc059422e28cadfe7ed471.png
 
Last edited by a moderator:
Thanks for the suggestion. I tried it out, but is was getting very monochromatic code. I'm quite sold on minted if I could just get the darn thing to work.
 
Looks like it's working fine. I just had to run it from Terminal as
$ pdflatex -shell-escape hw2
Thanks for your insight!
 
  • Like
Likes vanhees71 and Baarken

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 11 ·
Replies
11
Views
5K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
2K
Replies
15
Views
10K
Replies
7
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K