Build error: no body? (there is one)
Proliecan opened this issue · 2 comments
Proliecan commented
#let pseudocode(content:[], title: "", parameters: "", additionalKeywords: none, caption: none, _label: "") = {
[
#figure(
align(left,
algo(
body: content,
title: title,
parameters: parameters,
keywords: _algo-default-keywords + ("assert", "clone") + additionalKeywords,
comment-prefix: [#sym.triangle.stroked.r ],
comment-styles: (fill: rgb(100%, 0%, 0%)),
)
),
caption: caption,
supplement: [Pseudocode],
kind: "pseudocode",
) #label(_label)
]
v(0.2cm)
}
fails to build when used as function.
error: missing argument: body
┌─ /assets/template/template.typ:400:12
│
400 │ algo(
│ ╭─────────────^
401 │ │ body: content,
402 │ │ title: title,
403 │ │ parameters: parameters,
· │
406 │ │ comment-styles: (fill: rgb(100%, 0%, 0%)),
407 │ │ )
│ ╰─────────^
- What am I doing wrong?
- Could this b a bug?
platformer commented
The reason this fails is because body
has no default value in algo
, and thus it must be passed as a positional argument:
#let pseudocode(content:[], title: "", parameters: (), additionalKeywords: none, caption: none, _label: "") = {
[
#figure(
align(left,
algo(
content, // <-- HERE
title: title,
parameters: parameters,
keywords: _algo-default-keywords + ("assert", "clone") + additionalKeywords,
comment-prefix: [#sym.triangle.stroked.r ],
comment-styles: (fill: rgb(100%, 0%, 0%)),
)
),
caption: caption,
supplement: [Pseudocode],
kind: "pseudocode",
) #label(_label)
]
v(0.2cm)
}
This is just an oddity with the way Typst handles parameters in comparison to other scripting languages like Python. The Typst developers are considering alternative schemes that would allow function calls to be more flexible, but for now this is just how it is.
Side note: I also changed pseudocode
's default value for parameters
to ()
because algo
always expects it to be an array.
Proliecan commented
Thanks a lot!