SuperCollider Pygments lexer plugin
This is a Pygments lexer with custom styles for SuperCollider code. It provides syntax highlighting for SuperCollider files in Pygments-supported environments like mkdocs, sphinx, LaTeX's minted package, and more.
Pygments has a built-in lexer for SuperCollider, but the existing implementation has many issues such as not recognizing class names, incorrectly highlighting words which are not keywords in SuperCollider, etc. This plugin is a full reimplementation with much improved lexing, which means more accurate syntax highlighting of SuperCollider code. It has been submitted to the Pygments project and is awaiting review, but in the meantime, you can use it with this plugin.
Features
- Accurate lexer: Recognizes SuperCollider class names, keywords, symbols, and general syntax
- Custom color themes: Includes both light and dark themes designed specifically for SuperCollider code
- Easy integration: Works with Pygments-based tools such as mkdocs, Sphinx, and LaTeX minted
Important: Language/lexer name
Due to a naming conflict with Pygments' built-in SuperCollider lexer, you must use sc-plugin as the language/lexer name wherever you want to use this plugin.
Do not use sc or supercollider, as those will use the built-in lexer.
Installation
Install the plugin using pip:
pip install pygments-supercollider-lexer
Usage
1. Python
In vanilla Python scripts, you can use the lexer like this:
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
code = '''
SynthDef(\sine, {
var sig = SinOsc.ar(\freq.kr(440), 0, \amp.kr(0.1));
Out.ar(0, sig ! 2);
}).add;
'''
lexer = get_lexer_by_name('sc-plugin')
formatter = HtmlFormatter(style='supercollider_dark') # or 'supercollider_light'
result = highlight(code, lexer, formatter)
with open("output.html", "w") as f:
f.write(result)
Or on the command line:
pygmentize -l sc-plugin -O style=supercollider_dark -f html myfile.scd > output.html
2. Markdown/mkdocs
To use this lexer in markdown files with mkdocs, you need to install the PyMdown Extensions and configure your mkdocs.yml file to include the pymdownx.highlight extension as well as the pymdownx.superfences extension.
markdown_extensions:
- pymdownx.highlight
- pymdownx.superfences
Then, specify sc-plugin as the language name at the top of your code block:
```sc-plugin
{ SinOsc.ar(440) * 0.1 }.play;
```
Using the supplied styles with mkdocs
To use the custom SuperCollider color themes that come with this plugin in a site built with mkdocs, the best solution is to generate CSS rules for the chosen style and include it in your project. Pygments makes it easy to generate CSS files for the styles with the pygmentize command:
# For dark theme
pygmentize -S supercollider_dark -f html -a .highlight > css/supercollider_dark.css
# For light theme
pygmentize -S supercollider_light -f html -a .highlight > css/supercollider_light.css
Then, include the generated CSS files in your mkdocs.yml:
extra_css:
- css/supercollider_dark.css
If you want to support both light and dark modes, you can include both CSS files and wrap their contents in corresponding prefers-color-scheme media query.
If using the Material for MkDocs theme to switch between light and dark modes, you can use [data-md-color-scheme="default"] as a selector for the light theme and [data-md-color-scheme="slate"] for the dark theme.
3. LaTeX minted
To use the lexer with the minted package in LaTeX:
\usepackage{minted}
...
\begin{minted}{sc-plugin}
// SuperCollider code here
(
SynthDef(\sine, {
Out.ar(0, SinOsc.ar(440))
}).add;
)
\end{minted}
Troubleshooting
- If you see incorrect highlighting, double-check that you are using
sc-pluginas the language/lexer name. - If you get "no lexer for alias" errors, ensure the plugin is installed in the same Python environment as your tool (MkDocs, Sphinx, etc).
- If you update the plugin, reinstall it with
pip install -e .to refresh the entry points.
Development
To contribute or modify the lexer, (fork and) clone the repository and install it in editable mode:
git clone https://github.com/aeskildsen/pygments-supercollider-lexer.git
cd pygments-supercollider-lexer
pip install -e .[dev]
Run tests with:
pytest
License
This plugin is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for pygments-supercollider-lexer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pygments_supercollider_lexer-0.1.1.tar.gz | 8.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygments_supercollider_lexer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.0 kB
Release files / pygments_supercollider_lexer-0.1.1.tar.gz
| Download URL | pygments_supercollider_lexer-0.1.1.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19711e7a597e65cbfc18aac39a8314ccb95c6abd8390bb4b81195ebf17cb141a
|
|
BLAKE2b-256 checksum How to use checksums |
3b7fb52db8666dcdae7c47ef1360d4202b9c3ae66d41a89f5cde765fb3c88033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / pygments_supercollider_lexer-0.1.1-py3-none-any.whl
| Download URL | pygments_supercollider_lexer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
001098b18a8c169b10439fa9410318f20557cc925766c20ee2f3015b6545dd2f
|
|
BLAKE2b-256 checksum How to use checksums |
f8eda2852cb34b5aadb79db4d0baa50ded0c473b782f12aeb6eb6281d63d8bfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for pygments-supercollider-lexer 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.