feelpp / antora-ui

https://feelpp.github.io/antora-ui/
Mozilla Public License 2.0
0 stars 2 forks source link

Simplify pseudocode syntax #4

Closed ggrossetie closed 1 year ago

ggrossetie commented 1 year ago

I think we should use a literal block with a role:

[.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
        \STATE exchange $A[i]$ with $A[r]$
    \ENDFOR
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}
....

We don't need to use a unique identifier since pseudocode.js accepts an Element/Node from the DOM.

The following resources will be dynamically added if there's at least of literal block with the role pseudocode in the page:

The performance cost of using document.querySelectorAll('.literalblock.pseudocode pre') is insignificant.