Send Python snippets embedded in your LaTeX documents straight to a live REPL, all without leaving Emacs.
- Literate workflow – run the code that sits in your
lstlisting
,minted
,pycode
or\lstinline
blocks while you write. - Zero‑setup – a single
.el
file that relies only on AUCTeX/LaTeX‑mode and the built‑inpython.el
. - Smart target selection – with point inside a code block the whole block is sent; with an active region only the region is sent.
- Automatic REPL management – starts
python-shell
(oripython
when configured) if none is running and re‑uses the existing one otherwise.
(use-package latex-send-python
:straight (:host github :repo "ppareit/latex-send-python")
:after (latex python) ; make sure both modes are loaded first
:bind (:map LaTeX-mode-map
("C-c C-c" . latex-send-python)))
M-x package-install-file RET
/path/to/latex-send-python.el RET
-
Clone the repository:
git clone https://github.com/ppareit/latex-send-python.git
-
Add the directory to your
load-path
and require the file:(add-to-list 'load-path "~/path/to/latex-send-python") (require 'latex-send-python)
- Open a
.tex
file that contains Python code blocks. - Place the point inside the desired block or select a region.
- Hit
C-c C-c
(or runM-x latex-send-python
).
Where is the point? | What gets sent to the shell? |
---|---|
Inside a lstlisting env. |
The full environment |
Inside \lstinline |
The inline expression |
Active region | The region only |
If no shell is running one is spawned automatically using the interpreter set in python-shell-interpreter
(ipython
is honoured).
- When using
ipython
, enable%autoreload
for a smoother experience. - Combine with AUCTeX’s
TeX-command-master
for a tight write–run–compile loop.
Non at the moment, but let me know if something needs customization!
- On Emacs 29+ the first invocation can throw an "unexpected prompt" error coming from
python.el
. Calling the command again fixes the session. - Currently only
lstlisting
andlstinline
are detected. Other code‑friendly environments (e.g.verbatim
) could be added. PRs welcome!
Bug reports, feature requests and pull requests are warmly welcome.
- Fork the repository and create your branch (
git checkout -b feature/foo
). - Commit your changes with clear messages (
git commit -am 'Add foo'
). - Push the branch (
git push origin feature/foo
) and open a PR.
If this package saves you time you can buy the maintainer a coffee via PayPal.
This project is distributed under the terms of the GNU General Public License, version 3. See the LICENSE file for details.