0

For my teaching efforts, I want to integrate some Jupyter-Notebooks to my Presentation, which is written in LaTeX. These Notebooks contain examples and assignments. And these examples/assignments I want to structure dynamically, meaning that I can change my files without much hassle, either for different or new topics. I know that the \listings command makes it possible, to add .py files (and for that fact any other supported programming language) into LaTeX and hence make a frame. But is this also possible for .ipynb files?

Ive added a MWE:


\documentclass{article}

\usepackage{listings} \usepackage{xcolor} \usepackage{FiraMono} \usepackage[T1]{fontenc} \usepackage{xkeyval}

\definecolor{codegreen}{RGB}{17,136,17} \definecolor{codegray}{RGB}{14,14,14} \definecolor{codered}{RGB}{173,46,46} \definecolor{codeblue}{RGB}{16,16,255}

\lstdefinestyle{codestyle}{ basicstyle=\small\firamonolining, keywordstyle=\color{codeblue}, commentstyle=\itshape\color{codegreen}, identifierstyle=\color{codegray}, stringstyle=\color{codered}, breakatwhitespace=false, breaklines=true, keepspaces=true, numbers=left, numbersep=5pt, numberstyle=\tiny, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2, captionpos=b, } \lstset{style=codestyle}

\lstdefinelanguage{Py}[]{Python}{ morekeywords=[1]{,as,assert,nonlocal,with,yield,self,True,False,None,} }

\lstset{literate=% {Ö}{{"O}}1 {Ä}{{"A}}1 {Ü}{{"U}}1 {ß}{{\ss}}1 {ü}{{"u}}1 {ä}{{"a}}1 {ö}{{"o}}1 }

\usepackage[english]{babel}

\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

% Useful packages \usepackage{amsmath} \usepackage{graphicx} \usepackage[colorlinks=true, allcolors=blue]{hyperref}

\title{Your Paper} \author{You}

\begin{document} \maketitle

\begin{abstract} Your abstract. \end{abstract}

\section{Introduction}

\subsection{Manual Integration of Code} \begin{lstlisting}[language=Py] import numpy as np import matplotlib.pyplot as plt x=np.linspace(0,10,100) y=np.sin(x) plt.plot(x,y) print ("Hello World") from sympy.abc import * from sympy.functions import * from sympy import * f=sin(x/(2pi)) plot(f,diff(f), size=(3,3)) def polar(x,y): if x<=0 or y<=0: print('N') else: r=sqrt(x2+y2) phi=asin(y/r) return(r,(phi180/pi) \end{lstlisting}

\subsection[fragile]{Automated Integration of Code via listing and .py-file} \lstinputlisting[langauge=Py,firstline=1,lastline=22]{Test.py}

============

%\lstinputlisting[language=Py, firstline=1,lastline=22]{Test.ipynb}

=========

\bibliographystyle{alpha} \bibliography{sample}

\end{document}

The line in question is: %\lstinputlisting[language=Py, firstline=1,lastline=22]{Test.ipynb}

Is it possible to add a .ipynb-file (either via the listing command or a completely different one) to my LaTeX-PDF, without manually adding it?

Rivas
  • 1

0 Answers0