Skip to content

Commit 9bb03d2

Browse files
committed
bump version to 1.1.0
1 parent c865ef2 commit 9bb03d2

File tree

17 files changed

+587
-124
lines changed

17 files changed

+587
-124
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
# Quarto
88
.quarto/
9+
/examples/**/*.md
910
/examples/**/*.html
1011
/examples/**/*.tex
11-
*.pdf
12+
/examples/**/*.pdf
13+
/examples/**/site_libs
14+
/examples/**/.gitignore
1215
*_files/
1316
_book
1417

@@ -19,8 +22,7 @@ _book
1922
/*.tex
2023
*.aux
2124
*.lof
22-
*.log
23-
*.lot
25+
*.lo*
2426
*.fls
2527
*.out
2628
*.toc
@@ -44,4 +46,3 @@ _book
4446
*.synctex.gz
4547
*.synctex.gz(busy)
4648
*.pdfsync
47-
/.quarto/

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Changelog
2+
3+
## [1.1.0](https://github.com/leovan/quarto-pseudocode/compare/v1.0.0...v1.1.0) (2024-06-08)
4+
5+
### Features
6+
7+
- Add Quarto custom cross reference support.
8+
- Add build-in cross reference with ["float" cross reference](https://quarto.org/docs/authoring/cross-references.html#floats) support.
9+
- Add parameter `caption-number` to show number in build-in caption.
10+
- Automatically add chapter level to number in build-in caption for `book` type project.
11+
12+
### Breaking Changes
13+
14+
- Change parameter `alg-title` to `caption-prefix` and `alg-prefix` to `reference-prefix` to keep consistent with Quarto custom cross reference.
15+
16+
### Bug Fixes
17+
18+
- Fix caption number with chapter level not working due to typo.
19+
20+
## 1.0.0 (2023-08-10)
21+
22+
### Features
23+
24+
- First release version.

README.md

Lines changed: 124 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ This will install the extension under the `_extensions` subdirectory. If you're
2020

2121
## Using
2222

23-
Put this in the header of your document, or in the `_quarto.yml` file.
23+
### Adding Extension
24+
25+
Add this in the header of your document, or in the `_quarto.yml` file:
2426

2527
```yml
2628
filters:
2729
- pseudocode
2830
```
2931
30-
Then you can put the pseudocode in a code block marked with `pseudocode`.
32+
### Pseudocode Block
33+
34+
Add the pseudocode in a code block marked with `pseudocode`:
3135

3236
````
3337
```pseudocode
34-
#| label: alg-quicksort
3538
#| html-indent-size: "1.2em"
3639
#| html-comment-delimiter: "//"
3740
#| html-line-number: true
@@ -67,25 +70,29 @@ Then you can put the pseudocode in a code block marked with `pseudocode`.
6770
```
6871
````
6972

70-
> [!NOTE]
73+
> [!IMPORTANT]
7174
> Use upper camel case format keyword rather than all uppercase format keyword.
7275

73-
Use `@<alg-label>` to do cross reference.
76+
### Parameters
7477

75-
```
76-
Quicksort algorithm is shown as @alg-quicksort.
77-
```
78+
Global parameters are show as below:
7879

79-
> [!NOTE]
80-
> For `book` type project, cross reference in different files is only available with `pdf` document.
80+
| Parameter | Default | Format | Description |
81+
| ------------------- | ----------- | ------ | ------------------------------- |
82+
| `caption-prefix` | "Algorithm" | all | prefix for caption |
83+
| `reference-prefix` | "Algorithm" | all | prefix for reference |
84+
| `caption-number` | true | all | show number in build-in caption |
8185

82-
Pseudocode and cross reference rendered in `html` and `pdf` document are shown as below.
86+
Add global parameters in the header of your document, or in the `_quarto.yml` file:
8387

84-
| `html` document | `pdf` document |
85-
| :--------------------------------: | :-------------------------------: |
86-
| ![](screenshots/html-document.png) | ![](screenshots/pdf-document.png) |
88+
```yml
89+
pseudocode:
90+
caption-prefix: "Algorithm"
91+
reference-prefix: "Algorithm"
92+
caption-number: true
93+
```
8794

88-
Parameters for pseudocode share the same format like R or Python code.
95+
Parameters for pseudocode share the same format like R or Python code:
8996

9097
| Parameter | Default | Format | Description |
9198
| ------------------------ | -------- | ------ | -------------------------------------------------------- |
@@ -95,20 +102,16 @@ Parameters for pseudocode share the same format like R or Python code.
95102
| `html-line-number` | true | `html` | `lineNumber` in pseudocode.js |
96103
| `html-line-number-punc` | ":" | `html` | `lineNumberPunc`in pseudocode.js |
97104
| `html-no-end` | false | `html` | `noEnd` in pseudocode.js |
98-
| `pdf-placement` | | `pdf` | placement of the pseudocode in text |
105+
| `pdf-placement` | "H" | `pdf` | placement of the pseudocode in text |
99106
| `pdf-line-number` | true | `pdf` | show line number |
100107

101108
> [!NOTE]
102109
>
103110
> 1. If set the placement in pseudocode, such as `\begin{algorithm}[htb!]`, then `pdf-placement` option will be ignored.
104111
> 2. If set show line number or not in pseudocode, such as `\begin{algorithmic}[1]`, then `pdf-line-number` option will be ignored.
105-
> 3. All these changes won't affect the output of `html` document. We recommend you use options rather than modify pseudocode directly.
112+
> 3. All these changes won't affect the output of `html` document. We recommend you set the parameters rather than modify pseudocode directly.
106113

107-
For `html` document:
108-
109-
[pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) render math formulas using either [KaTeX](https://katex.org/) or [MathJax](https://www.mathjax.org/). We add [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) after html body, thus you need initialize [KaTeX](https://katex.org/) or [MathJax](https://www.mathjax.org/) before html body or in html header.
110-
111-
For example, you can put this in the header of your document, or in the `_quarto.yml` file.
114+
For `html` document, [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) render math formulas using either [KaTeX](https://katex.org/) or [MathJax](https://www.mathjax.org/). We add [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js) after html body, thus you need initialize [KaTeX](https://katex.org/) or [MathJax](https://www.mathjax.org/) before html body or in html header. Add this in the header of your document, or in the `_quarto.yml` file.
112115

113116
```yml
114117
format:
@@ -135,12 +138,7 @@ format:
135138
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
136139
```
137140

138-
For `pdf` document:
139-
140-
1. `\numberwithin{algorithm}{chapter}` will add chapter level before pseudocode caption in `book` type project, like `x.n` in chapter `x`.
141-
2. `\algrenewcommand{\algorithmiccomment}[1]{<your value> #1}` will change the form in witch comments are displayed.
142-
143-
Put these in the header of your document, or in the `_quarto.yml` file.
141+
For `pdf` document, pseudocode caption in `book` type project will be changed from `Algorithm n` to `Algorithm x.n` in chapter `x`. Add `\algrenewcommand{\algorithmiccomment}[1]{<your value> #1}` in the header of your document, or in the `_quarto.yml` file will change the form in which comments are displayed:
144142

145143
```yml
146144
format:
@@ -151,21 +149,110 @@ format:
151149
\algrenewcommand{\algorithmiccomment}[1]{\hskip3em$\rightarrow$ #1}
152150
```
153151

154-
You can change the `Algorithm` word to native language, such as `算法` in Chinese, by putting this in the header of your document, or in the `_metadata.yml` file.
152+
### Cross Reference
155153

156-
```yml
157-
pseudocode:
158-
alg-title: "算法"
159-
alg-prefix: "算法"
154+
#### Build-in Cross Reference
155+
156+
Set the `label` in pseudocode, and it must start with `alg-`:
157+
158+
````
159+
```pseudocode
160+
#| label: alg-quicksort
161+
...
162+
163+
\begin{algorithm}
164+
\caption{Quicksort}
165+
\begin{algorithmic}
166+
...
167+
\end{algorithmic}
168+
\end{algorithm}
169+
```
170+
````
171+
172+
Use `@<label>` to do cross reference:
173+
174+
```
175+
Quicksort algorithm is shown as @alg-quicksort.
160176
```
161177

162-
`alg-title` is used for pseudocode caption and `alg-prefix` is used for cross reference.
178+
> [!WARNING]
179+
> For `book` type project, build-in cross reference in different files works only with `pdf` format.
180+
181+
#### Quarto Custom Cross Reference
182+
183+
Add custom cross reference for pseudocode in the header of your document, or in the `_quarto.yml` file:
184+
185+
```yaml
186+
crossref:
187+
custom:
188+
- kind: float
189+
key: algo
190+
reference-prefix: "Algorithm"
191+
caption-prefix: "Algorithm"
192+
latex-env: algo
193+
latex-list-of-description: Algorithm
194+
```
195+
196+
> [!IMPORTANT]
197+
> Do not set `key` to `alg`, which is used for build-in reference.
198+
199+
Use [Quarto custom cross reference](https://quarto.org/docs/authoring/cross-references-custom.html) to surround the pseudocode:
200+
201+
````
202+
::: {#algo-quicksort}
203+
204+
```pseudocode
205+
...
206+
207+
\begin{algorithm}
208+
\caption{Quicksort}
209+
\begin{algorithmic}
210+
...
211+
\end{algorithmic}
212+
\end{algorithm}
213+
```
214+
215+
Quicksort
216+
217+
:::
218+
````
219+
220+
> [!IMPORTANT]
221+
>
222+
> 1. Do not set `label` to avoid conflict with build-in cross reference.
223+
> 2. Set the global parameter `caption-no-number` to `true` to avoid show different numbers in pseudocode build-in caption and Quarto cross reference caption.
224+
> 3. Set both captions in pseudocode and Quarto custom cross reference to achieve best effect.
225+
226+
Use `@<label>` to do cross reference.
227+
228+
```
229+
Quicksort algorithm is shown as @algo-quicksort.
230+
```
231+
232+
#### Difference
233+
234+
1. Quarto custom cross reference will add an extra caption like figure, in which number may not be same as pseudocode build-in caption.
235+
2. Build-in cross reference in different files is only available with `pdf` document for `book` type project. Quarto custom cross reference works in both `html` and `pdf` document.
236+
237+
Now, expect cross reference in different files with `pdf` document for `book` type project, we strongly recommend use build-in cross reference to achieve best effect.
238+
239+
> [!CAUTION]
240+
> Do not use different type of cross reference in the same project.
163241
164242
## Examples
165243
166-
1. Single document (`html` and `pdf`): [examples/simple/simple.qmd](examples/simple/simple.qmd).
167-
2. Book document (`html` and `pdf`): [examples/book/_quarto.yml](examples/book/_quarto.yml).
168-
3. Beamer document (`pdf`): [examples/beamer/beamer.qmd](examples/beamer/beamer.qmd).
244+
Pseudocode and cross reference rendered in `html` and `pdf` document are shown as below.
245+
246+
| `html` document | `pdf` document |
247+
| :--------------------------------: | :-------------------------------: |
248+
| ![](screenshots/html-document.png) | ![](screenshots/pdf-document.png) |
249+
250+
More examples please refer:
251+
252+
1. Single document (`html` and `pdf`): [examples/simple](examples/simple).
253+
2. Book document (`html` and `pdf`): [examples/book](examples/book).
254+
3. Beamer document (`pdf`): [examples/beamer](examples/beamer).
255+
4. Cross reference example (`html` and `pdf`): [examples/cross-reference](examples/cross-reference).
169256
170257
## License
171258

0 commit comments

Comments
 (0)