Sphinx extension to render LaTeX-like pseudocode via pseudocode.js (Sphinx 7.1+/8.x compatible, MathJax 3 friendly, AMD-safe)
Project description
sphinxcontrib-pseudocode2
This is a fork of the original sphinxcontrib-pseudocode project, updated to support Sphinx 7.1+ and 8.x, and modern pseudocode.js.
Installation
pip install sphinxcontrib-pseudocode2
Quick Start
Enable the extension in your Sphinx conf.py:
extensions = [
...,
"sphinxcontrib.pseudocode2",
]
# -------------------------- Optional Configuration --------------------------
# 1. Specify math engine (default: "mathjax3", alternative: "katex")
pseudocode2_math_engine = "mathjax3"
# 2. Global pseudocode.js configuration (pseudocode2_options)
# All parameters are directly passed to pseudocode.renderClass()
# Covers all pseudocode.js native options (unified project-wide style)
pseudocode2_options = {
"lineNumber": True, # Global default: enable line numbering
"lineNumberPunc": " | ", # Punctuation after line numbers (e.g., "1 | ")
"commentDelimiter": "#", # Global default comment delimiter
"noEnd": False, # Global default: show "END" for control blocks
"titlePrefix": "PseudoCode", # Global default title prefix (replace "Algorithm")
"scopeLines": True, # Global default: enable scope line highlighting
}
Write LaTeX-like pseudocode in an .. pcode:: directive:
.. pcode::
:linenos:
\begin{algorithm}
\caption{Quicksort}
\begin{algorithmic}
\PROCEDURE{Quicksort}{$A, p, r$}
\IF{$p < r$}
\STATE $q = $ \CALL{Partition}{$A, p, r$}
\STATE \CALL{Quicksort}{$A, p, q - 1$}
\STATE \CALL{Quicksort}{$A, q + 1, r$}
\ENDIF
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}
Configuration Options
Pseudocode rendering is extended with practical options (all compatible with pseudocode.js native capabilities):
linenos: Enable line numberingno-linenos: Disable line numberingindent: Set indentation (working only forem, no other units) for code blocks, default:1.2emcomment-delimiter: Customize comment delimiters, default://line-number-punc: Set line number punctuation, default::no-end: Omit theENDkeyword for control blockstitle-prefix: Customize the algorithm title prefix (e.g.,PseudoCodeinstead of defaultAlgorithm)caption-count: Reset the caption counter to this numberscopelines: Highlight scope lines (those with control block starters like IF, FOR, WHILE, etc.)no-scopelines: Disable scope line highlighting
Global Configuration via pseudocode2_options
Pseudocode rendering styles can be unified across the entire project using a single global configuration (supports all pseudocode.js native parameters, see the Options section of pseudocode.js). See also the example in the Quick Start section.
Priority Rule: Configuration priority (higher priority overrides lower): Directive option (e.g., :linenos: in .rst) > pseudocode2_options (global in conf.py) > pseudocode.js default.
Tips
-
Custom (Manual) indentation Control:
pseudocode.jsandalgorithmicdo not have a built-in way (a single command or a pair of commands) to set custom indentation levels. However, you can manually adjust indentation by the following workaround: use LaTeX's horizontal space command inside a math environment. Specifically, use$\hspace{<length>}$where<length>is a LaTeX length (e.g.,2em,1cm, etc.). For example:\STATE $\hspace{2em}$ This line is indented by 2em
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinxcontrib_pseudocode2-1.1.1.tar.gz.
File metadata
- Download URL: sphinxcontrib_pseudocode2-1.1.1.tar.gz
- Upload date:
- Size: 76.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3493097136ac2cf7bbb3fdc8ae62e5662a304645251bc92321db7df62304de47
|
|
| MD5 |
844ce551a1a9b339302467d163e031b4
|
|
| BLAKE2b-256 |
40183133377df1c360a9d1b6a62721e9f36ce89e958e044be45a6f130549f15a
|
File details
Details for the file sphinxcontrib_pseudocode2-1.1.1-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_pseudocode2-1.1.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eee72e2f27cbbbe5cc45b717c767a51d02266e1dce149a30a0f23756d99f19b9
|
|
| MD5 |
1f0dd5177d6a6456731a3ed029b88b06
|
|
| BLAKE2b-256 |
1fde30ab4e09c5722d1d08cbecad85df15e390facdda249179da1b50f1c4a4e5
|