├── examples ├── book │ ├── _extensions │ ├── _metadata.yml │ ├── index.qmd │ ├── 01-introduction.qmd │ ├── _quarto.yml │ └── 02-examples.qmd ├── beamer │ ├── _extensions │ └── beamer.qmd ├── simple │ ├── _extensions │ └── simple.qmd └── cross-reference │ ├── _extensions │ ├── _metadata.yml │ ├── index.qmd │ ├── 01-introduction.qmd │ ├── 02-examples.qmd │ └── _quarto.yml ├── screenshots ├── html-document.png └── pdf-document.png ├── _extensions └── pseudocode │ ├── _extension.yml │ ├── pseudocode.min.css │ ├── pseudocode.lua │ └── pseudocode.min.js ├── .gitignore ├── LICENSE ├── CHANGELOG.md ├── README.zh.md └── README.md /examples/book/_extensions: -------------------------------------------------------------------------------- 1 | ../../_extensions -------------------------------------------------------------------------------- /examples/beamer/_extensions: -------------------------------------------------------------------------------- 1 | ../../_extensions -------------------------------------------------------------------------------- /examples/simple/_extensions: -------------------------------------------------------------------------------- 1 | ../../_extensions -------------------------------------------------------------------------------- /examples/cross-reference/_extensions: -------------------------------------------------------------------------------- 1 | ../../_extensions -------------------------------------------------------------------------------- /screenshots/html-document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leovan/quarto-pseudocode/HEAD/screenshots/html-document.png -------------------------------------------------------------------------------- /screenshots/pdf-document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leovan/quarto-pseudocode/HEAD/screenshots/pdf-document.png -------------------------------------------------------------------------------- /examples/cross-reference/_metadata.yml: -------------------------------------------------------------------------------- 1 | pseudocode: 2 | caption-prefix: "Algorithm" 3 | reference-prefix: "Algorithm" 4 | caption-number: false 5 | -------------------------------------------------------------------------------- /examples/book/_metadata.yml: -------------------------------------------------------------------------------- 1 | pseudocode: 2 | caption-prefix: "Algorithm" 3 | reference-prefix: "Algorithm" 4 | caption-number: true 5 | caption-align: "right" 6 | -------------------------------------------------------------------------------- /_extensions/pseudocode/_extension.yml: -------------------------------------------------------------------------------- 1 | title: Pseudocode 2 | author: 范叶亮 | Leo Van 3 | version: 1.2.0 4 | quarto-required: ">=1.4.0" 5 | contributes: 6 | filters: 7 | - pseudocode.lua 8 | -------------------------------------------------------------------------------- /examples/book/index.qmd: -------------------------------------------------------------------------------- 1 | # Preface {.unnumbered .unlisted} 2 | 3 | This is a Quarto Pseudocode Extension Example. 4 | 5 | To learn more about Quarto Pseudocode Extension, please visit . 6 | -------------------------------------------------------------------------------- /examples/cross-reference/index.qmd: -------------------------------------------------------------------------------- 1 | # Preface {.unnumbered .unlisted} 2 | 3 | This is a Quarto Pseudocode Extension Example. 4 | 5 | To learn more about Quarto Pseudocode Extension, please visit . 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # R 2 | .Rhistory 3 | .Rapp.history 4 | .RData 5 | .Rproj.user/ 6 | 7 | # Quarto 8 | .quarto/ 9 | /examples/**/*.md 10 | /examples/**/*.html 11 | /examples/**/*.tex 12 | /examples/**/*.pdf 13 | /examples/**/site_libs 14 | /examples/**/.gitignore 15 | *_files/ 16 | _book 17 | 18 | # Lua 19 | /.luarc.json 20 | 21 | # Tex 22 | /*.tex 23 | *.aux 24 | *.lof 25 | *.lo* 26 | *.fls 27 | *.out 28 | *.toc 29 | *.fmt 30 | *.fot 31 | *.cb 32 | *.cb2 33 | .*.lb 34 | *.idx 35 | *.ilg 36 | *.ind 37 | *.bbl 38 | *.bcf 39 | *.blg 40 | *-blx.aux 41 | *-blx.bib 42 | *.run.xml 43 | *.fdb_latexmk 44 | *.synctex 45 | *.synctex(busy) 46 | *.synctex.gz 47 | *.synctex.gz(busy) 48 | *.pdfsync 49 | -------------------------------------------------------------------------------- /examples/cross-reference/01-introduction.qmd: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Quicksort algorithm is shown as @alg-quicksort (using `@alg-quicksort`). 4 | 5 | ::: {#alg-quicksort} 6 | ```pseudocode 7 | #| html-indent-size: "1.2em" 8 | #| html-comment-delimiter: "//" 9 | #| html-line-number: true 10 | #| html-line-number-punc: ":" 11 | #| html-no-end: false 12 | 13 | \begin{algorithm} 14 | \begin{algorithmic} 15 | \Procedure{Quicksort}{$A, p, r$} 16 | \If{$p < r$} 17 | \State $q = $ \Call{Partition}{$A, p, r$} 18 | \State \Call{Quicksort}{$A, p, q - 1$} 19 | \State \Call{Quicksort}{$A, q + 1, r$} 20 | \EndIf 21 | \EndProcedure 22 | \Procedure{Partition}{$A, p, r$} 23 | \State $x = A[r]$ 24 | \State $i = p - 1$ 25 | \For{$j = p$ \To $r - 1$} 26 | \If{$A[j] < x$} 27 | \State $i = i + 1$ 28 | \State exchange 29 | $A[i]$ with $A[j]$ 30 | \EndIf 31 | \State exchange $A[i]$ with $A[r]$ 32 | \EndFor 33 | \EndProcedure 34 | \end{algorithmic} 35 | \end{algorithm} 36 | ``` 37 | 38 | Quicksort 39 | ::: 40 | -------------------------------------------------------------------------------- /examples/book/01-introduction.qmd: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Quicksort algorithm is shown as @algo-quicksort. 4 | 5 | ```pseudocode 6 | #| label: algo-quicksort 7 | #| html-indent-size: "1.2em" 8 | #| html-comment-delimiter: "//" 9 | #| html-line-number: true 10 | #| html-line-number-punc: ":" 11 | #| html-no-end: false 12 | #| pdf-placement: "htb!" 13 | #| pdf-line-number: true 14 | 15 | \begin{algorithm} 16 | \caption{Quicksort} 17 | \begin{algorithmic} 18 | \Procedure{Quicksort}{$A, p, r$} 19 | \If{$p < r$} 20 | \State $q = $ \Call{Partition}{$A, p, r$} 21 | \State \Call{Quicksort}{$A, p, q - 1$} 22 | \State \Call{Quicksort}{$A, q + 1, r$} 23 | \EndIf 24 | \EndProcedure 25 | \Procedure{Partition}{$A, p, r$} 26 | \State $x = A[r]$ 27 | \State $i = p - 1$ 28 | \For{$j = p$ \To $r - 1$} 29 | \If{$A[j] < x$} 30 | \State $i = i + 1$ 31 | \State exchange 32 | $A[i]$ with $A[j]$ 33 | \EndIf 34 | \State exchange $A[i]$ with $A[r]$ 35 | \EndFor 36 | \EndProcedure 37 | \end{algorithmic} 38 | \end{algorithm} 39 | ``` 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023-2025 范叶亮 | Leo Van 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /_extensions/pseudocode/pseudocode.min.css: -------------------------------------------------------------------------------- 1 | @import url(https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css);.ps-root{font-family:KaTeX_Main,'Times New Roman',Times,serif;font-size:1em;font-weight:100;-webkit-font-smoothing:antialiased!important}.ps-root .ps-algorithm{margin:.8em 0;border-top:3px solid #000;border-bottom:2px solid #000}.ps-root .ps-algorithm.with-caption>.ps-line:first-child{border-bottom:2px solid #000}.ps-root .katex{text-indent:0;font-size:1em}.ps-root .MathJax,.ps-root .MathJax_CHTML{text-indent:0;font-size:1em!important}.ps-root .ps-line{margin:0;padding:0;line-height:1.2}.ps-root .ps-funcname{font-family:KaTeX_Main,'Times New Roman',Times,serif;font-weight:400;font-variant:small-caps;font-style:normal;text-transform:none}.ps-root .ps-keyword{font-family:KaTeX_Main,'Times New Roman',Times,serif;font-weight:700;font-variant:normal;font-style:normal;text-transform:none}.ps-root .ps-comment{font-family:KaTeX_Main,'Times New Roman',Times,serif;font-weight:400;font-variant:normal;font-style:normal;text-transform:none}.ps-root .ps-linenum{font-size:.8em;line-height:1em;width:1.6em;text-align:right;display:inline-block;position:relative;padding-right:.3em}.ps-root .ps-algorithmic.with-linenum .ps-line.ps-code{text-indent:-1.6em}.ps-root .ps-algorithmic.with-linenum .ps-line.ps-code>span{text-indent:0}.ps-root .ps-algorithmic.with-scopelines div.ps-block{border-left-style:solid;border-left-width:.1em;padding-left:.6em}.ps-root .ps-algorithmic.with-scopelines>div.ps-block{border-left:none} -------------------------------------------------------------------------------- /examples/beamer/beamer.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Quarto Pseudocode Extension Example" 3 | filters: 4 | - pseudocode 5 | pseudocode: 6 | caption-prefix: "Algorithm" 7 | reference-prefix: "Algorithm" 8 | caption-number: true 9 | format: 10 | beamer: 11 | include-in-header: 12 | text: | 13 | \usepackage{xeCJK} 14 | pdf-engine: xelatex 15 | keep-tex: true 16 | --- 17 | 18 | ## Test atoms 19 | 20 | Test atoms is shown as @algo-test-atoms. 21 | 22 | \renewcommand{\Return}{\State \textbf{return}~} 23 | \newcommand{\Print}{\State \textbf{print}~} 24 | \newcommand{\Break}{\State \textbf{break}} 25 | \newcommand{\Continue}{\State \textbf{continue}} 26 | \newcommand{\True}{\textbf{true}} 27 | \newcommand{\False}{\textbf{false}} 28 | \renewcommand{\And}{\textbf{and}~} 29 | \newcommand{\Or}{\textbf{or}~} 30 | \renewcommand{\Not}{\textbf{not}~} 31 | \newcommand{\To}{\textbf{to}~} 32 | \newcommand{\DownTo}{\textbf{downto}~} 33 | 34 | ```pseudocode 35 | #| label: algo-test-atoms 36 | #| html-line-number: false 37 | #| html-no-end: true 38 | #| pdf-line-number: false 39 | #| pdf-placement: "H" 40 | 41 | \begin{algorithm} 42 | \caption{Test atoms} 43 | \begin{algorithmic} 44 | \State \textbf{Specials:} \{ \} \$ \& \# \% \_ 45 | \State \textbf{Bools:} \And \Or \Not \True \False 46 | \State \textbf{Carriage return:} first line \\ second line 47 | \State \textbf{Text-symbols:} \textbackslash 48 | \State \textbf{Quote-symbols:} `single quotes', ``double quotes'' 49 | \State \textbf{Math:} $(\mathcal{C}_m)$, $i \gets i + 1$, $E=mc^2$, \( x^n + y^n = z^n \), $\$$, \(\$\) 50 | \end{algorithmic} 51 | \end{algorithm} 52 | ``` 53 | -------------------------------------------------------------------------------- /examples/cross-reference/02-examples.qmd: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## Test cross reference in different files 4 | 5 | Quicksort algorithm is shown as @alg-quicksort (using `@alg-quicksort`). Quarto custom cross reference in different files works both with `html` and `pdf` format. 6 | 7 | ## Test Quarto custom cross reference 8 | 9 | Test 1 is shown as @alg-test-1 (using `@alg-test-1`). 10 | 11 | ::: {#alg-test-1} 12 | ```pseudocode 13 | #| html-line-number: false 14 | #| pdf-line-number: false 15 | 16 | \begin{algorithm} 17 | \begin{algorithmic} 18 | \Procedure{Test-Quarto-Custom-Cross-Reference}{} 19 | \State QUARTO CUSTOM CROSS REFERENCE 20 | \EndProcedure 21 | \end{algorithmic} 22 | \end{algorithm} 23 | ``` 24 | 25 | Test Quarto custom cross reference 1 26 | ::: 27 | 28 | Test 2 is shown as @alg-test-2 (using `@alg-test-2`). 29 | 30 | ::: {#alg-test-2} 31 | ```pseudocode 32 | #| html-line-number: false 33 | #| pdf-line-number: false 34 | 35 | \begin{algorithm} 36 | \begin{algorithmic} 37 | \Procedure{Test-Quarto-Custom-Cross-Reference}{} 38 | \State QUARTO CUSTOM CROSS REFERENCE 39 | \EndProcedure 40 | \end{algorithmic} 41 | \end{algorithm} 42 | ``` 43 | ::: 44 | 45 | Test 3 is shown as @alg-test-3 (using `@alg-test-3`). 46 | 47 | ::: {#alg-test-3} 48 | ```pseudocode 49 | #| html-line-number: false 50 | #| pdf-line-number: false 51 | 52 | \begin{algorithm} 53 | \begin{algorithmic} 54 | \Procedure{Test-Quarto-Custom-Cross-Reference}{} 55 | \State QUARTO CUSTOM CROSS REFERENCE 56 | \EndProcedure 57 | \end{algorithmic} 58 | \end{algorithm} 59 | ``` 60 | 61 | Test Quarto custom cross reference 3 62 | ::: 63 | 64 | \listofalgorithms{} 65 | -------------------------------------------------------------------------------- /examples/book/_quarto.yml: -------------------------------------------------------------------------------- 1 | project: 2 | type: book 3 | 4 | book: 5 | title: "Quarto Pseudocode Extension Example" 6 | author: "范叶亮 | Leo Van" 7 | chapters: 8 | - index.qmd 9 | - 01-introduction.qmd 10 | - 02-examples.qmd 11 | 12 | filters: 13 | - pseudocode 14 | 15 | link-citations: true 16 | 17 | format: 18 | html: 19 | include-in-header: 20 | text: | 21 | 38 | 39 | pdf: 40 | include-in-header: 41 | text: | 42 | \usepackage{xeCJK} 43 | include-before-body: 44 | text: | 45 | \renewcommand{\Return}{\State \textbf{return}~} 46 | \newcommand{\Print}{\State \textbf{print}~} 47 | \newcommand{\Break}{\State \textbf{break}} 48 | \newcommand{\Continue}{\State \textbf{continue}} 49 | \newcommand{\True}{\textbf{true}} 50 | \newcommand{\False}{\textbf{false}} 51 | \renewcommand{\And}{\textbf{and}~} 52 | \newcommand{\Or}{\textbf{or}~} 53 | \renewcommand{\Not}{\textbf{not}~} 54 | \newcommand{\To}{\textbf{to}~} 55 | \newcommand{\DownTo}{\textbf{downto}~} 56 | pdf-engine: xelatex 57 | toc-depth: 2 58 | keep-tex: true 59 | -------------------------------------------------------------------------------- /examples/cross-reference/_quarto.yml: -------------------------------------------------------------------------------- 1 | project: 2 | type: book 3 | 4 | book: 5 | title: "Quarto Pseudocode Extension Example" 6 | author: "范叶亮 | Leo Van" 7 | chapters: 8 | - index.qmd 9 | - 01-introduction.qmd 10 | - 02-examples.qmd 11 | 12 | filters: 13 | - pseudocode 14 | 15 | crossref: 16 | custom: 17 | - kind: float 18 | key: alg 19 | reference-prefix: "Algorithm" 20 | caption-prefix: "Algorithm" 21 | latex-env: alg 22 | latex-list-of-description: Algorithm 23 | 24 | link-citations: true 25 | 26 | format: 27 | html: 28 | include-in-header: 29 | text: | 30 | 47 | 48 | pdf: 49 | include-in-header: 50 | text: | 51 | \usepackage{xeCJK} 52 | include-before-body: 53 | text: | 54 | \renewcommand{\Return}{\State \textbf{return}~} 55 | \newcommand{\Print}{\State \textbf{print}~} 56 | \newcommand{\Break}{\State \textbf{break}} 57 | \newcommand{\Continue}{\State \textbf{continue}} 58 | \newcommand{\True}{\textbf{true}} 59 | \newcommand{\False}{\textbf{false}} 60 | \renewcommand{\And}{\textbf{and}~} 61 | \newcommand{\Or}{\textbf{or}~} 62 | \renewcommand{\Not}{\textbf{not}~} 63 | \newcommand{\To}{\textbf{to}~} 64 | \newcommand{\DownTo}{\textbf{downto}~} 65 | pdf-engine: xelatex 66 | toc-depth: 2 67 | keep-tex: true 68 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.2.0](https://github.com/leovan/quarto-pseudocode/compare/v1.1.3...v1.2.0) (2025-10-01) 4 | 5 | ### Bug Fixes 6 | 7 | - Make filter compatible with Quarto 1.8. ([#11](https://github.com/leovan/quarto-pseudocode/issues/11)) 8 | 9 | > [!WARNING] 10 | > 11 | > 1. Change the prefix from `alg-` to `algo-` when using build-in cross reference to make it compatible with Quarto 1.8. 12 | > 1. Change the prefix from `algo-` to `alg-` when using Quarto custom cross reference to make it compatible with Quarto 1.8. 13 | 14 | ### Features 15 | 16 | - Optimize style when there is no caption. 17 | - Add parameter `caption-align` to control caption alignment. 18 | 19 | ## [1.1.3](https://github.com/leovan/quarto-pseudocode/compare/v1.1.2...v1.1.3) (2025-09-03) 20 | 21 | ### Bug Fixes 22 | 23 | - Fix wrong comment delimiter. ([#10](https://github.com/leovan/quarto-pseudocode/issues/10)) 24 | 25 | ## [1.1.2](https://github.com/leovan/quarto-pseudocode/compare/v1.1.1...v1.1.2) (2025-08-02) 26 | 27 | ### Bug Fixes 28 | 29 | - Respect options in meta data. ([#8](https://github.com/leovan/quarto-pseudocode/issues/8)) 30 | - Fix alignment when using Quarto custom cross reference. 31 | - Fix `pdf-line-number` not working for `pdf` document. 32 | 33 | ## [1.1.1](https://github.com/leovan/quarto-pseudocode/compare/v1.1.0...v1.1.1) (2024-11-03) 34 | 35 | ### Bug Fixes 36 | 37 | - Remove tailing space after the cross reference. 38 | 39 | ## [1.1.0](https://github.com/leovan/quarto-pseudocode/compare/v1.0.0...v1.1.0) (2024-06-08) 40 | 41 | ### Features 42 | 43 | - Add Quarto custom cross reference support. 44 | - Add build-in cross reference with ["float" cross reference](https://quarto.org/docs/authoring/cross-references.html#floats) support. 45 | - Add parameter `caption-number` to show number in build-in caption. 46 | - Automatically add chapter level to number in build-in caption for `book` type project. 47 | 48 | ### Breaking Changes 49 | 50 | - Change parameter `alg-title` to `caption-prefix` and `alg-prefix` to `reference-prefix` to keep consistent with Quarto custom cross reference. 51 | 52 | ### Bug Fixes 53 | 54 | - Fix caption number with chapter level not working due to typo. 55 | 56 | ## 1.0.0 (2023-08-10) 57 | 58 | ### Features 59 | 60 | - First release version. 61 | -------------------------------------------------------------------------------- /examples/book/02-examples.qmd: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## Test cross reference in different files 4 | 5 | Quicksort algorithm is shown as @algo-quicksort. Build-in cross reference in different files works only with `pdf` format. 6 | 7 | ## Test text-style 8 | 9 | Test text-style is shown as @algo-test-text-style. 10 | 11 | ```pseudocode 12 | #| label: algo-test-text-style 13 | #| html-indent-size: "1.2em" 14 | #| html-comment-delimiter: "//" 15 | #| html-line-number: true 16 | #| html-line-number-punc: ":" 17 | #| html-no-end: false 18 | #| pdf-placement: "htb!" 19 | #| pdf-line-number: true 20 | 21 | \begin{algorithm} 22 | \caption{Test text-style} 23 | \begin{algorithmic} 24 | \Require some preconditions 25 | \Ensure some postconditions 26 | \Procedure{Test-Declarations}{} 27 | \State font families: {\sffamily sffamily, \ttfamily ttfamily, \normalfont normalfont, \rmfamily rmfamily.} 28 | \State font weights: {normal weight, \bfseries bold, \mdseries medium. } 29 | \State font shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape.} 30 | \State font sizes: \tiny tiny \scriptsize scriptsize \footnotesize 31 | footnotesize \small small \normalsize normal \large large \Large Large 32 | \LARGE LARGE \huge huge \Huge Huge \normalsize 33 | \EndProcedure 34 | \Procedure{Test-Commands}{} 35 | \State \textnormal{textnormal,} \textrm{textrm,} \textsf{textsf,} \texttt{texttt.} 36 | \State \textbf{textbf,} \textmd{textmd.} 37 | \State \textup{textup,} \textit{textit,} \textsc{textsc,} \textsl{textsl.} 38 | \State \uppercase{uppercase,} \lowercase{LOWERCASE.} 39 | \EndProcedure 40 | \Procedure{Test-Colors}{} 41 | \State \Comment{feature not implemented} 42 | \EndProcedure 43 | \end{algorithmic} 44 | \end{algorithm} 45 | ``` 46 | 47 | ## Test atoms 48 | 49 | Test atoms is shown as @algo-test-atoms. 50 | 51 | ```pseudocode 52 | #| label: algo-test-atoms 53 | #| html-line-number: false 54 | #| html-no-end: false 55 | #| pdf-line-number: false 56 | 57 | \begin{algorithm} 58 | \caption{Test atoms} 59 | \begin{algorithmic} 60 | \State \textbf{Specials:} \{ \} \$ \& \# \% \_ 61 | \State \textbf{Bools:} \And \Or \Not \True \False 62 | \State \textbf{Carriage return:} first line \\ second line 63 | \State \textbf{Text-symbols:} \textbackslash 64 | \State \textbf{Quote-symbols:} `single quotes', ``double quotes'' 65 | \State \textbf{Math:} $(\mathcal{C}_m)$, $i \gets i + 1$, $E=mc^2$, \( x^n + y^n = z^n \), $\$$, \(\$\) 66 | \end{algorithmic} 67 | \end{algorithm} 68 | ``` 69 | 70 | ## Test control blocks 71 | 72 | Test control blocks is shown as @algo-test-control-blocks-part-1 and @algo-test-control-blocks-part-2. 73 | 74 | ```pseudocode 75 | #| label: algo-test-control-blocks-part-1 76 | 77 | \begin{algorithm} 78 | \caption{Test control blocks - Part 1} 79 | \begin{algorithmic} 80 | \Procedure{Test-If}{} 81 | \If{} 82 | \State 83 | \ElsIf{} 84 | \State 85 | \Else 86 | \State 87 | \EndIf 88 | \EndProcedure 89 | \Procedure{Test-For}{$n$} 90 | \State $i \gets 0$ 91 | \For{$i < n$} 92 | \Print $i$ 93 | \State $i \gets i + 1$ 94 | \EndFor 95 | \EndProcedure 96 | \Procedure{Test-For-To}{$n$} 97 | \State $i \gets 0$ 98 | \For{$i$ \To $n$} 99 | \Print $i$ 100 | \EndFor 101 | \EndProcedure 102 | \Procedure{Test-For-DownTo}{$n$} 103 | \For{$i \gets n$ \DownTo $0$} 104 | \Print $i$ 105 | \EndFor 106 | \EndProcedure 107 | \Procedure{Test-For-All}{$n$} 108 | \ForAll{$i \in \{0, 1, \cdots, n\}$} 109 | \Print $i$ 110 | \EndFor 111 | \EndProcedure 112 | \end{algorithmic} 113 | \end{algorithm} 114 | ``` 115 | 116 | ```pseudocode 117 | #| label: algo-test-control-blocks-part-2 118 | 119 | \begin{algorithm} 120 | \caption{Test control blocks - Part 2} 121 | \begin{algorithmic} 122 | \Procedure{Test-While}{$n$} 123 | \State $i \gets 0$ 124 | \While{$i < n$} 125 | \Print $i$ 126 | \State $i \gets i + 1$ 127 | \EndWhile 128 | \EndProcedure 129 | \Procedure{Test-Repeat}{$n$} 130 | \State $i \gets 0$ 131 | \Repeat 132 | \Print $i$ 133 | \State $i \gets i + 1$ 134 | \Until{$i>n$} 135 | \EndProcedure 136 | \Procedure{Test-Break-Continue}{$n$} 137 | \For{$i = 0$ \To $2n$} 138 | \If{$i < n/2$} 139 | \Continue 140 | \ElsIf{$i > n$} 141 | \Break 142 | \EndIf 143 | \Print $i$ 144 | \EndFor 145 | \EndProcedure 146 | \end{algorithmic} 147 | \end{algorithm} 148 | ``` 149 | 150 | ## Test statements and comments 151 | 152 | Test statements and comments is shown as @algo-test-statements-and-comments. 153 | 154 | ```pseudocode 155 | #| label: algo-test-statements-and-comments 156 | 157 | \begin{algorithm} 158 | \caption{Test statements and comments} 159 | \begin{algorithmic} 160 | \Procedure{Test-Statements}{} 161 | \State This line is a normal statement 162 | \Print \texttt{`this is print statement'} 163 | \Return $retval$ 164 | \EndProcedure 165 | \Procedure{Test-Comments}{} \Comment{comment for Procedure} 166 | \State a statement \Comment{inline comment} 167 | \State \Comment{line comment} 168 | \If{some condition}\Comment{comment for if} 169 | \Return \True \Comment{another inline comment} 170 | \Else \Comment{comment for else} 171 | \Return \False \Comment{yet another inline comment} 172 | \EndIf 173 | \EndProcedure 174 | \end{algorithmic} 175 | \end{algorithm} 176 | ``` 177 | 178 | \listofalgorithms{} 179 | -------------------------------------------------------------------------------- /README.zh.md: -------------------------------------------------------------------------------- 1 | # Quarto 伪代码扩展 2 | 3 | ![Release](https://img.shields.io/github/release/leovan/quarto-pseudocode.svg) 4 | ![License](https://img.shields.io/github/license/leovan/quarto-pseudocode.svg) 5 | ![Issues](https://img.shields.io/github/issues/leovan/quarto-pseudocode.svg) 6 | 7 | --- 8 | 9 | 🇺🇸 [README](README.md) | 🇨🇳 [中文说明](README.zh.md) 10 | 11 | 一个用于在 `html` 和 `pdf` 文档中渲染伪代码的 Quarto 扩展。`html` 文档基于 [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) 实现,`pdf` 文档基于 `algorithm` 和 `algorithmicx` 包实现。 12 | 13 | ## 安装 14 | 15 | ```bash 16 | quarto add leovan/quarto-pseudocode 17 | ``` 18 | 19 | 这将在 `_extensions` 子目录中安装本插件。如果使用版本控制,请检入到此目录。 20 | 21 | ## 使用 22 | 23 | ### 添加扩展 24 | 25 | 将如下内容添加到文档的头部或 `_quarto.yml` 文件中: 26 | 27 | ```yml 28 | filters: 29 | - pseudocode 30 | ``` 31 | 32 | ### 伪代码块 33 | 34 | 将伪代码添加到标记为 `pseudocode` 的代码块中: 35 | 36 | ```` 37 | ```pseudocode 38 | #| html-indent-size: "1.2em" 39 | #| html-comment-delimiter: "//" 40 | #| html-line-number: true 41 | #| html-line-number-punc: ":" 42 | #| html-no-end: false 43 | #| pdf-placement: "htb!" 44 | #| pdf-line-number: true 45 | 46 | \begin{algorithm} 47 | \caption{Quicksort} 48 | \begin{algorithmic} 49 | \Procedure{Quicksort}{$A, p, r$} 50 | \If{$p < r$} 51 | \State $q = $ \Call{Partition}{$A, p, r$} 52 | \State \Call{Quicksort}{$A, p, q - 1$} 53 | \State \Call{Quicksort}{$A, q + 1, r$} 54 | \EndIf 55 | \EndProcedure 56 | \Procedure{Partition}{$A, p, r$} 57 | \State $x = A[r]$ 58 | \State $i = p - 1$ 59 | \For{$j = p$ \To $r - 1$} 60 | \If{$A[j] < x$} 61 | \State $i = i + 1$ 62 | \State exchange 63 | $A[i]$ with $A[j]$ 64 | \EndIf 65 | \State exchange $A[i]$ with $A[r]$ 66 | \EndFor 67 | \EndProcedure 68 | \end{algorithmic} 69 | \end{algorithm} 70 | ``` 71 | ```` 72 | 73 | > [!IMPORTANT] 74 | > 使用大驼峰式关键词,而非全大写关键词。 75 | 76 | ### 参数配置 77 | 78 | 全局参数如下: 79 | 80 | | 参数 | 默认值 | 格式 | 注释 | 81 | | ------------------ | ----------- | ---- | ------------------------------------------- | 82 | | `caption-prefix` | "Algorithm" | 全部 | 标题前缀 | 83 | | `reference-prefix` | "Algorithm" | 全部 | 引用前缀 | 84 | | `caption-number` | true | 全部 | 显示内置标题数字 | 85 | | `caption-align` | "left" | 全部 | 内置标题对齐方式,"left"、"center"或"right" | 86 | 87 | 将参数添加到文档的头部或 `_metadata.yml` 文件中,例如: 88 | 89 | ```yml 90 | pseudocode: 91 | caption-prefix: "算法" 92 | reference-prefix: "算法" 93 | caption-number: true 94 | caption-align: "left" 95 | ``` 96 | 97 | 伪代码参数格式类似 R 和 Python 代码,如下: 98 | 99 | | 参数 | 默认值 | 格式 | 注释 | 100 | | ------------------------ | ------- | ------ | ---------------------------------------- | 101 | | `label` | | 全部 | 用于引用的标签,如果有必须以 `alg-` 开头 | 102 | | `html-indent-size` | "1.2em" | `html` | pseudocode.js 中的 `indentSize` | 103 | | `html-comment-delimiter` | "//" | `html` | pseudocode.js 中的 `commentDelimiter` | 104 | | `html-line-number` | true | `html` | pseudocode.js 中的 `lineNumber` | 105 | | `html-line-number-punc` | ":" | `html` | pseudocode.js 中的 `lineNumberPunc` | 106 | | `html-no-end` | false | `html` | pseudocode.js 中的 `noEnd` | 107 | | `pdf-placement` | "H" | `pdf` | 伪代码在文本中的放置方式 | 108 | | `pdf-line-number` | true | `pdf` | 是否显示行号 | 109 | 110 | > [!NOTE] 111 | > 112 | > 1. 如果在伪代码块中直接指定方式方式,例如 `\begin{algorithm}[htb!]`,则 `pdf-placement` 参数将被忽略。 113 | > 2. 如果在伪代码块中直接指定是否显示行号,例如 `\begin{algorithmic}[1]`,则 `pdf-line-number` 参数将被忽略。 114 | > 3. 所有这些改变不会影响 `html` 文档,建议使用参数选项而非直接修改伪代码。 115 | 116 | 对于 `html` 文档,[pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) 使用 [KaTeX](https://katex.org/) 或 [MathJax](https://www.mathjax.org/) 渲染数学公式。本扩展在 html body 之后添加 [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js),因此你需要在 html body 之前或 html header 中初始化 [KaTeX](https://katex.org/) 或 [MathJax](https://www.mathjax.org/)。将相关内容添加到文档的头部或 `_quarto.yml` 文件中: 117 | 118 | ```yml 119 | format: 120 | html: 121 | include-in-header: 122 | text: | 123 | 140 | 141 | ``` 142 | 143 | 对于 `pdf` 文档,在 `book` 类型项目中将第 `x` 章中伪代码标题序号将由 `Algorithm n` 变为 `Algorithm x.n`。将 `\algrenewcommand{\algorithmiccomment}[1]{ #1}` 添加到文档的头部或 `_quarto.yml` 文件中可以改变注释的显示方式: 144 | 145 | ```yml 146 | format: 147 | pdf: 148 | include-before-body: 149 | text: | 150 | \algrenewcommand{\algorithmiccomment}[1]{\hskip3em$\rightarrow$ #1} 151 | ``` 152 | 153 | ### 交叉引用 154 | 155 | #### 内置交叉引用 156 | 157 | 在伪代码块中设置 `label`,并且需要以 `algo-` 开头: 158 | 159 | > [!WARNING] 160 | > 从 Quarto 1.8 开始,`alg` 已经成为交叉引用的保留前缀。 161 | 162 | ```` 163 | ```pseudocode 164 | #| label: algo-quicksort 165 | ... 166 | 167 | \begin{algorithm} 168 | \caption{Quicksort} 169 | \begin{algorithmic} 170 | ... 171 | \end{algorithmic} 172 | \end{algorithm} 173 | ``` 174 | ```` 175 | 176 | 在正文中使用 `@