GithubHelp home page GithubHelp logo

ox-ipynb's Introduction

ox-ipynb — Convert an org-file to an ipynb

This module allows you to export an org-file to an Ipython notebook. Python and R notebooks are currently supported. It is not currently possible to mix these languages.

About this module

The Jupyter/Ipython notebooks are ultimately just json files. This module parses an org-file, and creates json files that represent them. The parsing is rudimentary. Jupyter notebooks only have two basic cells: text and code. This module tries to parse the org-file into those two kinds of cells.

See this example org-file: ./example.org and the corresponding ipynb: ./example.ipynb.

(require 'ox-ipynb)

This will install a new export menu titled “Export to jupyter notebook” with the sub-options to export to a buffer, to a file, to a file and open, and to slides and open.

Slideshows

See ./ipynb-slideshow.org to see how to make a slideshow out an org-file.

Adding a new language

It is probably possible to add new languages by adding to the variables ox-ipynb-kernelspecs and ox-ipynb-language-infos. These were reverse-engineered to make the json metadata. I do not know what the minimal setup for this is required and suggest adapting these variables by example.

Adding scientific references

You can use org-ref to add scientific references. To make it work, you should set this variable.

(setq ox-ipynb-preprocess-hook '((lambda () (org-ref-csl-preprocess-buffer 'html))))

Then the citations and bibliography will be replaced by CSL rendered citations.

ox-ipynb's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ox-ipynb's Issues

Need for a publishing function

Hi,
Thank you for the great software which makes it a joy to work on Notebooks.
I would like to have a git repository with org files that would be published (e.g. on gitlhub pages or gitlab pages) as Notebooks, in much the same way as html pages usually are.
For that I would like to be able to use org-publish which takes a publishing function (among other parameters) as arguments. The org→html publishing function is org-html-publish-to-html , would it be possible to have an equivalent function for org→ipynb ?

What do you think ?
Best Regards.

why not also export python src block

Hi,

Thanks for writing this package. I found this is very useful.

I wonder if it's easy to include python src block as code? at the moment, it's exported as a markdown cell.

if we could do that, then we would able to include python script and export as a code cell, for example,

#+include: "tmp.py" src python

gives a cell of the whole tmp.py script.

Thanks,

What's wrong with using tables as a data source for ipython blocks?

The example says

Note that you probably should not use the tables as data sources to code blocks because the ipython notebook does not support that.

Sacha Chua demos it in R, so I tried doing it in ipython and it seemed to work great.

What do I need to worry about if I'm doing this? What relevant feature is missing from org or jupyter that I should follow?

:noweb yes is not respected

For example:

#+BEGIN_SRC python :tangle picture_output.py :noweb-ref "" :noweb yes

  # export
  def main():
      #<<picture_output.main>>#
  if __name__ == "__main__":
      main()

#+END_SRC

is not exported with the #<<picture_output.main>># noweb-reference expanded. The cell in the resulting ipynb file looks like:

{
  "cell_type": "code",
  "execution_count": 1,
  "metadata": {},
  "outputs": [],
  "source": [
    "# export\ndef main():\n    #<<picture_output.main>>#\nif __name__ == \"__main__\":\n    main()"
  ]
},

Rendering of markdown table

Hi,
first of all, this is great work. I encountered the following issue when exporting tables. The second line (after the header) results in "|--". While this is fine at least with Jupyter 5.5, this is not correctly rendered in Jupyter 5.7.

For example this org table

| h1 | h2 |
| --- + --- |
|c1  | c2 |

becomes

|Header1|Header 2|
|---
|content1|content2|

but should be

|Header1|Header 2|
|---|---|
|content1|content2|
´´`

Feature / documentation request : Adding (non-org !) meta-data to a Notebook (not cell !)

Thank you again for the great software : I am very happy to use it to generate runnable Notebooks from org files .
Your assistance in my last issue was very helpful !

However, I now wish to not only generate a Rise presentation (which I already do, but have it launch automatically on start-up, which would require adding the "rise": {"autolaunch": true} metadata to the notebook.
I could see how to add "org" metadata to a notebook, or any metadata to cells, but I I could not see how to add non-org (i.e. "rise") metadata to the Notebook. Am I being dense again or is it not (yet !) possible / documented ?

Again, thank you so much for enabling me to use emacs for writing Notebooks !

Best Regards.

[enhancement] `ox-ipynb-get-language` should warn when language is not in `ox-ipynb-kernelspecs`

I have met the issue #42 and I think ox-ipynb-get-language should at least warn when the result does not match any of ox-ipynb-kernelspecs such that the user will know what is wrong.

This is because it is not immediately clear whether the issue on jupyter, the org file, or ox-ipynb.

Something like this:

(defun ox-ipynb-get-language ()
  (let ((lang
         (intern
          (or (cdr
               (assoc
                "OX-IPYNB-LANGUAGE"
                (org-element-map
                 (org-element-parse-buffer) 'keyword
                 (lambda (key)
                   (cons
                    (org-element-property :key key)
                    (org-element-property :value key))))))
              (org-element-map
               (org-element-parse-buffer) 'src-block
               (lambda (src)
                 (unless (string=
                          "none"
                          (cdr
                           (assq
                            :exports
                            (org-babel-parse-header-arguments
                             (org-element-property
                              :parameters src)))))
                   (org-element-property :language src)))
               nil t)
              "ipython"))))

    (progn
      (unless (member lang (mapcar #'car ox-ipynb-kernelspecs))
        (display-warning
         'ox-ipynb
         (format "Language \"%s\" not defined in ox-ipynb-kernelspecs."
                 lang)
         :warning))
      lang)))

Or maybe it should fail.

This should be clearer that the problem is on the config of ox-ipynb, thus reducing the amount of time needed to debug and search online until they found issue #42.

Citations & Bibliography?

The error I get is:

user-error: Unable to resolve link: "2018d"

I have bibliography links in buffer:

bibliographystyle:IEEEabrv
bibliography:4P03FFT.bib

The file does exist and the citation link works. HTML, Latex exports work.

Export error. s-slice-at: Args out of range: "", 1

Hi, I am using Emacs 25.2 on Mac OS X 10.12. First of all thank you for making this great library. I was really waiting for this functionality. But I have some issue.

In my simple org file, I have

#+BEGIN_SRC ipython :session 
  a = 1
  a
#+END_SRC

I use C-c e followed by n n to export to notebook. Then I get the following error.

-slice-at: Args out of range: "", 1

Could you help me sort this out?

Towards org mode in Jupytext?

Hello @jkitchin , thanks for the org mode converter!

I recently released Jupytext, a two-way converter between text and Jupyter notebooks. One of the first suggestion I got on the day of the announcement was... to support org mode, cf. mwouts/jupytext#62!

I see that you've gone pretty far in supporting not only code cells, but also text formatting. Do you think it would be feasible to implement the opposite conversion? Would you be interested in contributing a sample (and simple) org mode file to our project? Also, if you had suggestions on how to best represent the notebook metadata, and cell metadata in the org file, please let us know.

Export scope not respected

The export dispatcher allows one to export either the entire buffer or a subtree by setting "Export scope".

ox-ipynb doesn't seem to respect this, and instead just exports the entire buffer?

One work-flow for me involves putting all my lecture notes into a single file, with a top-level headline for each lecture. It would be very convenient to be able to set the relevant scope from the dispatch buffer.

Thanks for considering!

jupyter doesn't like metadata provided by ox-ipynb, prevents notebooks from loading

Get the below error when trying to open an exported notebook

image

Adding the metatdata section from a working notebook gets it to open

ox-ipynb

  "metadata": [
    [
      "org"
    ],
    null,
    null
  ],

working notebook

  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.7"
    }
  },

env

─➛ jupyter --version                                                                                                                                                                                                    11:31PM 28-10-2021
Selected Jupyter core packages...
IPython          : 7.28.0
ipykernel        : 6.4.1
ipywidgets       : 7.6.5
jupyter_client   : 7.0.6
jupyter_core     : 4.8.1
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.5.4
nbconvert        : 6.2.0
nbformat         : 5.1.3
notebook         : 6.4.4
qtconsole        : not installed
traitlets        : 5.1.0

emacs  --version
GNU Emacs 27.2

Exporting Org-tables does not produce table head separators

Dear John,

I ran into the following unexpected behavior while exporting some Org-Tables.

Exporting the following table:

| column-a | column-b | |----------+----------| | test1 | test2 | | test3 | test4 |

produces the following MarkDown Code:

| column-a|column-b| | test1|test2| | test3|test4|

Since the table head separator is missing, the table is not rendered properly in Jupyter Notebook.

prevent export of ditaa src-code blocks?

If my org file contains a ditaa source block, e.g.,

#+BEGIN_SRC ditaa :file img.png
--->
#+END_SRC

and I export this file to notebook format,
the resulting notebook will not open. Is there a way to work around this limitation?

(require 's) (require 'json)

(Submitted as a comment to a closed issue, but figured it was worth raising.)

Hi, I am running emacs version 25.3.2 on Ubuntu Linux 16.

I get told that "Symbol's function definition is void: s-slice-at". It turns out that 's-slice-at emacs' is not a good Google search term.

"M-x describe-package s" just prompts me to keep typing (there are many packages that begin with 's', but none in my configuration named simply 's', it seems).

So, I installed melpa, figured out how to find and install the s package, restarted emacs, executed a (require 's), and am told: that 'json-encode' is undefined. Google for 'json-encode emacs' sends me here: https://www.emacswiki.org/emacs/JSON, which says json.el is built-in, so, I think you need to add:

(require 's)
(require 'json)

to ox-ipynb.el

Thanks! I'm looking forward to using this package!

export of example code fails with wrong number of arguments

Hi there,

I am trying to set up ox-ipynb on my computer. However, whenever I run the export of the example document, I get an error (see below). Note, I did add ob-ipython, but I did not install a local juypter server. I assume that this errors is caused by a botched emacs installation and would be grateful for some pointers on how debug this (I am no lisp programmer though)

Thank you so much

Uli

Debugger entered--Lisp error: (wrong-number-of-arguments (0 . 0) 1)
org-get-tags(98)
(-intersection (org-get-tags (org-element-property :begin hl)) exclude-tags)
(if (-intersection (org-get-tags (org-element-property :begin hl)) exclude-tags) (progn hl))
(closure ((exclude-tags "noexport") (--buf-copy . #<buffer example.org<2>>) t) (hl) (if (-intersection (org-get-tags (org-element-property :begin hl)) exclude-tags) (progn hl)))((headline (:raw-value "Introduction" :begin 98 :end 3402 :pre-blank 1 :contents-begin 114 :contents-end 3401 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 98 :title (#("Introduction" 0 12 (:parent (headline (:raw-value "Introduction" :begin 98 :end 3402 :pre-blank 1 :contents-begin 114 :contents-end 3401 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 98 :title (#0) :parent (org-data nil (section (:begin 1 :end 98 :contents-begin 1 :contents-end 97 :post-blank 1 :post-affiliated 1 :parent #4) (keyword (:key "TITLE" :value "Example of org to ipynb" :begin 1 :end 34 :post-blank 0 :post-affiliated 1 :parent #5)) (keyword (:key "AUTHOR" :value "John Kitchin" :begin 34 :end 58 :post-blank 1 :post-affiliated 34 :parent #5)) (keyword (:key "OX-IPYNB-KEYWORD-METADATA" :value "key1 key2" :begin 58 :end 97 :post-blank 0 :post-affiliated 58 :parent #5))) #2)) (section (:begin 114 :end 585 :contents-begin 114 :contents-end 584 :post-blank 1 :post-affiliated 114 :parent #2) (paragraph (:begin 114 :end 368 :contents-begin 114 :contents-end 367 :post-blank 1 :post-affiliated 114 :parent #3) #("I wrote this module to allow me to write lecture notes in org-mode, but export them to ipython notebooks for my students. It also makes it easier to share my w

compile error: ‘add-to-list’ can’t use lexical var ‘output-cells’

This is the error message that I get when compiling ox-ipynb.el using emacs 25.2.1:

In ox-ipynb-export-code-cell:
ox-ipynb.el:107:13:Error: ‘add-to-list’ can’t use lexical var ‘output-cells’;
    use ‘push’ or ‘cl-pushnew’
ox-ipynb.el:158:13:Error: ‘add-to-list’ can’t use lexical var ‘output-cells’;
    use ‘push’ or ‘cl-pushnew’
ox-ipynb.el:155:13:Error: ‘add-to-list’ can’t use lexical var ‘output-cells’;
    use ‘push’ or ‘cl-pushnew’

Support custom cell-level metadata

I am not sure if this already supports this, my attempts at reading the source did not enlighten me.

I would very much like to be able to add metadata to individual cells, mainly code blocks, so that I can do extra post-processing on the notebook once I have exported it. Is this something you think is possible?

Thanks

Possible bug not respecting org-mode "exclude tags" in the exporter

Thanks for developing such a great jupyter notebook exporter from org-mode. I tend to generate both jupyter notebooks and latex (also beamer) files from a single org-mode source file which sometimes requires me to use tags to selectively choose which parts of the org-mode file gets exported to the jupyter notebook and latex/pdf file, respectively. In the system I have set up I use two different tags: noexport for org-mode blocks which should never be exported regardless of the export format and beamer for org-mode blocks which should not appear in jupyter notebooks. The issue that I have come across is that when including the following preamble in org-mode and exporting to a notebook, I seem to get an error.

#+TAGS: noexport(n) beamer(b)
# ' Comment this out to get Beamer only
# '+EXCLUDE_TAGS: beamer

The error backtrace that I get when I call the ox-ipynb exporter (toggle-debug-on-error is enabled in emacs) is appended at the end of this post describing the issue. However, by enabling the org-mode line above, #+EXCLUDE_TAG: beamer, (i.e. uncommenting this line) then the error disappears and ox-ipynb export works perfectly again. Could this possibly be a bug which is fixable in ox-ipynb or is this related to the discussion in issue #15 where ox-ipynb is referred to as not a "regular kind of exporter" not supporting the things the usual ones do? Would be interested in hearing your thoughts regardless and still a great package.

Debugger entered--Lisp error: (args-out-of-range #<buffer L04.org<2>> 28837 29106)
cl--set-buffer-substring(28837 29106 "")

(let* ((v (org-element-property :begin hl)) (v (org-element-property :end hl))) (cl--set-buffer-substring v v ""))

(while (consp --cl-var--) (setq hl (car --cl-var--)) (let* ((v (org-element-property :begin hl)) (v (org-element-property :end hl))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--)))

(let* ((--cl-var-- (reverse (org-element-map (org-element-parse-buffer) 'headline #'(lambda (hl) (if ... ...))))) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* ((v (org-element-property :begin hl)) (v (org-element-property :end hl))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil)

(let ((exclude-tags (or (plist-get (org-export--get-inbuffer-options) :exclude-tags) org-export-exclude-tags))) (let* ((--cl-var-- (reverse (org-element-map (org-element-parse-buffer) 'headline #'(lambda ... ...)))) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* ((v (org-element-property :begin hl)) (v (org-element-property :end hl))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil))

(progn (let ((exclude-tags (or (plist-get (org-export--get-inbuffer-options) :exclude-tags) org-export-exclude-tags))) (let* ((--cl-var-- (reverse (org-element-map (org-element-parse-buffer) 'headline #'...))) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* ((v (org-element-property :begin hl)) (v (org-element-property :end hl))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil)) (let* ((select-tags (or (plist-get (org-export--get-inbuffer-options) :select-tags) org-export-select-tags)) (found nil) (hls (reverse (org-element-map (org-element-parse-buffer) 'headline #'(lambda ... ... ...))))) (if found (progn (let* ((--cl-var-- hls) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* (... ...) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil)))) (let* ((--cl-var-- (reverse (org-element-map (org-element-parse-buffer) 'src-block #'(lambda ... ...)))) (src nil)) (while (consp --cl-var--) (setq src (car --cl-var--)) (goto-char (org-element-property :begin src)) (org-babel-remove-result) (let* ((v (org-element-property :begin src)) (v (org-element-property :end src))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((--cl-var-- ox-ipynb-preprocess-hook) (func nil)) (while (consp --cl-var--) (setq func (car --cl-var--)) (funcall func) (setq --cl-var-- (cdr --cl-var--))) nil) (let ((data (ox-ipynb-export-to-buffer-data)) (ipynb (ox-ipynb-notebook-filename))) (save-current-buffer (set-buffer (get-buffer-create "*ox-ipynb*")) (erase-buffer) (insert (json-encode data))) (switch-to-buffer "*ox-ipynb*") (set (make-local-variable 'export-file-name) ipynb) (get-buffer "*ox-ipynb*")))

(save-current-buffer (set-buffer --buf-copy) (goto-char (point-min)) (progn (let ((exclude-tags (or (plist-get (org-export--get-inbuffer-options) :exclude-tags) org-export-exclude-tags))) (let* ((--cl-var-- (reverse (org-element-map ... ... ...))) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* ((v ...) (v ...)) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil)) (let* ((select-tags (or (plist-get (org-export--get-inbuffer-options) :select-tags) org-export-select-tags)) (found nil) (hls (reverse (org-element-map (org-element-parse-buffer) 'headline #'...)))) (if found (progn (let* ((--cl-var-- hls) (hl nil)) (while (consp --cl-var--) (setq hl ...) (let* ... ...) (setq --cl-var-- ...)) nil)))) (let* ((--cl-var-- (reverse (org-element-map (org-element-parse-buffer) 'src-block #'...))) (src nil)) (while (consp --cl-var--) (setq src (car --cl-var--)) (goto-char (org-element-property :begin src)) (org-babel-remove-result) (let* ((v (org-element-property :begin src)) (v (org-element-property :end src))) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((--cl-var-- ox-ipynb-preprocess-hook) (func nil)) (while (consp --cl-var--) (setq func (car --cl-var--)) (funcall func) (setq --cl-var-- (cdr --cl-var--))) nil) (let ((data (ox-ipynb-export-to-buffer-data)) (ipynb (ox-ipynb-notebook-filename))) (save-current-buffer (set-buffer (get-buffer-create "*ox-ipynb*")) (erase-buffer) (insert (json-encode data))) (switch-to-buffer "*ox-ipynb*") (set (make-local-variable 'export-file-name) ipynb) (get-buffer "*ox-ipynb*"))))

(unwind-protect (save-current-buffer (set-buffer --buf-copy) (goto-char (point-min)) (progn (let ((exclude-tags (or (plist-get ... :exclude-tags) org-export-exclude-tags))) (let* ((--cl-var-- (reverse ...)) (hl nil)) (while (consp --cl-var--) (setq hl (car --cl-var--)) (let* (... ...) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil)) (let* ((select-tags (or (plist-get ... :select-tags) org-export-select-tags)) (found nil) (hls (reverse (org-element-map ... ... ...)))) (if found (progn (let* (... ...) (while ... ... ... ...) nil)))) (let* ((--cl-var-- (reverse (org-element-map ... ... ...))) (src nil)) (while (consp --cl-var--) (setq src (car --cl-var--)) (goto-char (org-element-property :begin src)) (org-babel-remove-result) (let* ((v ...) (v ...)) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((--cl-var-- ox-ipynb-preprocess-hook) (func nil)) (while (consp --cl-var--) (setq func (car --cl-var--)) (funcall func) (setq --cl-var-- (cdr --cl-var--))) nil) (let ((data (ox-ipynb-export-to-buffer-data)) (ipynb (ox-ipynb-notebook-filename))) (save-current-buffer (set-buffer (get-buffer-create "*ox-ipynb*")) (erase-buffer) (insert (json-encode data))) (switch-to-buffer "*ox-ipynb*") (set (make-local-variable 'export-file-name) ipynb) (get-buffer "*ox-ipynb*")))) (and (buffer-live-p --buf-copy) (progn (save-current-buffer (set-buffer --buf-copy) (restore-buffer-modified-p nil)) (kill-buffer --buf-copy))))

(let ((--buf-copy (org-export-copy-buffer))) (unwind-protect (save-current-buffer (set-buffer --buf-copy) (goto-char (point-min)) (progn (let ((exclude-tags (or ... org-export-exclude-tags))) (let* ((--cl-var-- ...) (hl nil)) (while (consp --cl-var--) (setq hl ...) (let* ... ...) (setq --cl-var-- ...)) nil)) (let* ((select-tags (or ... org-export-select-tags)) (found nil) (hls (reverse ...))) (if found (progn (let* ... ... nil)))) (let* ((--cl-var-- (reverse ...)) (src nil)) (while (consp --cl-var--) (setq src (car --cl-var--)) (goto-char (org-element-property :begin src)) (org-babel-remove-result) (let* (... ...) (cl--set-buffer-substring v v "")) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((--cl-var-- ox-ipynb-preprocess-hook) (func nil)) (while (consp --cl-var--) (setq func (car --cl-var--)) (funcall func) (setq --cl-var-- (cdr --cl-var--))) nil) (let ((data (ox-ipynb-export-to-buffer-data)) (ipynb (ox-ipynb-notebook-filename))) (save-current-buffer (set-buffer (get-buffer-create "*ox-ipynb*")) (erase-buffer) (insert (json-encode data))) (switch-to-buffer "*ox-ipynb*") (set (make-local-variable 'export-file-name) ipynb) (get-buffer "*ox-ipynb*")))) (and (buffer-live-p --buf-copy) (progn (save-current-buffer
(set-buffer --buf-copy) (restore-buffer-modified-p nil)) (kill-buffer --buf-copy)))))

ox-ipynb-export-to-buffer()

(setq buf (ox-ipynb-export-to-buffer))

(let ((ipynb (ox-ipynb-notebook-filename)) (content (buffer-string)) buf) (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert content) (org-mode) (set (make-local-variable 'export-file-name) ipynb) (let ((links ...)) (let* (... ...) (while ... ... ... ...) nil)) (let ((bib-entries ...)) (let* (... ...) (while ... ... ... ...) nil))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (setq buf (ox-ipynb-export-to-buffer)) (save-current-buffer (set-buffer buf) (set (make-local-variable 'export-file-name) ipynb)) buf)

ox-ipynb-export-to-ipynb-buffer(nil nil nil nil nil)

(set-buffer (ox-ipynb-export-to-ipynb-buffer async subtreep visible-only body-only info))

(save-current-buffer (set-buffer (ox-ipynb-export-to-ipynb-buffer async subtreep visible-only body-only info)) (let* ((efn export-file-name) (buf (find-file-noselect efn))) (write-file efn) (save-current-buffer (set-buffer buf) (set (make-local-variable 'export-file-name) efn)) (kill-buffer buf) efn))

ox-ipynb-export-to-ipynb-file(nil nil nil nil)

org-export-dispatch(nil)

funcall-interactively(org-export-dispatch nil)

call-interactively(org-export-dispatch record nil)

command-execute(org-export-dispatch record)

execute-extended-command(nil "org-export-dispatch")

smex-read-and-run(("toggle-debug-on-error" "org-export-dispatch" "org-version" "package-list-packages" "cd" "5x5" "arp" "dbx" "dig" "erc" "ert" "eww" "ftp" "gdb" "irc" "jdb" "man" "mpc" "pdb" "pwd" "rsh" "sdb" "xdb" "calc" "diff" "dirs" "ffap" "gnus" "grep" "help" "ielm" "info" "life" "mail" "mpuz" "ping" "pong" "smex" "talk" "term" "undo" "yank" "zone" "align" "chmod" "debug" "diary" "dired" "ediff" "edirs" ...))

smex()

funcall-interactively(smex)

call-interactively(smex nil nil)

command-execute(smex)

Null metadata prevents notebooks from loading

This is possibly related to #42, except I have already installed jupyter_console and jupyter_client.

I get the below error when trying to open an exported notebook:

image

I was trying to export the example.org file in the repo, with the exception that I removed the internal link (otherwise emacs says its unable to resolve the link and won't export).

Each of the cells has "metadata": null. I don't know much about the Jupyter format, but I guessed that {} might work instead of null and indeed changing all of those allowed the notebook to load.

env

$ jupyter --version
Selected Jupyter core packages...
IPython          : 7.26.0
ipykernel        : 6.15.1
ipywidgets       : 7.6.3
jupyter_client   : 7.3.4
jupyter_core     : 4.11.1
jupyter_server   : 1.10.2
jupyterlab       : 3.1.2
nbclient         : 0.5.3
nbconvert        : 6.1.0
nbformat         : 5.1.3
notebook         : 6.4.0
qtconsole        : not installed
traitlets        : 5.3.0

$ emacs --version
GNU Emacs 26.3

Org mode version 9.5.4 (9.5.4-ge0b05b @ /home/rob/.emacs.d/elpa/org-9.5.4/)

[feature] export subtree

When using ox-ipynb with the org-mode dispatcher and selecting "Export scope: subtree" the setting is not used by ox-ipynb, i.e. the whole file gets exported regardless.

Do you plan or are you open to support subtree export?

Possible bug: Table of contents not displayed

I am trying to generate the table of contents of my notebook when exporting it. I use the following in-buffer setting:
#+OPTIONS: toc:2

However, the exported .ipynb file only contains a header "Table of Contents" without any contents below.
The setting #+OPTIONS: toc:t gives the same result.

Are table of contents even supported by ox-ipynb?

I tried with the following minimal example:

#+OPTIONS: toc:2

* Headline 1
#+BEGIN_SRC ipython :results output drawer
  print("A block under Headline 1.")
#+END_SRC

#+RESULTS:
:results:
A block under Headline 1.
:end:

** Subheadline 1
 #+BEGIN_SRC ipython :results output drawer
   print("A block under Subheadline 1.")
 #+END_SRC

 #+RESULTS:
 :results:
 A block under Subheadline 1.
 :end:

** Subheadline 2
 #+BEGIN_SRC ipython :results output drawer
   print("A block under Subheadline 2.")
 #+END_SRC

 #+RESULTS:
 :results:
 A block under Subheadline 2.
 :end:

* Headline 2
#+BEGIN_SRC ipython :results output drawer
  print("A block under Headline 2.")
#+END_SRC

#+RESULTS:
:results:
A block under Headline 2.
:end:

rendering of table with vertical lines

Hi John,

the following table


| 100-999 | 10-99 | 0-9 | Name        |
|---------+-------+-----+-------------|
|       / |     < |   < | <           |
|         |       |   . | .           |
|---------+-------+-----+-------------|
|         |       |   . | .           |
|---------+-------+-----+-------------|
|         |       |   8 | eight       |

renders ok in pdf format, but the export to notebook format creates spurious rows and columns for the vertical and horizontal separators. Assuming that there is no easy translation, could they simply be ignored for notebook export?

Cheers

Uli

#+begin_export latex is not exported

Whenever I need a pure \LaTeX environment, I'm used to use it with

#+begin_export latex
<...>
#+end_export, 

as I can freely move to an org-src-mode window, allowing auctex keybindings, yasnippets snippets and such. However, if I export an org file to ipynb with these export blocks, they get supressed from the output. Is there a workaround (other than removing those block headers)? Thanks.

ox-ipynb.el is missing a (require 'dash) ?

At least adding the line
(require 'dash)
stopped ox-ipynb from complaining about missing -sequence and -constains?
(btw, searching for the latter string is really painful on search engines :-/)

Thanks for the package which will save me from using emacs-ipython-notebook.

Thomas

Export of citation fails

Exporting a org-mode document to ipynb fails with the following error message: Unable to resolve link "citeproc_bib_item_1"

I have an org-mode document with citations and jupyter-python code blocks that I wish to export to html, latex and ipynb. Export to html and latex works fine and is used routinely. Now the export to ipynb is new and is not working perfectly. My procedure is as follows: I have first exported the org document to org via org-ref as I always do for html export and get something like is shown below. Then I either use the usual html exporter which works fine or the ipynb exporter.

First the original document:
#+title: PyTorch Test
#+category: PyTorch Test

#+include: ../../OptionsPreamble.org
#+include: ../../LatexPreamble.org
#+include: ../../HtmlPreamble.org
#+include: ../../ThemeDakrone.org

#+startup: inlineimages
#+property: header-args:jupyter-python :session jupyter-python-3a884c28cceba85e17d10f6dce2d8df7

  • Description
    Learning the basics of PyTorch[[cite:&PyTorch]].

#+begin_src jupyter-python
print("Hello")
#+end_src

#+RESULTS:
:RESULTS:
Hello
:END:

  • Bibliography

#+csl-style: apa-numeric-superscript-brackets.csl
#+csl-locale: en-US

#+begin_export org
bibliographystyle:apacite
#+end_export
bibliography:../../../bibliography/bibliography.bib

Secondly, the temporary buffer after using org-ref export to Org buffer

#+title: PyTorch Test
#+category: PyTorch Test

#+latex_class: apa7
#+latex_class_options: [a4paper, biblatex]

#+latex_header: \usepackage{physics,amsmath}
...

#+startup: inlineimages
#+property: header-args:jupyter-python :session jupyter-python-3a884c28cceba85e17d10f6dce2d8df7

  • Description

Learning the basics of PyTorch^{[[[citeproc_bib_item_1][1]]]}.

#+begin_src jupyter-python
print("Hello")
#+end_src

  • Bibliography

#+csl-style: apa-numeric-superscript-brackets.csl
#+csl-locale: en-US

bibliographystyle:apacite
<<citeproc_bib_item_1>>1. PyTorch contributors. (2022). /PyTorch - An open source machine learning framework that accelerates the path from research prototyping to production deployment./ https://pytorch.org/

When I now export this temporary buffer with ox-ipynb I get the error message. Do I something wrong or is this expected/known behavior?

An additional problem that I have with the export to the temporary buffer is that the org-babel result section is missing. Is there a simple solution?

Any help is appreciated.

#+TOC: headlines 1 causes notebook export failure

Hi John,

the following example:

#+TOC: headlines 1

some text

fails with

funcall: Symbol’s function definition is void: ox-ipynb-keyword-link

This is on a new install, GNU Emacs 26.3 (build 1, x86_64-suse-linux-gnu, GTK+ Version 3.24.20), Org 9.4

Ignore `:exports none`

I frequently use the header argument :exports none for code blocks that I don't want to be exported to LaTeX:

#+begin_src jupyter-python :exports none
import numpy as np
#+end_src

But now I face the issue that these bocks are not even exported to ipynb, though they are crucial for running the notebook.

Is it possible to ignore :exports none during export to ipynb?

wrong-type-argument listp when exporting example file

I'm trying to get this to work, but am running into issues with the example file.

I have this in my init.el:

(load-file "~/.emacs.d/external/ox-ipynb/ox-ipynb.el")
(require 'ox-ipynb)

Now, when I open the example.org file and press C-c C-e n b, I get the following error:

Debugger entered--Lisp error: (wrong-type-argument listp #("John Kitchin" 0 12 (:parent (#1))))
  org-element-set-contents(#("John Kitchin" 0 12 (:parent (#0))))
  apply(org-element-set-contents #("John Kitchin" 0 12 (:parent (#0))) nil)
  #[257 "\211\305\306\307�#��\310\311�\211�:\204��\312\202\"�\n@9\203!�\nAA\202\"�\n)\"\210\313\314	�\211�:\2043�\312\202@�\n@9\203?�\nAA\202@�\n)#\210�\315\211	��\n;\203V�\316\317�\n#\202\\�\320\nA@�\"*��\211�;\203n�\321\n\312�\f$\202z�\nA\322\nA@�\f#\240\210\n+\210	A�A@\240\210	�@\240*\207" [new old element property value replace-regexp-in-string "\n" " " mapc #[(blob) "�\305	��\211�;\203��\306\f\307�\n$\202 �\fA\310\fA@�\n#\240\210\f+\207" [blob old value property element :parent org-add-props nil plist-put] 6] nil apply org-element-set-contents :parent get-text-property 0 plist-get org-add-props plist-put] 7 "\n\n(fn S)"](#("John Kitchin" 0 12 (:parent (#0))))
  #[257 "\211\211:\204��\211;\205��\311\262�\202��\211@9\205��\211@\262��?\206��\301\203-��\312\301\313\">\206��\211\2049�\314\310\242�\"\202��\211\315=\203]�\314\310\242�\211:\204N�\316\262�\202Y�\211@9\203Y�\211AA\262�\"\202��\211\304>\203~�\300�!\211\203}�\302\203v�\317\320�\"\210\202}�\307�\307\242B\240\210\210\306\321=\203\271��;\204\271�\211��\236A\211\203\270�\211@\310\242��\211;\203\247�\322\323��#\266\202\202\257�\312�A@�\"\266\202!\210�A\266\202\202\216�\210\303\203\377�\306\321=\203\377��\316�\211:\204\326�\211;\205\336�\311\262�\202\340�\211@9\205\336�\211@\262��\206\375�\324�\211;\203\365�\322\323��#\266\202\202\375�\312�A@�\"\266\202���>\203��\325\202r����>\203��\326\202r��\315=\203��\326\202r��\311=\203'�\325\202r��\204/�\325\202r�\211\2047�\326\202r�\211\211:\204H�\211;\205P�\311\262�\202R�\211@9\205P�\211@\262�\211\204Z�\325\202p�\211��>\203e�\325\202p�\327�!\203o�\325\202p�\326\262�\266\204\326=\203\377���\211\203\376�\211@\211@�A�\211;\203\225�\322\323��#\266\202\202\235�\312�A@�\"\266\202\211\203\365��� \235\203\336���!\235\203\317�\330�!\211\203\313�\211@\310\242�A!\210\310\242�@!\210�A\266\202\202\262�\210\202\365�\310\242�A!\210\310\242�@!\210\202\365���!\235\203\360�\314\310\242\330�!\"\210\202\365�\310\242�!\210\266��A\266\202\202{�\210\211\305>\206���\211:\204��\316\262�\202��\211@9\203��\211AA\262�?\206��\306\331=\203.�\211�\">?\206��\306\332=\203\352��\316�\211:\204G�\211;\205O�\311\262�\202Q�\211@9\205O�\211@\262��\206n�\324�\211;\203f�\322\323��#\266\202\202n�\312�A@�\"\266\202���>\203y�\325\202\343����>\203\204�\326\202\343��\315=\203\216�\326\202\343��\311=\203\230�\325\202\343��\204\240�\325\202\343�\211\204\250�\326\202\343�\211\211:\204\271�\211;\205\301�\311\262�\202\303�\211@9\205\301�\211@\262�\211\204\313�\325\202\341�\211��>\203\326�\325\202\341�\327�!\203\340�\325\202\341�\326\262�\266\204\325=\206��\314\310\242�\211:\204\371�\316\262�\202��\211@9\203��\211AA\262�\"\207" [#[257 "\211\305\306\307�#��\310\311�\211�:\204��\312\202\"�\n@9\203!�\nAA\202\"�\n)\"\210\313\314	�\211�:\2043�\312\202@�\n@9\203?�\nAA\202@�\n)#\210�\315\211	��\n;\203V�\316\317�\n#\202\\�\320\nA@�\"*��\211�;\203n�\321\n\312�\f$\202z�\nA\322\nA@�\f#\240\210\n+\210	A�A@\240\210	�@\240*\207" [new old element property value replace-regexp-in-string "\n" " " mapc #[(blob) "�\305	��\211�;\203��\306\f\307�\n$\202 �\fA\310\fA@�\n#\240\210\f+\207" [blob old value property element :parent org-add-props nil plist-put] 6] nil apply org-element-set-contents :parent get-text-property 0 plist-get org-add-props plist-put] 7 "\n\n(fn S)"] nil nil nil (plain-text) nil objects (nil) (#0) plain-text plist-get :ignore-list mapc org-data nil throw :--map-first-match objects get-text-property 0 :parent object element org-element-secondary-p reverse greater-elements elements org-element-secondary-value-alist org-element-all-objects org-element-all-elements org-element-object-containers org-element--parsed-properties-alist org-element-dual-keywords org-element-multiple-keywords org-element-greater-elements] 11 "\n\n(fn --DATA)"](#("John Kitchin" 0 12 (:parent (#0))))
  mapc(#[257 "\211\211:\204��\211;\205��\311\262�\202��\211@9\205��\211@\262��?\206��\301\203-��\312\301\313\">\206��\211\2049�\314\310\242�\"\202��\211\315=\203]�\314\310\242�\211:\204N�\316\262�\202Y�\211@9\203Y�\211AA\262�\"\202��\211\304>\203~�\300�!\211\203}�\302\203v�\317\320�\"\210\202}�\307�\307\242B\240\210\210\306\321=\203\271��;\204\271�\211��\236A\211\203\270�\211@\310\242��\211;\203\247�\322\323��#\266\202\202\257�\312�A@�\"\266\202!\210�A\266\202\202\216�\210\303\203\377�\306\321=\203\377��\316�\211:\204\326�\211;\205\336�\311\262�\202\340�\211@9\205\336�\211@\262��\206\375�\324�\211;\203\365�\322\323��#\266\202\202\375�\312�A@�\"\266\202���>\203��\325\202r����>\203��\326\202r��\315=\203��\326\202r��\311=\203'�\325\202r��\204/�\325\202r�\211\2047�\326\202r�\211\211:\204H�\211;\205P�\311\262�\202R�\211@9\205P�\211@\262�\211\204Z�\325\202p�\211��>\203e�\325\202p�\327�!\203o�\325\202p�\326\262�\266\204\326=\203\377���\211\203\376�\211@\211@�A�\211;\203\225�\322\323��#\266\202\202\235�\312�A@�\"\266\202\211\203\365��� \235\203\336���!\235\203\317�\330�!\211\203\313�\211@\310\242�A!\210\310\242�@!\210�A\266\202\202\262�\210\202\365�\310\242�A!\210\310\242�@!\210\202\365���!\235\203\360�\314\310\242\330�!\"\210\202\365�\310\242�!\210\266��A\266\202\202{�\210\211\305>\206���\211:\204��\316\262�\202��\211@9\203��\211AA\262�?\206��\306\331=\203.�\211�\">?\206��\306\332=\203\352��\316�\211:\204G�\211;\205O�\311\262�\202Q�\211@9\205O�\211@\262��\206n�\324�\211;\203f�\322\323��#\266\202\202n�\312�A@�\"\266\202���>\203y�\325\202\343����>\203\204�\326\202\343��\315=\203\216�\326\202\343��\311=\203\230�\325\202\343��\204\240�\325\202\343�\211\204\250�\326\202\343�\211\211:\204\271�\211;\205\301�\311\262�\202\303�\211@9\205\301�\211@\262�\211\204\313�\325\202\341�\211��>\203\326�\325\202\341�\327�!\203\340�\325\202\341�\326\262�\266\204\325=\206��\314\310\242�\211:\204\371�\316\262�\202��\211@9\203��\211AA\262�\"\207" [#[257 "\211\305\306\307�#��\310\311�\211�:\204��\312\202\"�\n@9\203!�\nAA\202\"�\n)\"\210\313\314	�\211�:\2043�\312\202@�\n@9\203?�\nAA\202@�\n)#\210�\315\211	��\n;\203V�\316\317�\n#\202\\�\320\nA@�\"*��\211�;\203n�\321\n\312�\f$\202z�\nA\322\nA@�\f#\240\210\n+\210	A�A@\240\210	�@\240*\207" [new old element property value replace-regexp-in-string "\n" " " mapc #[(blob) "�\305	��\211�;\203��\306\f\307�\n$\202 �\fA\310\fA@�\n#\240\210\f+\207" [blob old value property element :parent org-add-props nil plist-put] 6] nil apply org-element-set-contents :parent get-text-property 0 plist-get org-add-props plist-put] 7 "\n\n(fn S)"] nil nil nil (plain-text) nil objects (nil) (#0) plain-text plist-get :ignore-list mapc org-data nil throw :--map-first-match objects get-text-property 0 :parent object element org-element-secondary-p reverse greater-elements elements org-element-secondary-value-alist org-element-all-objects org-element-all-elements org-element-object-containers org-element--parsed-properties-alist org-element-dual-keywords org-element-multiple-keywords org-element-greater-elements] 11 "\n\n(fn --DATA)"] (#("John Kitchin" 0 12 (:parent #0))))
  #[257 "\211\211:\204��\211;\205��\311\262�\202��\211@9\205��\211@\262��?\206��\301\203-��\312\301\313\">\206��\211\2049�\314\310\242�\"\202��\211\315=\203]�\314\310\242�\211:\204N�\316\262�\202Y�\211@9\203Y�\211AA\262�\"\202��\211\304>\203~�\300�!\211\203}�\302\203v�\317\320�\"\210\202}�\307�\307\242B\240\210\210\306\321=\203\271��;\204\271�\211��\236A\211\203\270�\211@\310\242��\211;\203\247�\322\323��#\266\202\202\257�\312�A@�\"\266\202!\210�A\266\202\202\216�\210\303\203\377�\306\321=\203\377��\316�\211:\204\326�\211;\205\336�\311\262�\202\340�\211@9\205\336�\211@\262��\206\375�\324�\211;\203\365�\322\323��#\266\202\202\375�\312�A@�\"\266\202���>\203��\325\202r����>\203��\326\202r��\315=\203��\326\202r��\311=\203'�\325\202r��\204/�\325\202r�\211\2047�\326\202r�\211\211:\204H�\211;\205P�\311\262�\202R�\211@9\205P�\211@\262�\211\204Z�\325\202p�\211��>\203e�\325\202p�\327�!\203o�\325\202p�\326\262�\266\204\326=\203\377���\211\203\376�\211@\211@�A�\211;\203\225�\322\323��#\266\202\202\235�\312�A@�\"\266\202\211\203\365��� \235\203\336���!\235\203\317�\330�!\211\203\313�\211@\310\242�A!\210\310\242�@!\210�A\266\202\202\262�\210\202\365�\310\242�A!\210\310\242�@!\210\202\365���!\235\203\360�\314\310\242\330�!\"\210\202\365�\310\242�!\210\266��A\266\202\202{�\210\211\305>\206���\211:\204��\316\262�\202��\211@9\203��\211AA\262�?\206��\306\331=\203.�\211�\">?\206��\306\332=\203\352��\316�\211:\204G�\211;\205O�\311\262�\202Q�\211@9\205O�\211@\262��\206n�\324�\211;\203f�\322\323��#\266\202\202n�\312�A@�\"\266\202���>\203y�\325\202\343����>\203\204�\326\202\343��\315=\203\216�\326\202\343��\311=\203\230�\325\202\343��\204\240�\325\202\343�\211\204\250�\326\202\343�\211\211:\204\271�\211;\205\301�\311\262�\202\303�\211@9\205\301�\211@\262�\211\204\313�\325\202\341�\211��>\203\326�\325\202\341�\327�!\203\340�\325\202\341�\326\262�\266\204\325=\206��\314\310\242�\211:\204\371�\316\262�\202��\211@9\203��\211AA\262�\"\207" [#[257 "\211\305\306\307�#��\310\311�\211�:\204��\312\202\"�\n@9\203!�\nAA\202\"�\n)\"\210\313\314	�\211�:\2043�\312\202@�\n@9\203?�\nAA\202@�\n)#\210�\315\211	��\n;\203V�\316\317�\n#\202\\�\320\nA@�\"*��\211�;\203n�\321\n\312�\f$\202z�\nA\322\nA@�\f#\240\210\n+\210	A�A@\240\210	�@\240*\207" [new old element property value replace-regexp-in-string "\n" " " mapc #[(blob) "�\305	��\211�;\203��\306\f\307�\n$\202 �\fA\310\fA@�\n#\240\210\f+\207" [blob old value property element :parent org-add-props nil plist-put] 6] nil apply org-element-set-contents :parent get-text-property 0 plist-get org-add-props plist-put] 7 "\n\n(fn S)"] nil nil nil (plain-text) nil objects (nil) (#0) plain-text plist-get :ignore-list mapc org-data nil throw :--map-first-match objects get-text-property 0 :parent object element org-element-secondary-p reverse greater-elements elements org-element-secondary-value-alist org-element-all-objects org-element-all-elements org-element-object-containers org-element--parsed-properties-alist org-element-dual-keywords org-element-multiple-keywords org-element-greater-elements] 11 "\n\n(fn --DATA)"]((#("John Kitchin" 0 12 (:parent #0))))
  org-element-map((#("John Kitchin" 0 12 (:parent #0))) plain-text #[257 "\211\305\306\307�#��\310\311�\211�:\204��\312\202\"�\n@9\203!�\nAA\202\"�\n)\"\210\313\314	�\211�:\2043�\312\202@�\n@9\203?�\nAA\202@�\n)#\210�\315\211	��\n;\203V�\316\317�\n#\202\\�\320\nA@�\"*��\211�;\203n�\321\n\312�\f$\202z�\nA\322\nA@�\f#\240\210\n+\210	A�A@\240\210	�@\240*\207" [new old element property value replace-regexp-in-string "\n" " " mapc #[(blob) "�\305	��\211�;\203��\306\f\307�\n$\202 �\fA\310\fA@�\n#\240\210\f+\207" [blob old value property element :parent org-add-props nil plist-put] 6] nil apply org-element-set-contents :parent get-text-property 0 plist-get org-add-props plist-put] 7 "\n\n(fn S)"])
  org-export--get-inbuffer-options([cl-struct-org-export-backend org nil ((babel-call . org-org-identity) (bold . org-org-identity) (center-block . org-org-identity) (clock . org-org-identity) (code . org-org-identity) (diary-sexp . org-org-identity) (drawer . org-org-identity) (dynamic-block . org-org-identity) (entity . org-org-identity) (example-block . org-org-identity) (export-block . org-org-export-block) (fixed-width . org-org-identity) (footnote-definition . ignore) (footnote-reference . org-org-identity) (headline . org-org-headline) (horizontal-rule . org-org-identity) (inline-babel-call . org-org-identity) (inline-src-block . org-org-identity) (inlinetask . org-org-identity) (italic . org-org-identity) (item . org-org-identity) (keyword . org-org-keyword) (latex-environment . org-org-identity) (latex-fragment . org-org-identity) (line-break . org-org-identity) (link . org-org-link) (node-property . org-org-identity) (template . org-org-template) (paragraph . org-org-identity) (plain-list . org-org-identity) (planning . org-org-identity) (property-drawer . org-org-identity) (quote-block . org-org-identity) (radio-target . org-org-identity) (section . org-org-section) (special-block . org-org-identity) (src-block . org-org-identity) (statistics-cookie . org-org-identity) (strike-through . org-org-identity) (subscript . org-org-identity) (superscript . org-org-identity) (table . org-org-identity) (table-cell . org-org-identity) (table-row . org-org-identity) (target . org-org-identity) (timestamp . org-org-identity) (underline . org-org-identity) (verbatim . org-org-identity) (verse-block . org-org-identity)) nil ((:filter-parse-tree . org-org--add-missing-sections)) nil (79 "Export to Org" ((79 "As Org buffer" org-org-export-as-org) (111 "As Org file" org-org-export-to-org) (118 "As Org file and open" (lambda (a s v b) (if a (org-org-export-to-org t s v b) (org-open-file (org-org-export-to-org nil s v b)))))))])
  org-export-get-environment([cl-struct-org-export-backend org nil ((babel-call . org-org-identity) (bold . org-org-identity) (center-block . org-org-identity) (clock . org-org-identity) (code . org-org-identity) (diary-sexp . org-org-identity) (drawer . org-org-identity) (dynamic-block . org-org-identity) (entity . org-org-identity) (example-block . org-org-identity) (export-block . org-org-export-block) (fixed-width . org-org-identity) (footnote-definition . ignore) (footnote-reference . org-org-identity) (headline . org-org-headline) (horizontal-rule . org-org-identity) (inline-babel-call . org-org-identity) (inline-src-block . org-org-identity) (inlinetask . org-org-identity) (italic . org-org-identity) (item . org-org-identity) (keyword . org-org-keyword) (latex-environment . org-org-identity) (latex-fragment . org-org-identity) (line-break . org-org-identity) (link . org-org-link) (node-property . org-org-identity) (template . org-org-template) (paragraph . org-org-identity) (plain-list . org-org-identity) (planning . org-org-identity) (property-drawer . org-org-identity) (quote-block . org-org-identity) (radio-target . org-org-identity) (section . org-org-section) (special-block . org-org-identity) (src-block . org-org-identity) (statistics-cookie . org-org-identity) (strike-through . org-org-identity) (subscript . org-org-identity) (superscript . org-org-identity) (table . org-org-identity) (table-cell . org-org-identity) (table-row . org-org-identity) (target . org-org-identity) (timestamp . org-org-identity) (underline . org-org-identity) (verbatim . org-org-identity) (verse-block . org-org-identity)) nil ((:filter-parse-tree . org-org--add-missing-sections)) nil (79 "Export to Org" ((79 "As Org buffer" org-org-export-as-org) (111 "As Org file" org-org-export-to-org) (118 "As Org file and open" (lambda (a s v b) (if a (org-org-export-to-org t s v b) (org-open-file (org-org-export-to-org nil s v b)))))))] nil nil)
  org-export-as(org nil nil nil nil)
  org-export-to-buffer(org "*Org ORG Export*" nil nil nil nil nil (closure ((ext-plist) (body-only) (visible-only) (subtreep) (async) htmlize-output-type t) nil (org-mode)))
  org-org-export-as-org(nil nil nil nil nil)
  (let ((ipynb (or (if (boundp (quote export-file-name)) (progn export-file-name)) (concat (file-name-base (buffer-file-name)) ".ipynb"))) buf) (org-org-export-as-org async subtreep visible-only body-only info) (save-current-buffer (set-buffer "*Org ORG Export*") (set (make-local-variable (quote export-file-name)) ipynb) (setq buf (ox-ipynb-export-to-buffer)) (save-current-buffer (set-buffer buf) (set (make-local-variable (quote export-file-name)) ipynb)) (prog1 buf (kill-buffer "*Org ORG Export*"))))
  ox-ipynb-export-to-ipynb-buffer(nil nil nil nil)
  org-export-dispatch(nil)
  funcall-interactively(org-export-dispatch nil)
  call-interactively(org-export-dispatch nil nil)
  command-execute(org-export-dispatch)

Using org-plus-contrib-20171004 with Emacs 25.2.2 on Debian Linux.

I would appreciate any idea how to resolve this.

org headlines cause error

First off, many thanks for building this tool; I'm very excited to use it!

I was unable to export your example.org, so I think I narrowed the problem down to the headlines. A minimal org file with an ipython block exports successfully:

#+BEGIN_SRC ipython 
a = 'test'
a
#+END_SRC

#+RESULTS:
: # Out[11]:
: : 'test'

However, as soon as I add a headline:

* headline
#+BEGIN_SRC ipython 
a = 'test'
a
#+END_SRC

#+RESULTS:
: # Out[11]:
: : 'test'

I get the error: Wrong number of arguments: (0 . 0), 1

The debugger backtrace shows:

Debugger entered--Lisp error: (wrong-number-of-arguments (0 . 0) 1)
  org-get-tags(1)
  #f(compiled-function (hl) #<bytecode 0x43a50b81>)((headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("headline" 0 8 (:parent (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#0) :parent (org-data nil #2)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))) :parent (org-data nil #1)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #1) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #2)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #2)))))
  #f(compiled-function (--data) #<bytecode 0x43a50b8d>)((headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("headline" 0 8 (:parent (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#0) :parent (org-data nil #2)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))) :parent (org-data nil #1)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #1) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #2)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #2)))))
  mapc(#f(compiled-function (--data) #<bytecode 0x43a50b8d>) ((headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("headline" 0 8 (:parent (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#0) :parent (org-data nil #2)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))) :parent (org-data nil . #1)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))
  #f(compiled-function (--data) #<bytecode 0x43a50b8d>)((org-data nil (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("headline" 0 8 (:parent (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#0) :parent (org-data nil #2)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))) :parent #1) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))
  org-element-map((org-data nil (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("headline" 0 8 (:parent (headline (:raw-value "headline" :begin 1 :end 92 :pre-blank 0 :contents-begin 12 :contents-end 92 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#0) :parent (org-data nil #2)) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))))) :parent #1) (section (:begin 12 :end 92 :contents-begin 12 :contents-end 92 :post-blank 0 :post-affiliated 12 :parent #2) (src-block (:language "ipython" :switches nil :parameters nil :begin 12 :end 57 :number-lines nil :preserve-indent nil :retain-labels t :use-labels t :label-fmt nil :value "a = 'test'\na\n" :post-blank 1 :post-affiliated 12 :parent #3)) (fixed-width (:begin 57 :end 92 :value "# Out[11]:\n: 'test'\n" :post-blank 0 :post-affiliated 68 :results ("") :parent #3))))) headline #f(compiled-function (hl) #<bytecode 0x43a50b81>))
  ox-ipynb-export-to-buffer()
  ox-ipynb-export-to-ipynb-buffer(nil nil nil nil nil)
  ox-ipynb-export-to-ipynb-file(nil nil nil nil)
  org-export-dispatch(nil)
  funcall-interactively(org-export-dispatch nil)
  call-interactively(org-export-dispatch nil nil)
  command-execute(org-export-dispatch)

Can ox-ipynb recognize jupyter-python src blocks?

I've been trying out emacs-jupyter as an alternative to ob-ipython with good results. To export to ipynbs, I currently use a hackish ox-ipynb-preprocess-hook to replace all of the
#+BEGIN_SRC jupyter-python
blocks to
#+BEGIN_SRC ipython

Is there a simple way to get ox-ipynb to recognize source blocks with 'jupyter-python' as the language? I was thinking that
#+OX-IPYNB-LANGUAGE: jupyter-python
should work, but ox-ipynb exports a malformed ipynb with no code blocks.

Minimal example:

#+PROPERTY: header-args:jupyter-python :session jpy
#+PROPERTY: header-args :exports both
* A emacs jupyter cell

#+BEGIN_SRC jupyter-python
print("hello")
#+END_SRC

Thanks

Error on basic file

I am trying to get ox-ipynb running but I am running into a error when opening an exported file.
The .org file is simply:

Hello world!
#+BEGIN_SRC python
  print("Hello")
#+END_SRC

I export it using ox-ipynb and when I open the file in jupyter I get the error: Unreadable Notebook: /Users/guilhermesalome/Desktop/test.ipynb TypeError('pop() takes at most 1 argument (2 given)').

Does anyone have any ideas on what could be causing this and how I can fix it?
Thanks! :D

Feature / Documentation request : Generating images with (e.g. ditaa, plantuml) code blocks

Again, thank you so much for scimax and ox-ipynb !
As I want to have a source for my Notebooks, I want to also have the illustrations as source code that can be edited, so I would like to use the org mode source blocks for ditaa , graphviz and plantuml.
However, when I use code blocks with :exports results , ox-ipynb still wants to export a cell with the source as a code cell. Of course, it does not work when loading the notebook.
Would it be possible for the exporter to respect the :exports results and only export the resulting image ?

Best Regards.

Top-level metadata is emitted as a list (should be dict)

When trying to open an ipynb converted with this tool, I encountered this error from Jupyter:

pop() takes at most 1 argument (2 given)

I traced it down to the top-level metadata being emitted as this list:

  "metadata": [
    [
      "org"
    ],
    null,
    null
  ],

Googling around for the error, I saw that the metadata should be a dict. I manually replaced it with:

"metadata": {},

which fixed the error. I can now open my ipynb.

Emacs version 25.3.1
Jupyter version 4.4.0

I used ox-ipynb-export-to-buffer, then saved the resulting buffer as an ipynb.

conditional export?

This harks back to and earlier question and based on jkitchin/scimax#305 is likely not possible. Still, I recently started using notebooks in a class where it would be useful to have a version that the students get to see and version that the TA gets to see (i.e., with solutions and or comments wrt marking).

Drawers come to mind, but conditional drawer inclusion is not supported in the ox-ipynb. I wonder, however whether the is another way (short of using, e.g., a python script) to exclude some content?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.