Render pseudocode fences in the VS Code Markdown preview with an algorithm-style layout.
Usage
Use a fenced code block with one of these languages:
algorithmalgoalgpseudocodepseudo
```algorithm title="Euclid" label="alg:euclid" input="integers \(a, b\)" output="\(\text{gcd}(a,b)\)" linenos latex
while b != 0 do
r <- a mod b
a <- b
b <- r
return a
```
Supported fence options:
title="..."orcaption="...": caption shown above the algorithm.label="...": optional label shown in the caption and included in generated LaTeX.input="...",output="...",require="...", orensure="...": algorithm parameters shown before the body. Inline LaTeX syntax such as\(\text{gcd}(a,b)\)is rendered in the preview.linenosornumbers: show line numbers.latex: render only thealgorithm2e-style view. Omit it to render only the code-block-style pseudocode view.bsyntax: use brace syntax for control blocks, such aswhile (condition) { ... }.
Use the command Markdown Algorithms: Copy Algorithm LaTeX from the Command Palette while your cursor is inside an algorithm fence, or while one or more algorithm fences are selected, to copy algorithm2e LaTeX.
Each rendered algorithm preview also includes a Copy LaTeX action in its caption. If a fence has a label, the preview exposes it as a clickable anchor, so links such as [Euclid](#markdown-algorithm-alg-euclid) can jump to label="alg:euclid".
Settings
markdownAlgorithms.defaultTitle: default caption when a fence does not settitleorcaption.markdownAlgorithms.defaultLineNumbers: show line numbers unless a fence setslinenos=falseornumbers=false.markdownAlgorithms.defaultLatex: use the LaTeX-style preview unless a fence setslatex=false.markdownAlgorithms.defaultBraceSyntax: parse brace syntax unless a fence setsbsyntax=false.
Inside algorithm steps, common pseudocode operators are rendered as math symbols:
<-renders as←and exports as\leftarrow{}.->renders as→and exports as\rightarrow{}.<=,>=, and!=render as≤,≥, and≠.
The preview also highlights common pseudocode keywords, function calls, numbers, quoted strings, and inline comments.
Brace syntax example:
```algorithm title="Euclid" input="integers \(a, b\)" output="\(\text{gcd}(a,b)\)" linenos bsyntax
while (b != 0) {
r <- a mod b;
a <- b;
b <- r;
}
return a;
```
Brace syntax also supports function, procedure, and repeat / until blocks:
```algorithm title="Repeat Example" bsyntax
function gcd(a, b) {
repeat {
a <- b;
} until (a == b);
}
```