Display a large python file on multiple frames automatically with beamer

beamerminted

I have a large python file that I would like to display on my beamer presentation.

I usually use minted but I cannot find how to display the file on multiple frames automatically (like it is done by default with the article document class) when using something like:

\begin{frame}[fragile]
    \scriptsize
    \inputminted{python}{my_file.py}
\end{frame}

Thanks a lot !

Best Answer

Here is the solution:

\documentclass{beamer}
\usepackage{minted}
\begin{filecontents*}{pythoncode.py}
import getopt, sys, urllib, time

def main():

    status = 0

# input arguments

    try:
    opts, args = getopt.getopt(sys.argv[1:],"h:iq",
                   ["help","invid=","quarter="])
    except getopt.GetoptError:
    usage()
    tree = False
    for o, a in opts:
    if o in ("-h", "--help"):
        usage()
    if o in ("-i", "--invid"):
        invid = str(a)
    if o in ("-q", "--quarter"):
        quarter = int(a)

    kepid, invid, kepmag, mode, start, stop, release = GetMetaData(invid,quarter)

# convert Gregorian date to Julian date

def Greg2JD(year, month, day):

    if (month < 3):
        y = float(year) - 1.0
        m = float(month) + 12.0
    else:
        y = float(year)
        m = float(month)
    a = 0; b = 0
\end{filecontents*}
\begin{document}
\begin{frame}[
t, % align text from top
allowframebreaks, % allow brake frames
fragile % allow verb content
]{Python Code}
    \scriptsize
    \inputminted[breaklines,breakanywhere]{python}{pythoncode.py}
\end{frame}
\end{document}

enter image description here

Related Question