I've got some python code that I wrote and I wonder how can import the code from file.py or file.txt into texstudio instead of copying all my code again.
Asked
Active
Viewed 528 times
2 Answers
1
You can use the listing package:
\usepackage{listing}
\lstinputlisting[language=Python]{path_to_file.py}
You'll get similar output as minted, except it requires no external tool and no configuration.
Miyase
- 2,544
- 2
- 12
- 26
0
You may consider using the minted package that allows this kind of importing requirements. If you want to include part or all of the following file, foo.py in the same directory, using \inputminted in a listing environment.
def foo(a, b):
return a + b
def bar(a, b)
return a - b
This command also accepts optional parameters to specify the start line and end line, and supports an absolute path for the source file.
\begin{listing}[H]
\inputminted[firstline=1,lastline=3]{python}{foo.py}
\end{listing}
Ukiyo-E
- 728
upquotepackage is necessary formintedto work. What distribution are you running (TeXlive, MikTeX, different?) – Tomáš Kruliš Jul 17 '20 at 12:27