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:
:numref:`quick-sort`produces Algorithm 1:numref:`Here is my algorithm {number} <quick-sort>`produces Here is my algorithm 1:ref:`test control blocks <test-control-blocks>`produces test control blocks
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.
Custom Macros with \newcommand¶
You can define your own LaTeX macros using \newcommand in three ways:
Inline Macros: Define the macro at the beginning of the
pcodeblock. 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 apcodeblock directly with a\newcommand. The simplest workaround is to add a comment line before the first macro definition.Per-Page Macros: Define macros in a
.. math::block. These macros will be available to allpcodeblocks on the same page.\[\newcommand{\ceil}[1]{\lceil #1 \rceil}\]Global Macros: Define macros in your
conf.pyfile using themathjax3_configsetting. These macros will be available across your entire Sphinx project.# In conf.py mathjax3_config = { 'tex': { 'macros': { 'RR': r'\mathbb{R}', } } }