millejoh / emacs-ipython-notebook

Jupyter notebook client in Emacs
http://millejoh.github.io/emacs-ipython-notebook/
GNU General Public License v3.0
1.47k stars 123 forks source link

[Feature Request] Is there a way to exporte the notebook as emacs-org or generate a notebook from org file? #842

Closed Atreyagaurav closed 2 years ago

Atreyagaurav commented 2 years ago

I don't know if I'm just stupid and couldn't find it, because I feel like this should be there somewhere. But just in case would it be possible to add this feature? I think a lot of people in emacs use org mode, but we also use jupyter notebook to share it with others, and we receive jupyter notebook, which we try things on.

The import org as notebook could probably be unneeded if we have export to notebook from org, but I still think it could be done better from ein side as ein has more information about the kernels so it can ask users which kernel they want to use, and if there are source blocks that are not in the particular language (like when org file has sources of multiple languages) then it can ask which ones to include etc. The org file export from org side can't know those things beforehand.

I'm a beginner in elisp but I'm willing to help on this on brainstorm and coding if someone else can also help with it. I do think it'll be an wonderful feature. Again, that's why I feel like it has already been done.

dickmao commented 2 years ago

I don't know if I'm just stupid and couldn't find it, because I feel like this should be there somewhere

You're not stupid. You just haven't discovered Google yet.

When you do, try searching "export org to ipynb".

Atreyagaurav commented 2 years ago

Why did you close this? Even if there is export to notebook for org, ein still doesn't have export to org feature, so I think my issue is still valid.

dickmao commented 2 years ago

Mebbe summat like:

(use-package ein
  :config (use-package ein-notebook
        :bind (:map ein:notebook-mode-map ("C-c x" . my-export))
        :init (defun my-export ()
                    (interactive)
                    (require 'ox-ipynb)
                    (let ((export-file-name
                           (ein:$notebook-notebook-path (ein:get-notebook))))
                      (ox-ipynb-export-to-ipynb-buffer)))))

You'll have to play around with it.

Atreyagaurav commented 2 years ago

That code snippet looks like it exports org to ipynb. That's not the only thing I'm interested in. Although I'd prefer some way to import from ein instead of export from org since the author mentions this

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.

Which means ein would have a lot easier job to import an org into a already defined kernel. Since it can just copy the text into markdown and code into code cells.

But let's forget that for a sec,

I'm also interested in exporting ipynb to org file.

[Feature Request] Is there a way to exporte the notebook as emacs-org

As mentioned in the title. Jupyter-notebook can export .py, html, and many other formats but not org. So it'd be really nice to add org through ein and also expose the functions for export to other formats like .py and .md in ein (I hope we can just use the function of jupyter notebook for this after just adding some function.)

nakkaya commented 2 years ago

As mentioned in the title. Jupyter-notebook can export .py, html, and many other formats but not org. So it'd be really nice to add org through ein and also expose the functions for export to other formats like .py and .md in ein (I hope we can just use the function of jupyter notebook for this after just adding some function.)

org-mode can export .py/.html/.pdf and much more. You can even tangle a multiple languages together. See org-babel tangle.

dickmao commented 2 years ago

The import org as notebook could probably be unneeded if we have export to notebook from org

I took that sentiment at face value.

How are you doing with discovering Google? If or when you've found it, try "nbconvert org mode".

Atreyagaurav commented 2 years ago

Sorry for the confusion @nakkaya Jupyter notebooks cannot export .org file from the notebook code and markdown. As in make org from ipython. I'm not talking about capability of org to export in different formats.

nakkaya commented 2 years ago

@Atreyagaurav Then you need nbconvert. [1]

[1] https://github.com/jupyter/nbconvert/issues/800

Atreyagaurav commented 2 years ago

@nakkaya

If you read my comment I said this:

So it'd be really nice to add org through ein and also expose the functions for export to other formats like .py and .md in ein (I hope we can just use the function of jupyter notebook for this after just adding some function.)

Yes I can export to them through jupyter. Ein is a emacs interface and hence how is it wrong to expect to call those function through ein?? Like just adding some functions like ein:notebook-export-to-python, ein:notebook-export-to-markdown etc which calls nbconvert internally (I didn't know its name when I commented, but I knew jupyter had something).

@dickmao In the same topic, if installing a dependency allows nbconvert to export notebook to org, then we can just do that through there as long as it's documented.

Though I did try https://pypi.org/project/nbcorg/ from google and it didn't work for me (it throws some exception about jinja).

And I'd really appreciate you sending some links or manual instead of just saying "go search this".