Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Pseudocode rendering is extended with practical options (all compatible with pse

- ``linenos``: Enable line numbering
- ``no-linenos``: Disable line numbering
- ``indent``: Set indentation (seems working only for ``em``, no other units) for code blocks, default: ``1.2em``
- ``indent``: Set indentation (working only for ``em``, no other units) for code blocks, default: ``1.2em``
- ``comment-delimiter``: Customize comment delimiters, default: ``//``
- ``line-number-punc``: Set line number punctuation, default: ``:``
- ``no-end``: Omit the ``END`` keyword for control blocks
Expand All @@ -84,7 +84,19 @@ Pseudocode rendering is extended with practical options (all compatible with pse

### Global Configuration via ``pseudocode2_options``

Pseudocode rendering styles can be unified across the entire project using a single global configuration (supports all pseudocode.js native parameters, see [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js)). See also the example in the [Quick Start section](#quick-start).
Pseudocode rendering styles can be unified across the entire project using a single global configuration (supports all pseudocode.js native parameters, see the ``Options`` section of [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js)). See also the example in the [Quick Start section](#quick-start).

**Priority Rule**:
Configuration priority (higher priority overrides lower): Directive option (e.g., :linenos: in .rst) > pseudocode2_options (global in conf.py) > pseudocode.js default
Configuration priority (higher priority overrides lower): Directive option (e.g., :linenos: in .rst) > pseudocode2_options (global in conf.py) > pseudocode.js default.

## Tips

- Custom (Manual) indentation Control: ``pseudocode.js`` and ``algorithmic`` do not have a built-in way (a single command
or a pair of commands) to set custom indentation levels. However, you can manually adjust indentation by the following
workaround: use LaTeX's horizontal space command **inside** a math environment. Specifically, use

``$\hspace{<length>}$`` where ``<length>`` is a LaTeX length (e.g., ``2em``, ``1cm``, etc.). For example:

```text
\STATE $\hspace{2em}$ This line is indented by 2em
```
4 changes: 4 additions & 0 deletions docs/source/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
\end{algorithmic}
\end{algorithm}

.. _test-atoms-algo:

.. tabs::

.. tab:: Rendered
Expand All @@ -180,6 +182,8 @@
\STATE \textbf{Specials:} \{ \} \$ \& \# \% \_
\STATE \textbf{Bools:} \AND \OR \NOT \TRUE \FALSE
\STATE \textbf{Carriage return:} first line \\ second line
\STATE $\hspace{2em}$ This line is indented by 2em
\STATE $\hspace{2em}$ This line is indented by 2em
\STATE \textbf{Text-symbols:} \textbackslash
\STATE \textbf{Quote-symbols:} `single quotes', ``double quotes''
\STATE \textbf{Math:} $(\mathcal{C}_m)$, $i \gets i + 1$, $E=mc^2$, \( x^n + y^n = z^n \), $\$$, \(\$\)
Expand Down
21 changes: 18 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ You can change this behavior by overriding the corresponding string of ``'pseudo
`numfig_format <https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-numfig_format>`_.

Configuration Options
======================
=====================================================

Pseudocode rendering is extended with practical options (all compatible with pseudocode.js native capabilities):

- ``linenos``: Enable line numbering
- ``no-linenos``: Disable line numbering
- ``indent``: Set indentation (seems working only for ``em``, no other units) for code blocks, default: ``1.2em``
- ``indent``: Set indentation (working only for ``em``, no other units) for code blocks, default: ``1.2em``
- ``comment-delimiter``: Customize comment delimiters, default: ``//``
- ``line-number-punc``: Set line number punctuation, default: ``:``
- ``no-end``: Omit the ``END`` keyword for control blocks
Expand All @@ -58,7 +58,7 @@ Pseudocode rendering is extended with practical options (all compatible with pse
Global Configuration via ``pseudocode2_options``
=====================================================

Pseudocode rendering styles can be unified across the entire project using a single global configuration (supports all pseudocode.js native parameters, see [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js)). The following example shows how to set global options in `conf.py`:
Pseudocode rendering styles can be unified across the entire project using a single global configuration (supports all pseudocode.js native parameters, see the ``Options`` section of [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js)). The following example shows how to set global options in `conf.py`:

.. code-block:: python

Expand All @@ -74,6 +74,21 @@ Pseudocode rendering styles can be unified across the entire project using a sin
**Priority Rule**:
Configuration priority (higher priority overrides lower): Directive option (e.g., :linenos: in .rst) > pseudocode2_options (global in conf.py) > pseudocode.js default

Tips
=====================================================

- Custom (Manual) indentation Control: ``pseudocode.js`` and ``algorithmic`` do not have a built-in way (a single command
or a pair of commands) to set custom indentation levels. However, you can manually adjust indentation by the following
workaround: use LaTeX's horizontal space command **inside** a math environment. Specifically, use

``$\hspace{<length>}$`` where ``<length>`` is a LaTeX length (e.g., ``2em``, ``1cm``, etc.). For example:

.. code-block:: latex

\STATE $\hspace{2em}$ This line is indented by 2em

See also :ref:`this example <test-atoms-algo>`

########
Examples
########
Expand Down
1 change: 1 addition & 0 deletions sphinxcontrib/pseudocode2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def run(self):
env = getattr(self, "env", None)
app = getattr(env, "app", None) if env is not None else None
global_opts = getattr(app.config, "pseudocode2_options", {}) if app is not None else {}
global_opts = global_opts if global_opts is not None else {}
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant. Line 62 uses getattr(app.config, 'pseudocode2_options', {}) which already provides {} as the default when the attribute doesn't exist. The getattr function never returns None in this case—it returns the provided default {}. If a user explicitly sets pseudocode2_options = None in their config, that would be a configuration error that should be caught earlier or documented as invalid.

Suggested change
global_opts = global_opts if global_opts is not None else {}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR solves the case where app.config has the attribute 'pseudocode2_options' whose value is None.


if "no-scopelines" in self.options:
use_scopelines = False
Expand Down