Skip to main content

sphinxcontrib-pseudocode2

pytest codecov PyPI RTD Status 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")
    "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 numbering
  • no-linenos: Disable line numbering
  • indent: Set indentation (working only for em, no other units) for code blocks, default: 1.2em
  • comment-delimiter: Customize comment delimiters, default: //
  • line-number-punc: Set line number punctuation, default: :
  • no-end: Omit the END keyword for control blocks
  • title-prefix: Customize the algorithm title prefix (e.g., PseudoCode instead of default Algorithm)
  • caption-count: Reset the caption counter to this number
  • scopelines: 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.js and algorithmic do 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
    

Metadata

Release files for sphinxcontrib-pseudocode2 1.1.2

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-pseudocode2 1.1.2
File Size Uploaded
sphinxcontrib_pseudocode2-1.1.2.tar.gz 76.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinxcontrib-pseudocode2 1.1.2
File Interpreter ABI Platform
sphinxcontrib_pseudocode2-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 85.3 kB

Release files / sphinxcontrib_pseudocode2-1.1.2.tar.gz

Download URL sphinxcontrib_pseudocode2-1.1.2.tar.gz
Size 76.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5c633412660c3a7d037cca11f8a6ae7f2456ebcd0c4d6cbc3b09e9ca78fadb25
BLAKE2b-256 checksum
How to use checksums
ac9f54e1e93e6cdb2af324a0570f0571d9459c32f7e7895b9cc838648604a0fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / sphinxcontrib_pseudocode2-1.1.2-py3-none-any.whl

Download URL sphinxcontrib_pseudocode2-1.1.2-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eadc481f13b1acf06a88631e8943b10197b8b26b4beede7bf63adcb64ea0b937
BLAKE2b-256 checksum
How to use checksums
a1df0a6cafb6898346c42e5400e43e0c7a1c90652969afac7b80ea61b1e8c784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.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