Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Hydrogen, how do I save they python script with output included like a jupyter notebook?

I'm new to Atom and Jupyter. I've only installed Hydrogen and I'm testing on a simple script. I can make some data and, shift+Enter shows the plot inline! I'd like to save the file w/ the output blocks I see in the Atom+Hydrogen GUI. I've seen other Jupyter notebooks like this. Can I do it and how?

like image 786
travelingbones Avatar asked Nov 07 '22 11:11

travelingbones


1 Answers

You can use Pandoctools for this. It can export hydrogen *.py / *.md documents to any Pandoc output format or to Jupyter notebook.

For example you can create and register Jupyter kernel. For example is can be named "nn". That should be the same kernel that you selected in Atom/Hydrogen. Then add hat to the Python file, split Hydrogen to cells, provide settings and set Markdown cells (commented metadata line would export to ipynb that can be opened in nteract native app):

"""
---
kernels-map:
  py: nn
jupyter:
  kernelspec:
    display_name: nn
    language: python
    name: nn
pandoctools:
  out: "*.pdf"
  # out: "*.ipynb"
...

# Markdown section title 1

Some **static** Markdown text.
"""


# %% {echo=False}
import IPython.display as ds
import math
import sugartex as stex


# %% {markdown}
"""
# Markdown section title 2

The quick brown Fox jumps over the lazy dog.
"""


# %%
ds.Markdown(stex.pre(f'''

Some **dynamic** Markdown text with SugarTeX formula: ˎα^˱{math.pi:1.3f}˲ˎ.
It works because of the `Markdown` display option and `sugartex` Pandoc filter.
Acually `stex.pre` is redundant here but it is needed when the text is imported
or read from somewhere instead of being written in the same document.

'''))

Then convert the file via pandoctools: drag and drop file to pandoctools shortcut/executable or "open with" pandoctools executable.

Also see:

  • introduction article: convenient and easily tweakable Atom+Markdown+Pandoc+Jupyter experience,
  • examples of input to output conversion that have cross-references!
  • how to use Pandoctools and it's CLI,
  • how to use Knitty that collects Jupyter outputs and change it's settings.
like image 129
Peter Zagubisalo Avatar answered Nov 14 '22 23:11

Peter Zagubisalo