Welcome to Sphinxcontrib-pseudocode demo

Features

Below shows various rendered algorithms, which are copied from corresponding pseudocode.js examples. The source code of those algorithms can be found here.

We can also reference any particular algorithm. For example, we can also reference each algorithm:

Note

We assume each pcode directive contains exactly one \(\LaTeX\) algorithmic block:

\begin{algorithm}
\caption{Test atoms}
\begin{algorithmic}
\STATE my algorithm 1
\END{ALGORITHMIC}
\END{ALGORITHM}

You still can have multiple algorithmic blocks but the numbering will be messed up.

By default, each pcode is mapped to ‘Algorithm %s’ when referenced via numref. You can change this behavior by overriding the corresponding string of 'pseudocode' key in numfig_format.

\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
             \begin{algorithmic}
 \PRINT \texttt{'hello world'}
 \end{algorithmic}
        
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
\[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]

Custom Macros with \newcommand

You can define your own LaTeX macros using \newcommand in three ways:

  1. Inline Macros: Define the macro at the beginning of the pcode block. The macro will only be available for that specific block.

    Note

    Due to a quirk in the reStructuredText parser, a directive’s content block cannot begin with a \. To avoid issues, do not start a pcode block directly with a \newcommand. The simplest workaround is to add a comment line before the first macro definition.

    \[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \newcommand{\floor}[1]{\lfloor #1 \rfloor} \]
  2. Per-Page Macros: Define macros in a .. math:: block. These macros will be available to all pcode blocks on the same page.

    \[\newcommand{\ceil}[1]{\lceil #1 \rceil}\]
    \[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]
  3. Global Macros: Define macros in your conf.py file using the mathjax3_config setting. These macros will be available across your entire Sphinx project.

    # In conf.py
    mathjax3_config = {
        'tex': {
            'macros': {
                'RR': r'\mathbb{R}',
            }
        }
    }
    
    \[ \newcommand{\ceil}[1]{\lceil #1 \rceil} \]