Does Typst have something like console.log() of JavaScript?

Is there a function that would print all or most elements of an object with it’s properties, sub-objects, references to children and parent? I would be using this for learning and debugging purposes.

I would like to loop through all par-elements and replace their text or add a text beneath them that would list this additional information.

Repr() seems like a partial answer, but I haven’t been able to get it working. I have tried something like this, but my code doesn’t compile:

#show par: it => {
  it
  repr(it)
}
1 Like

On the web app (and I think Tinymist on VSCode too), you can hover your mouse over any variable, such as it in that code, to see what it evaluates to each time that code runs. You can also interrupt compilation and print information to console with e.g. panic(repr(it)).

2 Likes

Thank you, I got panic(repr(it)) working as you instructed. Unfortunately, the information panic printed me is not helping me construct the show-rules I try to achieve. I guess panic was not what I neede to look for. I’m sorry, I find it difficult to ask the right question. I’m still on such as beginner level with Typst. There’s something with show-rules that I have a hard time understanding, despite reading some tutorials.

**For example with the Typst code below, how would I adjust the line "#show par: rect" to select only pars that are not a list or enum, but baseline text?** And I would like to know why "#show par: rect" will select only some of the text elements? And instead of giving me the right answer, what's the logic, reasoning and experimenting that would help me learn and figure this out myself? I need to learn to ask the right questions, so I can start finding my own answers. Or does it help to study how Typst operates under the hood? And where could I find such information?

#set page(width: 150mm, height: auto)
#set par(spacing: 1.2em, leading: 0.2em, justify: true)
#show selector.or(list.item, enum.item): block

#show par: rect // How to adjust this line?

#let words = 26

#lorem(words)

#lorem(words)

- #lorem(words)
- #strong[Aaa] #lorem(words)
- #strong[Bbb] #lorem(words)
  - #strong[Ccc] #lorem(words)
  - #strong[Ddd] #lorem(words)
    - #strong[Eee] #lorem(words)
    - #strong[Fff] #lorem(words)
  - #strong[Ggg] #lorem(words)
    + #strong[Hhh] #lorem(words)
    + #strong[Iii] #lorem(words)
    + #strong[Jjj] #lorem(words)
+ #strong[Kkk] #lorem(words)
  - #strong[Lll] #lorem(words)
  - #strong[Mmm] #lorem(words)
  - #strong[Nnn] #lorem(words)

I agree that it’s sometimes not obvious how the compiler generates elements from markup. My approach in Typst is to think in functions that return content, rather than producing semantic markup that is styled separately.

So if you want to have some par-s of the document to have a different style the easiest way to achieve that is to wrap that part with some function that adds style. And if you want to make sure that Typst generates a par for the content then you can add a parbreak(), like this:

#let my-par(body) = text(fill: blue, body + parbreak())
#my-par(lorem(24))

See “What becomes a paragraph?” in the Typst documentation for details.

Applied to your example each numbered or unnumbered list item will become a paragraph and be wrapped in a rect if you change the show-rule into:

#show selector.or(list.item, enum.item): it => it + parbreak()
2 Likes

About post formatting:

The summary string should be short and it can’t use any styling. You should write long sentences and paragraphs inside details block or before it, depending on the content and context.

1 Like