Skip to main content

Jupyterlab extension to highlight Stan syntax

Project description

jupyterlab-stan-highlight

JupyterLab extension to highlight Stan syntax in notebooks and standalone Stan files.

This extension has been updated to work with JupyterLab 4.0+ and uses CodeMirror 6 for syntax highlighting.

Modeled on the VSCode grammar and uses stan-language-definitions

Use it with CmdStanJupyter to receive highlighting for your %%stan blocks in python notebooks!

Features

  • Syntax highlighting for .stan files
  • Automatic highlighting for %%stan magic cells in Jupyter notebooks
  • Support for Stan language constructs including:
    • Data types (int, real, vector, matrix, etc.)
    • Control flow (for, while, if, else)
    • Distributions and functions
    • Comments and preprocessor directives

Prerequisites

  • JupyterLab 4.0 or later

Installation

From PyPI (Recommended)

pip install jupyterlab-stan-highlight

Development Installation

For a development install, clone this repository and run:

pip install -e .
# Or if you prefer to use conda/mamba
# conda install -c conda-forge jupyterlab nodejs
# mamba install -c conda-forge jupyterlab nodejs

# Install dependencies
jlpm install

# Build the extension
jlpm run build

# Install the extension for development
jupyter labextension develop . --overwrite

Usage

  1. Stan Files: Open any .stan file in JupyterLab and syntax highlighting will be applied automatically.

  2. Notebook Magic Cells: In a Jupyter notebook, create a code cell that starts with %%stan and the rest of the cell content will be highlighted as Stan code:

%%stan
data {
  int<lower=0> N;
  vector[N] y;
}
parameters {
  real mu;
  real<lower=0> sigma;
}
model {
  y ~ normal(mu, sigma);
}

Building

To build the extension:

jlpm run build

To build for production:

jlpm run build:prod

Changes from Previous Version

This version (0.4.0+) includes major updates for JupyterLab 4 compatibility:

  • Migrated from CodeMirror 5 to CodeMirror 6
  • Updated to use JupyterLab 4 APIs
  • Modernized build system using @jupyterlab/builder
  • Added TypeScript support
  • Improved magic cell detection

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab4_stan_highlight-0.4.0.tar.gz (137.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyterlab4_stan_highlight-0.4.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab4_stan_highlight-0.4.0.tar.gz.

File metadata

File hashes

Hashes for jupyterlab4_stan_highlight-0.4.0.tar.gz
Algorithm Hash digest
SHA256 82b8d0d3246062d512d4f9d48c7a459a12806cbd56f51a831edcb33b3b18dc91
MD5 a5cd2661d2b912cd6d185c0ccf56b016
BLAKE2b-256 cf9bbf9d2071897da0af58bc914b55a66cbca73cf8c0e5c00a50ce3792527482

See more details on using hashes here.

File details

Details for the file jupyterlab4_stan_highlight-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlab4_stan_highlight-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b6dbad154df9c2028e4e0246a7f14311e9f35fe9fe205e4245fd0d556bfa467
MD5 d87133d804c17a9517b9ac3b42fa86cd
BLAKE2b-256 889fc38be77a64a373e032aff8944fdefa78a1126ff576a1f262043f0d7c0d90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page