Skip to main content

A MkDocs plugin to render beautiful pseudocode with LaTeX-inspired syntax.

Project description

MkDocs Pseudocode Plugin

This MkDocs plugin allows you to write beautiful pseudocode in your MkDocs documentation using a simplified syntax inspired by LaTeX.

Features

  • Render pseudocode blocks with LaTeX-inspired syntax
  • Support for common control structures (if, for, while, repeat, foreach)
  • Math expressions rendered using MathJax
  • Nested procedures and calls
  • Automatic indentation and keyword highlighting

Installation

  1. Install the plugin locally:

    pip install mkdocs-pseudocode
    
  2. Add the plugin to your mkdocs.yml configuration file:

    plugins:
      - search
      - pseudocode
    
  3. Copy CSS file into your extra.css file of your Mkdocs project

    Place the pseudo-code.css file in the docs/css/ directory of your MkDocs project.

    Add the following lines to your mkdocs.yml file:

    extra_css:
        - css/pseudo-code.css
    

Usage

Write your pseudocode in fenced code blocks with the pseudocode language identifier:

```pseudocode
% 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
    \ENDFOR
    \STATE exchange $A[i]$ with $A[r]$
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}

Customization

CSS

You can customize the appearance of the pseudocode by adding your own CSS rules. The default CSS classes used are:

  • .ps-root
  • .ps-algorithm
  • .ps-algorithmic
  • .ps-caption
  • .ps-keyword
  • .ps-procedure
  • .ps-if
  • .ps-for
  • .ps-while
  • .ps-repeat
  • .ps-foreach
  • .ps-state
  • .ps-call
  • .ps-funcname
  • .ps-indent-{level}

JavaScript

To ensure MathJax expressions are rendered correctly, you may need to add the following JavaScript snippet to your MkDocs theme:

<script>
document.addEventListener("DOMContentLoaded", function() {
    if (typeof MathJax !== 'undefined') {
        MathJax.typesetPromise();
    }
});
</script>

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

Author

Jules TOPART


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

mkdocs-pseudocode-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

mkdocs_pseudocode-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-pseudocode-0.1.1.tar.gz.

File metadata

  • Download URL: mkdocs-pseudocode-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.11

File hashes

Hashes for mkdocs-pseudocode-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a8d9e8afe1a43d2da144a7017be7a881c9d096d852673a92b2a06f90ab9cd002
MD5 cd665bccc7a83864fc5a05f964284073
BLAKE2b-256 174aa44c7708bb09283ddddc21c1196d91ea959521eb8dcb62d13aad0a35f172

See more details on using hashes here.

File details

Details for the file mkdocs_pseudocode-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_pseudocode-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f145c829a610adfd7ba2aa420456ad2e29ee38992408131aba7297e3e2ab9584
MD5 1194dff45bb11d1ae28aefceff657783
BLAKE2b-256 a4359cbf043891f6c99e1454d7750ed38716932613ab241e416bf2e656e66c84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page