How to write easily custom style functions

Hello everyone, I am new on the community, I was searching for a Latex but without outdated, complicated and undocumented stuffs to keep my mind at ease.

I am really grateful for the work on typst, that for now brang me all what I needed.

I did an outline that is fine to me, written like this :

#show outline.entry.where(
  level: 1,
): it => {
  set block(above: 1.2em)
  // it.element.body.fields().values().first() == "Annexes"
  if it.element.body.fields().values().first() == "Annexes" {
    pagebreak()
    text(weight: "bold", "Table des annexes")
  } else { text(weight: "bold", it) }
}

#outline(title: outline_title, depth: 2)

It works fine, for having 2 outlines, one for appendices and the normal one.

But I found it really heavy to write and to find how to make this test it.element.body.fields().values().first() == “Annexes”.

So now for my questions, first is there easiest ways to get this same result ? Second, in general, how can I can compare easily text bodies and a value, and how can I navigate easily without having the feeling of retro enginnering the things for finding the fields and all.

Thank you in advance for your answers.

Hi Theo, welcome to the forum.

For converting content into text there is the package t4t. But it’s really not recommended to look into content like this.

Here’s an example that uses t4t:

#import "@preview/t4t:0.4.3": *

#show outline.entry.where(
  level: 1,
): it => {
  set block(above: 1.2em)
  
  if get.text(it.element) == "Annexes" {
    pagebreak()
    text(weight: "bold", "Table des annexes")
  } else { text(weight: "bold", it) }
}

#outline(title: [Outline Title], depth: 2)

= Heading 1
= Annexes

As for the other questions, I don’t have a lot to say really. Hovering over variables to display their values is helpful though.