Printing Code from Python in Latex via "minted"

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
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!
 
on Phys.org
If I understand you correctly, you want to show your Python code in [itex]\LaTeX[/itex] 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 [itex]\LaTeX[/itex] 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   Reactions: vanhees71 and Baarken