You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `pdf-placement` | | `pdf` | placement of the pseudocode in text |
105
+
| `pdf-placement` | "H" | `pdf` | placement of the pseudocode in text |
99
106
| `pdf-line-number` | true | `pdf` | show line number |
100
107
101
108
> [!NOTE]
102
109
>
103
110
> 1. If set the placement in pseudocode, such as `\begin{algorithm}[htb!]`, then `pdf-placement` option will be ignored.
104
111
> 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.
106
113
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.
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:
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
155
153
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.
160
176
```
161
177
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.
163
241
164
242
## Examples
165
243
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).
0 commit comments