How can I change a raw block's language in a show rule without having the font size changed?

Hello,
I’m building a quick example rendering system for a document and wanted to use a example raw-environment to print the contents as a typst raw code and then render the result of it. But for whatever reason, Typst makes the raw code a teeny wheeny tiny bit smaller…

#set page(height: auto, width: auto, margin: 2mm)
#show raw: block.with(stroke: gray, inset: 0.6em, radius: 0.5em)

#show raw.where(block: true, lang: "example"): it => {
  eval(it.text, mode: "markup")
  it
  raw(it.text, lang: "typst")
}

```example
#text(blue,[Hello World])
```

Results in the silly thing below

I expected no font changes, since I have to explicitly set the raw blocks font size. Is this intended? Am I doing something wrong? (setting the second raw block’s block to true doesn’t change anything…).

I would be happy if anybody could help me :)

Similar to Smaller font when using a raw block in a show rule · Issue #1331 · typst/typst · GitHub, you have to undo yet another shrinkage by 0.8:

#show raw.where(block: true, lang: "example"): it => {
  show raw: set text(1em / 0.8)
  eval(it.text, mode: "markup")
  it
  raw(it.text, lang: "typst")
}

But unlike that show rule, it won’t affect other custom content created in the show rule.

Thank you, this did the job! Let’s hope an appropriate solution is found at some point :)

1 Like

This would be a good use case for Replacing show rules · Issue #7165 · typst/typst · GitHub once it’s available.

1 Like