jupyter emacs

Table of Contents

1 Jupyter Emacs

This is my personal guide for setting up jupyter notebooks in org mode of doom emacs, which required some specific configuration.

You might not even need this!

org-babel already exists to serve a lot of the same purpose! Org mode already has a built in way to excecute a lot of code. In the case of typescript look into the emacs package ob-typescript, see more information in org mode. It turns out, If you want to use the session variable, ob-typescript is not enough, and you will have to use jupyter, as discussed in this note.

1.0.1 installation

sudo pacman -S jupyter

In doom emacs, also install the package. for doom, edit ~/.doom.d/config.el and add (package! jupyter)

then, ~./.emacs.d/bin/doom sync

  1. clojure

    we want to install clojupyter to act as a clojure kernel for jupyter. To do this we need to use jupyter’s package manager (?), anaconda. (it seems like this package is very big and more than I need.) Install it with:

    → yay -S python-conda
    → conda create --name conda-env

1.0.2 add typescript kernel

You have to add a typescript kernel to jupyter notebooks if you want to work with typescript. After a little research, I decided on one called tslab

sudo npm install -g typescript
sudo npm install -g tslab
tslab install

now, you should be able to run the REPL with jupyter-run-repl and choosing the typescript option. It start’s up a typescript kernel process in the background

you should now be able to see javascript and typescript with a $ jupyter kernelspec list

initially, you should be able to open REPLS with M-x jupyter-run-repl, and at this point, have python, typescript, and javascript available to you.

1.0.3 Integrating with org mode

this is all a little bit trickier because of using DOOM emacs.

it shhould be really easy to get working according to this documentation: however, in doom, because of performance enhancer’s it get’s a little bit trickyer, even though it should be easier. also check this issue in doom for more info

first: turn on +jupyter in init.el of doom

I needed the following settings in my config.el to get everything up and running:

it was important in my case that async was not included

(setq org-babel-default-header-args:jupyter-typescript '(
                                                         (:session . "ts")
                                                         (:kernel . "tslab")))

;; this seems to add syntax-highlighting to jupyter-python and jupyter-typescript blocks
(after! org-src
 (dolist (lang '(python typescript jupyter))
 (cl-pushnew (cons (format "jupyter-%s" lang) lang)
                org-src-lang-modes :key #'car))
  ;; (org-babel-jupyter-override-src-block "python") ;; alias all python to jupyter-python
  ;; (org-babel-jupyter-override-src-block "typescript") ;; alias all python to jupyter-python

1.0.4 Usage tips

In one of the followint code blocks in org, you should be able to C-c C-c your way to a result below

This command excecutes the block that you are currently in.

to excecute to where you are, as well as all previous code blocks, run the command M-x jupyter-org-execute-to-point , which loads the whole org file into the jupyter kernel server

below I have set aside a few ways to test this out if you are looking at this document in org

  1. testing python
    b = 8
    oh = 9
    oh + 18 + b
  2. Testing typescript
    const x = "foo"
    const y = "barrr"
    x + y
    const b = "ooooooooooooo";
    5 + 6

1.0.5 Useful links:

setting up a good python environment in org mode https://rgoswami.me/posts/jupyter-orgmode/

debate about jupyter vs org mode: https://news.ycombinator.com/item?id=16841909

EIN allows you to open jupyter notebook files in emacs https://github.com/millejoh/emacs-ipython-notebook/blob/master/README.rst

Author: John Doe

Created: 2021-04-25 Sun 15:56