Problems with code blocks in @preview/problemst:0.1.0

Hi folks, I’m pretty new to typst. Currently using it to make my homework assignments readable. I’ve just updated to 0.12.0.

I’ve run into an issue with code blocks when using the problemst template. At first, I thought it was because I was trying to use a raw() with lang: "typc", but now that I’m including matlab code blocks as well I see it error out there as well. Any advice on how to get code blocks working again?

Here’s the error I’m seeing:

$ typst c example.typ
error: can only be used when context is known
   ┌─ @preview/problemst:0.1.0/pset.typ:55:18
   │
55 │         box(width:measure([#it.lines.last().count]).width, align(right, text(fill: luma(50%))[#l.number]))                                                                     
   │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   │
= hint: try wrapping this in a `context` expression
= hint: the `context` expression should wrap everything that depends on this function
help: error occurred while applying show rule to this line
   ┌─ example.typ:17:0
   │
17 │ // Subroutine code:
   │ ^^^^^^^^^^^^^^^^^^^                                                                                                                                                            

and here’s a reproducible example file: View paste 6J732

Anybody got tips on how to fix?

Another discovery: this appears to be a regression introduced with Typst 0.12.0. Switching back to 0.11.1 fixes the issue, though I lose access to sym.crossmark :(

Actually, it is not a regression. It is the expected behavior and the error explains what to do at the level package.

I think you should post an issue on the Github repo of the package. The error is easy to correct, since it seems that a context is missing.

Thanks for clarifying. I’ve posted an issue here. Hopefully that’s the right place.

Until the author responds, got any advice for me on how to fix this? I’m happy to fork the template and tinker, I just haven’t figured out context yet. I’ve read through the docs page about 3 times, but it’s still Greek to me.

I now see that there’s already a PR up for this. Guess I just needed to find the right place to look. Thanks!

1 Like