# including python code in beamer? [closed]

Suppose I have a python file. How can I include in beamer presentation in one of the slides?

\insertcode{"Scripts/mc.py"}{Python}


does not work with \usepackage{listings} , which otherwise work in article.

• Try \begin{frame}[fragile] for the frame where this should be.
– yo'
Feb 10, 2014 at 17:24
• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. In particular, could you put together a minimal working example (MWE) that shows what you've tried, and what doesn't work? Feb 10, 2014 at 17:27
• \insertcode is not a macro defined by the listings package. Are you using some kind of template? In any case, please post an MWE as suggested by cmhughes. Feb 10, 2014 at 17:55
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Mar 2, 2014 at 13:10

The command which should be used with listings is \lstinputlisting[language=Python]{filename.py}. Here is a minimal example of its usage:

\documentclass{beamer}
\usepackage{listings}

\begin{document}
\begin{frame}
\frametitle{Python and Py-Ramesses}
\lstinputlisting[language=Python]{filename.py}
\end{frame}
\end{document}


If you want fully-fledged syntax highlighting try using the minted package. Here is a minimal example:

\documentclass{beamer}
\usepackage{minted}

\begin{document}
\begin{frame}
\frametitle{Python and Py-Ramesses}
\inputminted{python}{filename.py}
\end{frame}
\end{document}