Numbering examples with gentle-clues package AND display number in title

Hello,
I am trying to number example boxes created with the gentle-clues package. From what I gathered, I should include them in a new kind of figure. So I tried something like this:

#import "@preview/gentle-clues:1.3.1" : *
#figure(kind: "example", supplement: [Example],
  example(title: "I would like to see `Example n` here, where n is the counter ", 
    [This is an example]
  )
)<ex:somecalc>
As we can see in @ex:somecalc

The numbering works well, and the cross-reference as well, but I cannot find a way to display the example number in the title.

My understanding is that I can use counter(figure.where(kind: "example") but I cannot find a way to include that in the string that is the example title.

I did find a solution. I was mostly missing context.

#import "@preview/gentle-clues:1.3.1" : *
#figure(kind: "example", supplement: [Example],
  example(title: [Example #context {counter(figure.where(kind: "example")).display()}], 
    [This is an example]
  )
)<ex:somecalc>
As we can see in @ex:somecalc

It is a bit more convenient to define a variable and then use it:

#let current_example_number = context {
  counter(figure.where(kind: "example")).display()
}

#figure(kind: "example", supplement: [Example],
  example(title: [Example #current_example_number], 
    [This is an example]
  )
)<ex:somecalc1>
As we can see in @ex:somecalc1

I am still interested to learn if there is a better solution!

Welcome to the forum! Indeed, the way you did it is probably best, as far as I know the package does not natively support referencing. This might change in the future when issue 147 gets resolved, as currently supporting this natively can be quite annoying on the implementation side (though some packages allow it, like theorion).

To make the solution more user-friendly, you could define your own function that gets rid of some of the overhead, for example:

#import "@preview/gentle-clues:1.3.1"
// Note the different import!

#let current_example_number = context {
  counter(figure.where(kind: "example")).display()
}

#let example(content, ..args) = figure(
  kind: "example", 
  supplement: [Example],
  gentle-clues.example(
    title: [Example #current_example_number], 
    content,
    ..args
  ),
)

#example[This is an example]<ex:somecalc1>

#example(accent-color: purple)[Another example, but purple!]<ex:someothercalc>

As we can see in @ex:somecalc1 ...

It does mean you have to re-define all the “clues” you want manually, but depending on your use case this could be an acceptable trade-off. Note that the ..args sink still allows you to pass any parameters you want to gentle-clues, including changing the title for the current clue :)