Mc-Zen / tidy

A documentation generator for Typst in Typst.
https://typst.app/universe/package/tidy
MIT License
57 stars 2 forks source link

Error using `show-example` #15

Closed ntjess closed 8 months ago

ntjess commented 8 months ago
#import "@preview/tidy:0.2.0": show-example

#show raw: show-example.show-example

```typ
Hello world

Produces the error
```console
error: variables from outside the function are read-only and cannot be modified
   ┌─ @preview/tidy:0.2.0\src\show-example.typ:32:4
   │
32 │     mode = "markup"
   │     ^^^^
Mc-Zen commented 8 months ago

It's not really intended to be used like that. The bug is there for sure and easy to fix. However, show-example creates a new raw and that would result in a recursive show rule.

Mc-Zen commented 8 months ago

I can change that and prevent the creation of a new raw but show-example still wouldn't work quite as within docstrings because the scope is not passed down automatically and user-defined functions would not be available.

Mc-Zen commented 8 months ago

On the other hand, you could do which would work.

#let my-var = [34]
#show raw: show-example.show-example.with(scope: (my-var: my-var))

```typ
Hello world #my-var


Okay, I'll push some update that will allow doing that.