Skip to main content

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

pytest codecov PyPI gh-page status

PyPI Downloads license GitHub Release Date - Published_At GitHub commits since latest release (by SemVer including pre-releases)

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")
    "captionCount": True          # Global default: enable auto-increment numbering
}

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 numbering
  • comment-delimiter: Customize comment delimiters
  • line-number-punc: Set line number punctuation
  • no-end: Omit the END keyword for control blocks
  • title-prefix: Customize the algorithm title prefix (e.g., "PseudoCode" instead of default "Algorithm")

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 pseudocode.js).

Priority Rule: Configuration priority (higher priority overrides lower): Directive option (e.g., :linenos: in .rst) > pseudocode2_options (global in conf.py) > pseudocode.js default

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

sphinxcontrib_pseudocode2-1.0.0.tar.gz (71.6 kB view details)

Uploaded Source

Built Distribution

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

sphinxcontrib_pseudocode2-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file sphinxcontrib_pseudocode2-1.0.0.tar.gz.

File metadata

File hashes

Hashes for sphinxcontrib_pseudocode2-1.0.0.tar.gz
Algorithm Hash digest
SHA256 51eb890e880757ebd7d65022b68b7f22be1bd85d8cf9cabfbf582173a52598d5
MD5 936bd4808ed36d17ceeaf5ed0d40910e
BLAKE2b-256 3a1abbbd78e2f12368274e14a2e5c1f9d4f295575f91d52b2c7b97d707a7f48f

See more details on using hashes here.

File details

Details for the file sphinxcontrib_pseudocode2-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinxcontrib_pseudocode2-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10f93c25f0dd233a582257d1ea63a0a074366fd1b5a4d05861b20eab26f27ca4
MD5 a92d9c8ad70428b29fc54491d8900540
BLAKE2b-256 4a45370e1b1d1dc2d13e30a711d126ef61a82580c5b162fb9b9bafe168886477

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