#Figure numbering

10 messages · Page 1 of 1 (latest)

languid dagger
#

Hi there! I'm working on a thesis template, and have inherited some of the code. I'm trying to make a List of Figures, but I'm getting an error even from the numbering of the figures. This is the relevant part that gives the error:

  set figure(numbering: (..args) => {
    let chapter = counter(heading).display((..nums) => nums.pos().at(0))
    [#chapter.numbering("1", ..args.pos())]
  })

the error being:

Error: Command failed: typst compile "/Users/roaldarbol/Filen/Projects/templates/thesis-template/examples/example-myst/_build/temp/mystrCZDha/MyST-Thesis.typ"
error: type integer has no method `numbering`
   ┌─ _build/temp/mystrCZDha/typst-thesis.typ:71:14
   │
71 │     [#chapter.numbering("1", ..args.pos())]
   │               ^^^^^^^^^
#

I'm using MyST Markdown as an intermediate, so I'm trying to keep up with both languages.
The (here placeholder) figures are rendered like this:

#show figure: set block(breakable: true)
#figure(
  image("files/69a0e369000b9a76c8fe1b9d5d2e6162.svg", width: 90%),
  caption: [
This is a placeholder image.
],
  kind: "figure",
  supplement: [Figure],
) <ch-4-setup2>
languid dagger
#

I really hope someone can help me with this! 😅

somber needle
#

When you do

[#chapter.numbering("1", ..args.pos())]

you are trying to call a function chapter.numbering(..), which does not exist. You probably want

[#chapter.#numbering("1", ..args.pos())]

so that the dot is interpreted as a dot, and #numbering(..) as a standalone function.

languid dagger
#

Yeeees, thanks a ton, that works!!!

#

I'm not sure I completely understand the use of # all that well - in templates, it seems to be omitted most of the time... oh well, a headache for another time - thanks again, life saver!

somber needle
#

When you enter markup mode with [ ... ], everything you write in it is interpreted as literal content. To access variables and functions, you need to switch to code mode via #. Most templates don't actually use markup mode for most of the things (like set/show rules), which can be seen that they use curly braces { ... } when they are defined. In this case, you are already in code mode so you don't need the # symbols all the time.

#

You can read a bit about this here under "Modes"

Typst

A compact reference for Typst's syntax. Learn more about the language within
markup, math, and code mode.

languid dagger
#

This is brilliant, thanks a bunch!

languid dagger
#

The documentation says that: Once you have entered code mode with #, you don't need to use further hashes unless you switched back to markup or math mode in between. But I'm taking from the above that that's negated if you're inside [], is that correctly understood? (I learned that, since the template is made with #let template() = {}, everything in the curly braces is code by default - so I guess I do understand that now 😄 )