GitHub - burakbayramli/jupimacs: emacs plug-in to run python code inside tex or markdown buffer (original) (raw)

DESCRIPTION

emacs-jupyter connects to an in-process jupyter kernel, executes notebook code, and displays the results automatically in a LaTeX or Markdown buffer.

INSTALLATION

First install Pymacs - https://github.com/pinard/Pymacs. Build, install. In your .emacs

(load-file "[PYMACS DIR]/pymacs.el")

Then pip install

ipython
matplotlib
pytest
setuptools

In your .emacs add the snippet below. The code can seem excessive, but the extra stuff was needed to be able to detect if I am in an .md or .tex buffer so we can load the right module, also set the right tempo template functions.

(defun reload-pymacs()
  (interactive)
  (if (buffer-live-p (get-buffer "*Pymacs*" ))
      (kill-buffer (get-buffer "*Pymacs*")))
  (message (buffer-file-name (current-buffer)))
  ;;
  ;; load tex or md mode based on the extension
  (if (equal (file-name-extension (buffer-file-name (current-buffer))) "tex")
      (progn 
    (pymacs-load "[INSTALL DIR]/ipython-tex")
    (global-set-key "\M-," 'ipython-tex-run-py-code)
    (global-set-key [f5] 'ipython-tex-complete-py)
    (tempo-define-template 
     "tex-listings-python" 
     '("\\begin{minted}[fontsize=\\footnotesize]{python}\n"
       (s)
       "\n\\end{minted}\n"
       )
     "")	
    ))
  (if (equal (file-name-extension (buffer-file-name (current-buffer))) "md")
      (progn 
    (pymacs-load "[INSTALL DIR]/ipython-md")
    (global-set-key "\M-," 'ipython-md-run-py-code)
    (global-set-key [f5] 'ipython-md-complete-py)
    (tempo-define-template 
     "tex-listings-python" 
     '("```python\n"
       (s)
       "\n```\n"
       )
     "")	
    ))

  )

(global-set-key [f1] 'tempo-template-tex-listings-python)
(global-set-key [f11] 'reload-pymacs)

For better management create a virtualenv environment, pip install the necessary packages from there, install pymacs on it, then start emacs with the bash script below,

#!/bin/bash
source /some/dir/yourenv/bin/activate
/usr/bin/emacs24

FEATURES

LIMITATIONS

Take a look at our other sites

IT

Science, Mathematics

LICENSE

Emacs Jupyter is licensed under GPL v3. See COPYING for details.