How to label a table with #let binding?

#let in-outline = state("in-outline", false)
#show outline: it => {
  in-outline.update(true)
  it
  in-outline.update(false)
}

#let flex-caption(long, short) = context if in-outline.get() { short } else { long }



#let my_table = table(
  columns: 1,
  [#lorem(100)],[#lorem(100)],[#lorem(100)],[#lorem(100)],[#lorem(100)],[#lorem(100)],[#lorem(100)],[#lorem(100)])



#show figure: set block(breakable: true)

#context{
  figure(
    my_table, caption: flex-caption([This is the table caption], [This is the outline caption])
  ); <link_my_table>
} 

@link_my_table

I want to label my_table and reference it. I’m also using flex-caption to generate different caption for outlines. The table is bound with #let because I want to wrap it across pages as suggested here. I can’t figure out where to place the label, is it even possible?

Hi, from the docs:

Currently, labels can only be attached to elements in markup mode, not in code mode. This might change in the future.

Which means it works if you use square brackets for your code inside context.

#context[
  #figure(
    my_table, caption: flex-caption([This is the table caption], [This is the outline caption])
  ) <link_my_table>
]
1 Like

Hi @Vaclav_Bocan ,

I had success with

#figure(
  context { my_table },
  caption: flex-caption([This is the table caption], [This is the outline caption]),
)<link_my_table>

@link_my_table

Not sure if that helps as the previous posted solution works as well. EDIT: I guess be careful about not adding unnecessary line breaks if using the square brackets.

1 Like

At least in this minimal example, context isn’t even necessary.

1 Like

Hello, thanks for this alternative solution. flokl’s answer was helpful in general, because I didn’t know about the markup/code mode restriction, but yours also helps me to understand the flexibility we have in typst.

1 Like

Yes I know, it is necessary though for something else outside the scope of this question. I didn’t want to complicate the question with all the details.

1 Like