Giter VIP home page Giter VIP logo

sphinxcontrib-pseudocode's Introduction

sphinxcontrib-pseudocode

This is a fork that fixes the latex code not being rendered for newer versions of Sphinx and makes it compatible with Katex.

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.

sphinxcontrib-pseudocode's People

Contributors

mgaitan avatar xxks-kkk avatar bastiedotorg avatar azazel75 avatar 0xflotus avatar knabben avatar abrosimov-a-a avatar kexplo avatar drammock avatar cormier avatar florianhumblot avatar germanrodriguezherrera avatar gsmecher avatar ioggstream avatar shakfu avatar the-alchemist avatar victorapostol avatar wlievens avatar hoefling avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.