njpipeorgan / wolfram-language-notebook

Notebook support for Wolfram Language in VS Code
Apache License 2.0
166 stars 12 forks source link

Notebook support for Wolfram Language in VS Code

Prerequisites

Install this extension from VS Code Marketplace.

Getting Started

To create a new Wolfram Language notebook, execute Create New Wolfram Language Notebook in the Command Palette, or create a new file with .wlnb extension.

Execute Manage Kernels command and choose Use wolframscript to add wolframscript to the kernel configuration and connect to it. The status of the kernel will be shown in the status bar.

Add a code cell, type Wolfram language code in the cell, and evaluate it.

getting-started

Features

Syntax Highlighting: The notebook highlights Wolfram language syntax, common built-in functions, and full character names, e.g. \[Alpha].

Auto-completion and Usages: Auto-completion for built-in functions are provided. Their usage information is displayed when typing and hovering.

Output Renderer: The notebook renders common Wolfram language expressions into HTML for better presentations. Graphics are shown as rasterized images.

Export as Wolfram notebook: The notebooks can be exported as Wolfram notebooks, containing markdown cells, code cells and their outputs.

Remote development: When configured, the notebook can establish a tunnel or an SSH connection to the remote machine, and the computations are done remotely. Code and outputs can be stored either on the remote machine or locally.

Kernel Configuration

To add a new kernel, click ⨉ Wolfram Kernel in the status bar and choose Add a new kernel (when no kernel is currently connected). By default, the command launching the kernels is wolframscript and the port is randomly selected between 49152 and 65535. To edit or remove kernel configurations, find kernel.configurations in the extension settings page, and edit settings.json.

Remote Development

Use VS Code Remote Tunnel

With this approach, you connect to a remote machine through a secure tunnel following this guide. When configured, you can work with the files and the kernel on the remote system from a web browser. In short, you need to:

  1. Install code CLI on the remote machine.
  2. Create a tunnel with the command code tunnel, where a URL will be printed as https://vscode.dev/tunnel/.../....
  3. Open the URL in a web browser.
  4. Click ⨉ Wolfram Kernel to add or launch a kernel on the remote system.

Use VS Code Remote Development

With this approach, you use VS Code to connect to remote machines, containers, or WSL. You work with the files and the kernel on the remote system. To do this, you need to:

  1. Install Remote Development Extension Pack;
  2. Follow the guide to connect to a remote system; and
  3. Click ⨉ Wolfram Kernel to add or launch a kernel on the remote system.

Launch Remote Kernel via SSH

With this approach, you launch and connect to a remote kernel via SSH: code and files are stored locally, and the communication with the remote kernel is managed by the extension.

To add a remote kernel, choose On a remote machine, and provide the private key file for ssh authentication (skip the private key if it is already available to ssh).

To edit or remove kernel configurations, find kernel.configurations in the extension settings page, and edit settings.json. Each kernel is an entry with the kernel name as the key and the following configurations as the value:

Key Value
type "local"/"remote"
command command to launch the kernel, e.g. "wolframscript"
ports ranges of numbers, e.g. "1,3,6-9"
sshCommand the ssh command, e.g. "ssh"
sshHost user@hostname
sshPort port of ssh server (default: 22)
sshCredentialType "key"/"none"
sshCredential path to the ssh credential

Release Notes

Check Release Notes.

FAQ

The notebook failed to connect to a kernel.

The output of an evaluation was not what I expected.

How can I use the notebook with Wolfram Language Server?