For AI agents: the complete documentation index is available at https://shijin.space/llms.txt, the full documentation bundle is available at https://shijin.space/llms-full.txt, and this page is available as Markdown at https://shijin.space/projects/cinderfolio/pseudocode/index.md.

Cinderfolio-Pseudocode

pseudocode.js 将 algorithmic 语法排成论文式算法,下方使用官方快速排序示例。

网站与 Marp 统一使用 pseudo 围栏,与 Obsidian Pseudocode 插件保持一致。

深色g0#121212
浅色g16bg#fafaf8
品牌基准色brand#f97316
cf-pseudocode.css 随仓库提供,需配合 Cinderfolio 配色变量及 KaTeX / MathJax 的样式和字体,暂不单独下载。
KaTeX 0.16.47
MathJax 3.2.2

Algorithm 1 Quicksort

1:procedure Quicksort(A,p,rA, p, r)

2:if p<rp < r then

3:q=q = Partition(A,p,rA, p, r)

4:Quicksort(A,p,q−1A, p, q - 1)

5:Quicksort(A,q+1,rA, q + 1, r)

6:procedure Partition(A,p,rA, p, r)

7:x=A[r]x = A[r]

8:i=p−1i = p - 1

9:for j=pj = p to r−1r - 1 do

10:if A[j]<xA[j] < x then

11:i=i+1i = i + 1

12:exchange A[i]A[i] with A[j]A[j]

13:exchange A[i]A[i] with A[r]A[r]

代码块选项

在 pseudo 后用空格分隔选项,每个代码块放一个算法:

```pseudo math=mathjax noEnd=true scopeLines=true
\begin{algorithm}
\caption{Quicksort}
\begin{algorithmic}
\STATE \CALL{Quicksort}{$A, p, r$}
\end{algorithmic}
\end{algorithm}
```

Algorithm 3 Quicksort

1:Quicksort()

代码块目前接受以下三项设置:

  • math=katex 或 math=mathjax:选择公式引擎。省略时,网页使用 KaTeX,Marp 跟随文稿的 math 设置。
  • noEnd=true 或 noEnd=false:是否隐藏 end if 等结束行,默认 true。源文中的 \ENDIF 等结束命令仍须保留。
  • scopeLines=true 或 scopeLines=false:是否显示缩进竖线,默认 true。

行号自动显示;算法标题编号在每篇文档内从 1 开始。

常用伪代码语法

算法正文放在 algorithmic 环境中;外层 algorithm 和 \caption{标题} 添加带编号的标题。以下示例均可放入 pseudo 代码块,上方为源码,下方为渲染结果。完整说明见 pseudocode.js 官方语法文档。

基本语句
条件分支
循环
函数与调用
公式与注释
\begin{algorithmic}
\INPUT Values $a, b$                % 输入
\OUTPUT Maximum $m$                % 输出
\REQUIRE $a, b \in \mathbb{R}$      % 前置条件
\ENSURE $m \ge a$ \AND $m \ge b$    % 后置条件
\STATE $m \gets \max(a, b)$         % 一条语句
\PRINT $m$                         % 输出一行
\RETURN $m$                        % 返回结果
\end{algorithmic}

Input: Values a,ba, b

Output: Maximum mm

Require: a,b∈Ra, b \in \mathbb{R}

Ensure: m≥am \ge a and m≥bm \ge b

1:m←max⁡(a,b)m \gets \max(a, b)

2:print mm

3:return mm

显示职责
  • 字体:算法文字与公式采用所选引擎的字体,中文使用页面的后备字体。算法字号与行距独立于 Marp 正文。
  • 关键词:浅色主题使用强调色系的 darker 档,深色主题使用 light 档,与 Shiki 的流程导航色一致。
  • 横线与注释:次要文字灰阶;三条横线颜色一致。
  • 行号与缩进竖线:统一使用辅助文字灰阶。
  • 外框:独立算法使用圆角边框;单算法标签页与标签容器共用外框。