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
-
Clone the repository:
git clone https://github.com/your-username/mkdocs-pseudocode-plugin.git cd mkdocs-pseudocode-plugin
-
Install the plugin locally:
pip install -e .
-
Add the plugin to your
mkdocs.yml
configuration file:plugins: - search - pseudocode
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
Your Name
Feel free to customize the content as needed before publishing it on GitHub.
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
Built Distribution
File details
Details for the file mkdocs-pseudocode-0.1.0.tar.gz
.
File metadata
- Download URL: mkdocs-pseudocode-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d32d3f4d27648b48f51552d207f5f1cc7514e80813fb86f84e4c80e62e4532b |
|
MD5 | 479cd5c8b52dec1a5eaa7b9e9c07fbe7 |
|
BLAKE2b-256 | 05b711ece51cb1023f2dbb34d699a11a7a354e716c80d15af559bb542eabd773 |
File details
Details for the file mkdocs_pseudocode-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: mkdocs_pseudocode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a93ed49d4d764b21596e108f1120f2011ce8158af72c094aef292234cfa17d |
|
MD5 | 2ed474b0ec995ac7692b1a3e5f767d75 |
|
BLAKE2b-256 | 05c31ed59c4586a9ea1c6a667cb41e5d8b6c0c0cac8772f967b9172c22e015f0 |