

Jupyter and Latex – ipynb-tex
source link: https://www.tuicool.com/articles/hit/V3MBNjb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ipynb-tex.sty
ipynb-tex is a simple style sheet which allows you to extract tagged cells out of a Jupyter notebook and include them in a TeX document
Rather than save output or copies of source code to insert into TeX docs, ipynb-tex always inserts the latest cells from your notebooks directly into TeX files.
Installation
In your main document directory, just make a symlink to the ipynb-tex.sty file.
ln -s /path/to/ipynb-tex/ipynb-tex.sty
Include cells in your .tex document
Command Description\ipynbsource{notebook}[tag]
Include the source from all cells sharing the tag "example".
\ipynboutput{notebook}[tag]
Include the output from all cells sharing the tag "example".
\ipynb{notebook}[tag]
Include the source and output from all cells sharing the tag "example".
\ipynbimage{notebook}[tag]
Include an image
\ipynbtex{notebook}[tag]
Include raw TeX output
Compile LaTeX
ipynb-tex uses PythonTeX to execute the cell extraction code. So, just as with PythonTeX, you'll need to execute pythontex
as part of your document build. Also include --shell-escape to allow external functions to be called correctly.
pdflatex --shell-escape document.tex #scan the document, figure out what Python needs to be executed pythontex --rerun=always document #executes the Python found in the document pdflatex --shell-escape document.tex #include any valid TeX printed from the Python execution pdflatex --shell-escape document.tex #ensure any included references are correctly handled
Tagging cells in a notebook
Toggle the toolbar UI
Tag a cell
Modifying this plugin
This repo comes with a ready to go version of ipynb-tex.sty
, but if you want to make changes and rebuild it just run ./build
, which merges ipynb-tex-template.sty
and extract_cells.py
to create ipynb-tex.sty
.
There are no package dependencies required to run this script, but to execute the sample you'll need to include a set of dependencies.
pip install -r requirements.txt
Running Tests
pip install nose nosetests
Todo
- Remove the need to "rerun=always", by registering the [filename].ipynb as a dependency while pythontex is running.
- Export cells only once, by making an in-memory variable which tags a file as already processed, to avoid repeated work.
- Add a \ipynbdirectory which serves as the base path for all notebooks, so if you're compiling a doc with lots, no need to keep including the path
Recommend
-
76
README.md tex-conceal.vim This plugin extends the Conceal feature of Vim for LaTeX. Without conceal
-
8
【记录贴】在树莓派中安装 TeX Live本文使用 Zhihu On VSCode 创作并发布为什么要在树莓派上安装 TeX Live 呢?因为好玩(x)可以学到 Linux 的一些东...
-
11
TEX: A...
-
10
TeX Live宏包集合和自定义安装G GrindelwaldFor the greater good.“Te...
-
7
TeX Live 2020不安装指南李阿玲首席水煮牛肉品鉴师TeX Live 2020已经发布了...
-
7
Adicionando kernels do C# e F# no Jupyter Notebook/Lab. (#csharp #fsharp #dotnet #jupyter) Posted on
-
11
TEX, the Decentralized Token Exchange The First Decentralized Exchange of the DeFi-on-Bitcoin Ecosystem Exchanges are an important part of the Bitcoin ecosystem, but also its Achilles heel. Many...
-
6
TeX Is Wonderful, What Is TeX? March 9, 2011 Two stories about the beginning of TeX Don Knuth is one of the founders of Computer Science, that is CS with capital...
-
3
.tex | 生物学知识提纲 Feb 25, 2022 最近在学校书店看到一本书,是 BARRON’S 360 系列的《A Complete Study Guide to Biology with Online Practice》。(原本)觉得对半路出家的我来说很有用...
-
6
TeX 的表格陷阱 Thu Sep 21, 2017 (La)TeX 常被视为高质量出版工具。 确实如此, 但并非用它们生成的文档必然具备较...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK