Debian Codegraph @

texmf-dist/doc/latex/jupynotex/README.md

raw symbols SCIP
1 # What is Jupynotex?
2
3 A Jupyter Notebook to LaTeX translator to include whole or partial notebooks in your papers.
4
5 ## Wait, what?
6
7 A TeX package that you can use in your project to include Jupyter Notebooks (all of them, or some specific cells) as part of your text.
8
9 It will convert the Jupyter Notebook format to proper LaTeX so it gets included seamless, supporting text, latex, images, etc.
10
11
12 # How To Use?
13
14 All you need to do is include the `jupynotex.py` and `jupynotex.sty` files in your LaTeX project, and use the package from your any of your `.tex` files:
15
16 `\usepackage{jupynotex}`
17
18 After that, you can include a whole Jupyter Notebook in your file just specifying it's file name:
19
20 `\jupynotex{file_name_for_your_notebook.ipynb}`
21
22 If you do not want to include it completely, you can optionally specify which cells:
23
24 `\jupynotex[<which cells>]{sample.ipynb}`
25
26 The cells specification can be numbers separated by comma, or ranges using dashes (defaulting to first and last if any side is not included).
27
28 Examples:
29
30 - include the whole *foobar* notebook:
31
32 `\jupynotex{foobar.ipynb}`
33
34 - include just the cell #7:
35
36 `\jupynotex[7]{sample.ipynb}`
37
38 - include cells 1, 3, and 6, 7, and 8 from the range:
39
40 `\jupynotex[1,3,6-8]{sample.ipynb}`
41
42 - include everything up to the fourth cell, and the eigth:
43
44 `\jupynotex[-4,8]{whatever.ipynb}`
45
46 - include the cell number 3, and from 12 to the notebook's end
47
48 `\jupynotex[3,12-]{somenote.ipynb}`
49
50 If the cell number or the range ends with an `i` or an `o` it will only show the input or output, correspondingly. E.g.:
51
52 - include cell 1 completely, only the input of cell 2, and cells 3 and 4
53
54 `\jupynotex[1,2i,3-4]{sample.ipynb}`
55
56 - include cell 3 completely, and outputs of 5, 6, and 7
57
58 `\jupynotex[3,5-7o]{sample.ipynb}`
59
60
61 ## Configurations available
62
63 The whole package can be configured when included in your project:
64
65 \usepackage[OPTIONS]{jupynotex}
66
67 Global options available:
68
69 - `output-text-limit=N` where N is a number; it will wrap all outputs that exceed that quantity of columns
70 - `cells-id-template=TPL`: Where TPL is a template to build the title of each cell using Python's format syntax; available variables are 'number' and 'filename', it defaults to `Cell {number:02d}`
71 - `first-cell-id-template=TPL`: Same than `cells-id-template` but only applies to the first cell of each file; it defaults to the value of `cells-id-template`
72
73 A note regarding these configurations per project: as they use Python's format syntax, it may get weird with curly braces, which you must use for LaTeX to respect spaces and other characters. E.g., see this config that changes the title of all cells to just the number using three digits surrounded by dots, see how there is the `{}` for latex to delimit the whole value of the config variable, and the `{}` inside for Python formatting:
74
75 \usepackage[cells-id-template={...{number:03d}...}]{jupynotex}
76
77 Also, each cell(s) can be configured when included in your .tex files:
78
79 \jupynotex[3, OPTIONS]{yournotebook.ipynb}
80
81 Cell options available:
82
83 - `output-image-size=SIZE` where SIZE is a valid .tex size (a number with an unit, e.g. `70mm`); it will set any image in the output of those cells to the indicated size
84
85
86 ## Full Example
87
88 Check the `example` directory in this project.
89
90 There you will find different notebook examples and `.tex` files using them. Also there's a build script to easily run on any of the examples, like:
91
92 ./build cell_ranges.tex
93
94 Play with it. Enjoy.
95
96
97 # Supported cell types
98
99 Jupyter has several types of cells, `jupynotex` supports most of those. If you find one that is not supported, please open an issue with an example.
100
101 In any case, only the "code" cells are included when processing a notebook (no markdown titles, for example, to make it easy for the developer to find the numbers of cells to include).
102
103 Supported cell types in the output:
104
105 - `execute_result`: this may have multiple types of information inside; if an image is present, it will be included, otherwise if a latex output is present it will included (directly, so the latex is really parsed later by the LaTeX system, else the plain text will be included (verbatim).
106
107 - `stream`: the different text lines will be included (verbatim)
108 result.extend(_verbatimize(x.rstrip() for x in item["text"]))
109
110 - `display_data`: the image will be included
111
112 - `error`: in this case the Traceback will be parsed, sanitized and included in the output keeping its structure (verbatim)
113
114 Two type of images are currently supported (for the case in `execute_result` or `display_data` cell type:
115
116 - PNG: used directly
117
118 - SVG: converted to PDF (need to have `inkscape` present in the system) and included that
119
120
121 # Dependencies
122
123 You need Python 3 in your system, and the following modules in your LaTeX toolbox:
124
125 - [tcolorbox](https://ctan.org/pkg/tcolorbox)
126
127 - [minted](https://www.ctan.org/pkg/minted)
128
129 To support SVG images in the notebook, [inkscape](https://inkscape.org/) needs to be installed and in the system's PATH.
130
131
132 # Feedback & Development
133
134 Please open any issue or ask any question [here](https://github.com/facundobatista/jupynotex/issues/new).
135
136 To run the tests (need to have [fades](https://github.com/pyar/fades) installed):
137
138 ./tests/run
139
140 This material is subject to the Apache 2.0 license.