https://github.com/gnu-octave/pkg-jupyter-notebook
A package to run and fill Jupyter Notebooks within GNU Octave.
https://github.com/gnu-octave/pkg-jupyter-notebook
gnu-octave octave octave-packages
Last synced: 3 months ago
JSON representation
A package to run and fill Jupyter Notebooks within GNU Octave.
- Host: GitHub
- URL: https://github.com/gnu-octave/pkg-jupyter-notebook
- Owner: gnu-octave
- License: gpl-3.0
- Created: 2021-05-30T13:35:58.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-22T20:20:29.000Z (about 1 year ago)
- Last Synced: 2025-03-22T20:29:27.333Z (about 1 year ago)
- Topics: gnu-octave, octave, octave-packages
- Language: MATLAB
- Homepage:
- Size: 1.31 MB
- Stars: 7
- Watchers: 8
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Octave Jupyter Notebook package
> **This package is already included into Octave core.**
> The function of this package `jupyter_notebook` exists in Octave version 7 and newer: .

A package to run and fill Jupyter Notebooks within GNU Octave.
The package supports filling both textual and graphical outputs.
## Installation
From the Octave command-line:
```
pkg install "https://github.com/gnu-octave/pkg-jupyter-notebook/archive/v1.3.0.tar.gz"
```
## jupyter_notebook
```
notebook_object = jupyter_notebook (notebook_filename, options)
```
Run and fill the Jupyter Notebook in file `notebook_filename` from
within GNU Octave.
Both text and graphical Octave outputs are supported.
This class has a public property `notebook` which is a structure
representing the JSON-decoded Jupyter Notebook. This property is
intentionally public to enable advanced notebook manipulations.
**Note:** Jupyter Notebook versions (`nbformat`) lower than 4.0 are not
supported.
The optional second argument `options` is a struct with fields:
* `tmpdir` to set the temporary working directory.
## plot magic
`%plot` magic is supported with the following settings:
* `%plot -f ` or `%plot --format `: specifies the
image storage format. Supported formats are:
* PNG (default)
* SVG (Note: If SVG images do not appear in the notebook,
it is most related to the Jupyter Notebook security
mechanism and explicitly "trusting" them is necessary).
* JPG
* `%plot -r ` or `%plot --resolution `: specifies the image resolution.
* `%plot -w ` or `%plot --width `: specifies the image width.
* `%plot -h ` or `%plot --height `: specifies the image height.
## Methods
The `jupyter_notebook` class supports the following methods.
### `run (cell_index)`
Run the Jupyter Notebook cell with index `cell_index`
and eventually replace previous output cells in the object.
The first Jupyter Notebook cell has the index 1.
**Note:** The code evaluation of the Jupyter Notebook cells is done
in a separate Jupyter Notebook context. Thus, currently open
figures and workspace variables won't be affected by executing
this function. However, current workspace variables cannot be
accessed either.
### `run_all ()`
Run all Jupyter Notebook cells and eventually replace previous
output cells in the object.
**Note:** The code evaluation of the Jupyter Notebook cells is done
in a separate Jupyter Notebook context. Thus, currently open
figures and workspace variables won't be affected by executing
this function. However, current workspace variables cannot be
accessed either.
### `generate_notebook (notebook_file_name)`
Write the Jupyter Notebook stored in the `notebook`
attribute to `notebook_file_name`.
The `notebook` attribute is encoded to JSON text.
### `generate_octave_script (script_file_name)`
Write an Octave script that has the contents of the Jupyter Notebook
stored in the `notebook` attribute to `script_file_name`.
Non-code cells are generated as block comments.
## Examples:
The outputs of the following examples are shown using this notebook:

### Run all cells and generate the filled notebook
```
## Instantiate an object from the notebook file
notebook = jupyter_notebook ("myNotebook.ipynb")
=> notebook =
## Run the code and embed the results in the notebook attribute
notebook.run_all()
## Generate the new notebook by overwriting the original notebook
notebook.generate_notebook ("myNotebook.ipynb")
```
This is the generated notebook:

### Run the third cell and generate the filled notebook
```
## Instantiate an object from the notebook file
notebook = jupyter_notebook ("myNotebook.ipynb")
=> notebook =
## Run the code and embed the results in the notebook attribute
notebook.run(3)
## Generate the new notebook in a new file
notebook.generate_notebook ("myNewNotebook.ipynb")
```
This is the generated notebook:

### Generate an Octave script from a notebook
```
## Instantiate an object from the notebook file
notebook = jupyter_notebook ("myNotebook.ipynb")
=> notebook =
## Generate the octave script
notebook.generate_octave_script ("myScript.m")
```
This is the generated script: