Skip to main content

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

quicksort-demo

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_path pin can be removed.

Usage

Write LaTeX algorithm within pcode directive as shown above. The following option is supported:

  • linenos (LineNumber in pseudocode.js: Whether line numbering is enabled)

For Developer

This blog explains the underlying implementation details of this extension.

Metadata

Release files for sphinxcontrib-pseudocode 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxcontrib-pseudocode 0.8.0
File Size Uploaded
sphinxcontrib_pseudocode-0.8.0.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinxcontrib-pseudocode 0.8.0
File Interpreter ABI Platform
sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / sphinxcontrib_pseudocode-0.8.0.tar.gz

Download URL sphinxcontrib_pseudocode-0.8.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2464f5506dd312b6de7f84e0f435f204ad9633abe061e8a08787b3525d3b8f11
BLAKE2b-256 checksum
How to use checksums
9560792d8d8d8dd4939281768541496ef3d573da369d29e1a454cee34ca17ea4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl

Download URL sphinxcontrib_pseudocode-0.8.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b5ecb01c2aa1d5908c40e22d6cb01e43aa7cd762e230791993cc0880fb570a6
BLAKE2b-256 checksum
How to use checksums
708514df1e13f48999a342985d4aaca06f7ec20536c3c72a22a37e4a1979456e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

3 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page