Skip to main content

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

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 = [
    'sphinxcontrib.pseudocode'
]

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.

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-pseudocode-0.7.0.tar.gz (12.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_pseudocode-0.7.0-py2.py3-none-any.whl (18.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sphinxcontrib-pseudocode-0.7.0.tar.gz.

File metadata

  • Download URL: sphinxcontrib-pseudocode-0.7.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for sphinxcontrib-pseudocode-0.7.0.tar.gz
Algorithm Hash digest
SHA256 af17a05d4a7c6d06f26d939bb3fae681076e16ce2644f6a48f0bba4a2088fe98
MD5 15c62a759736ca5b7ed1d9385a4e788c
BLAKE2b-256 30e02df2cbc07e83729c14d738c07eee8e1ef4d2a5f20113484fa55a3af51b33

See more details on using hashes here.

File details

Details for the file sphinxcontrib_pseudocode-0.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sphinxcontrib_pseudocode-0.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for sphinxcontrib_pseudocode-0.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c5e73b8fde296a8d62619ee9ed530fdeada0e3058be796216ff8de3f617062cf
MD5 b1609446322a71b7b3e1b0d0cfe727b6
BLAKE2b-256 0ce2f379fa65c4dfac6eec3302e58a1d3199296ee080e9c6a3d90c2d9f3ff744

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