write LaTeX algorithm in your sphinx-doc powered docs
Project description
sphinxcontrib-pseudocode
This is a sphinx-doc extension that allows you to write LaTeX algorithm directly inside sphinx-doc. The rendering of LaTex algorithm is powered by pseudocode.js.
Demo
You can directly type LaTeX algorithm (e.g., quicksort algorithm taken from pseudocode.js demo) under pcode
directive in any .rst files as follows:
.. pcode::
:linenos:
% This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
\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
\PROCEDURE{Partition}{$A, p, r$}
\STATE $x = A[r]$
\STATE $i = p - 1$
\FOR{$j = p$ \TO $r - 1$}
\IF{$A[j] < x$}
\STATE $i = i + 1$
\STATE exchange
$A[i]$ with $A[j]$
\ENDIF
\STATE exchange $A[i]$ with $A[r]$
\ENDFOR
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}
The above code will be rendered as
See more examples on demo page.
Installation and Configuration
Install the package via
pip install sphinxcontrib-pseudocode
Then in the Sphinx-doc conf.py, add
extensions = [
'sphinx.ext.mathjax',
'sphinxcontrib.pseudocode'
]
MathJax version requirement: The current release of pseudocode.js (@latest, v2.4.1)
requires MathJax.tex2chtml, which was removed in MathJax 4. Sphinx 8+ defaults to
MathJax 4, so you must pin MathJax 3 explicitly in your conf.py:
mathjax_path = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
Without this setting, algorithm blocks containing math expressions will silently fail to render in any Sphinx version that defaults to MathJax 4.
Note: MathJax 4 support has been merged into pseudocode.js but not yet released (commit 1ab6334). Once a new version is published to npm, the
mathjax_pathpin can be removed.
Usage
Write LaTeX algorithm within pcode directive as shown above. The following option is supported:
linenos(LineNumberin pseudocode.js: Whether line numbering is enabled)
For Developer
This blog explains the underlying implementation details of this extension.
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_pseudocode-0.8.0.tar.gz.
File metadata
- Download URL: sphinxcontrib_pseudocode-0.8.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2464f5506dd312b6de7f84e0f435f204ad9633abe061e8a08787b3525d3b8f11
|
|
| MD5 |
8cf960770f913d2bb8ca4a4178d505c7
|
|
| BLAKE2b-256 |
9560792d8d8d8dd4939281768541496ef3d573da369d29e1a454cee34ca17ea4
|
Provenance
The following attestation bundles were made for sphinxcontrib_pseudocode-0.8.0.tar.gz:
Publisher:
publish.yml on xxks-kkk/sphinxcontrib-pseudocode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_pseudocode-0.8.0.tar.gz -
Subject digest:
2464f5506dd312b6de7f84e0f435f204ad9633abe061e8a08787b3525d3b8f11 - Sigstore transparency entry: 1529913237
- Sigstore integration time:
-
Permalink:
xxks-kkk/sphinxcontrib-pseudocode@10e5061035dbee9b0f8995c8367c3029d6f5e327 -
Branch / Tag:
refs/tags/0.8.0 - Owner: https://github.com/xxks-kkk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@10e5061035dbee9b0f8995c8367c3029d6f5e327 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5ecb01c2aa1d5908c40e22d6cb01e43aa7cd762e230791993cc0880fb570a6
|
|
| MD5 |
1c0f81a5ae4b6b1252bf8c909af0eece
|
|
| BLAKE2b-256 |
708514df1e13f48999a342985d4aaca06f7ec20536c3c72a22a37e4a1979456e
|
Provenance
The following attestation bundles were made for sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl:
Publisher:
publish.yml on xxks-kkk/sphinxcontrib-pseudocode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl -
Subject digest:
8b5ecb01c2aa1d5908c40e22d6cb01e43aa7cd762e230791993cc0880fb570a6 - Sigstore transparency entry: 1529913304
- Sigstore integration time:
-
Permalink:
xxks-kkk/sphinxcontrib-pseudocode@10e5061035dbee9b0f8995c8367c3029d6f5e327 -
Branch / Tag:
refs/tags/0.8.0 - Owner: https://github.com/xxks-kkk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@10e5061035dbee9b0f8995c8367c3029d6f5e327 -
Trigger Event:
release
-
Statement type: