-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocument.tex
95 lines (86 loc) · 2.84 KB
/
document.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
\documentclass[11pt]{article}
\usepackage{ipynb-tex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fancyvrb}
\usepackage{hyperref}
\pagenumbering{gobble}
\def\projectname{ipynb-tex}
\newenvironment{example}
{\VerbatimEnvironment
\begin{VerbatimOut}[gobble=3]{example.out}}
{\end{VerbatimOut}%
\vspace{1ex}%
\setlength{\parindent}{0pt}%
\fbox{\begin{minipage}{0.5\linewidth}%
\inputminted[resetmargins]{latex}{example.out}%
\end{minipage}%
\hspace{0.05\linewidth}%
\begin{minipage}{0.45\linewidth-2\fboxsep}%
\input{example.out}%
\end{minipage}%
\vspace{1ex}}}
\begin{document}
\noindent Jupyter notebook's pdf export feature is not as rich as necessary in some cases, particularly with regards to maths exports etc. however it is common to want to include notebook source and output into a LaTeX document.
In that case working from LaTeX and importing individual notebook cells is most effective and provides the nicest resulting document. To that end \verb|ipynb-tex| provides new TeX commands to include cells directly from notebooks.
\section{Command Examples}
\subsection{Markdown Content}
Simple markdown content can be included directly in the document:
\begin{center}
\mintinline{tex}{\IpynbSource{notebook.ipynb}{intro}}\vspace{1em}
\fbox{
\IpynbSource{notebook.ipynb}{intro}
}
\end{center}
\subsection{Source Code}
The source code cell can be exported directly in :
\begin{minted}{tex}
\begin{ minted }[
breaklines,
escapeinside=||
]{python}
|\IpynbSource{notebook.ipynb}{tag1}|
\end{ minted }
\end{minted}
\begin{minted}[
breaklines,
escapeinside=||
]{python}
|\IpynbSource{notebook.ipynb}{tag1}|
\end{minted}
Source can include \TeX code
\begin{Verbatim}
\IpynbSource{notebook.ipynb}{equation}
\end{Verbatim}
\IpynbSource{notebook.ipynb}{equation}
\subsection*{Cell Output}
Include the output of a cell
\begin{Verbatim}
\IpynbOutText{notebook.ipynb}{tag1}
\end{Verbatim}
\IpynbOutText{notebook.ipynb}{tag1}
\noindent Include the output of a cell with \TeX in it
\begin{Verbatim}
\IpynbOutLatex{notebook.ipynb}{tag3}
\end{Verbatim}
\IpynbOutLatex{notebook.ipynb}{tag3}
\noindent [In progress] Handle sympy
\begin{verbatim}
\IpynbSource{notebook.ipynb}{sympy}
$$\ipynboutput{notebook.ipynb}{sympy}$$
\end{verbatim}
%\IpynbSourceLatex{notebook.ipynb}{sympy}
\subsection{Images}
Include an image, technically \projectname only outputs a base-64 encoded image, but it can be included, by using Christian Sachs' \href{https://ctan.org/tex-archive/macros/luatex/latex/luaimageembed?lang=en}{luaimageembed} package.
\begin{Verbatim}
\includegraphicsembedded[width=0.5\pagewidth]{
\IpynbOutImage{notebook.ipynb}{graph}
}
\end{Verbatim}
\begin{center}
\includegraphicsembedded[width=0.5\pagewidth]{
\IpynbOutImage{notebook.ipynb}{graph}
}
\end{center}
\end{document}