You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resetting show and set to its default / Revoke rules #420
I think we need a way to reset show rules to their default.
// introduce a custom style for all text objects#showtext: box.with(stroke: .4pt+red, outset: (bottom: .3em, rest: .1em), radius: .1em)
Some simple text.
Some other text wrapped in a tight red box.
// how do we turn it off?!#showtext: it=>it
Ugh!
Similarly, after a set rule there is no simple way of "unsetting" it (reverting to the default), apart from explicitly writing the default or wrapping everything in a scope.
Reacted by Daniel Rauber, Aaron Yeoh Cruz, Nathan Jessurun, Andrew Voynov, CGMossa, Nicolai Weitkemper, Laurenz Stampfl, Qijing Li, explosion-mental, Adam Stone and 70 more
Reacted by jassler, CGMossa, Kevin Stephen, Vladislav Deryabkin, dvdvgt, Tyler Thrailkill, Michał Hemperek, Börge Kiss, Jannis Piekarek and Dominik Schwaiger
// introduce a custom style for all text objects
#[
#show text: box.with(stroke: .4pt + red, outset: (bottom: .3em, rest: .1em), radius: .1em)
Some simple text.
Some other text wrapped in a tight red box.
]
Good
I think it's cleaner than TeX's "save stack" way to handle these things, but it doesn't solve everything.
Reacted by Qijing Li, Lorenzo Rossi, Robin and Michał Hemperek
Another currently (I think) unsolvable example:
I have defined a custom show for headings so they are wrapped within a block with a stroke. However, in some special cases (not dependent on level or similar) this should not be the case.
You might be aware, but you can reconstruct the heading from its body:
#show heading: block.with(stroke: 1pt, inset: 4pt)
= Hello
#show heading: it => it.body
= Hello again
In theory, "Hello again" should now be completely plain and unstyled, but through another bug it keeps the compiler-default show-set rule that increases weight and size. But in any case, you can get rid of the original show rule here by reconstructing the heading from scratch. But you also need to take care of adding the numbering etc. again so it's not really a satisfactory solution.
Reacted by baptiste, Andrew Voynov, CGMossa, explosion-mental, Hanchen Zhang, Richard Glen Domingo, Dominik Schwaiger, XY_cpp, Ertuğrul Uyar, Y. Xu and 12 more
#showheading: settext(red) <my-show-rule>
= Red heading// syntax prone to bikeshedding#unapply@my-show-rule// or <my-show-rule> or something= Not red heading
Reacted by raphCode, Yupeng Chen, qaz, Nianyi Wang, Ertuğrul Uyar and Cierra-Runis
Reacted by Ilia, Francisco J. Sanchez, CGMossa, Nicolai Weitkemper, Khaïs COLIN, Eîar Abramski-Kronenberg, Youssef Sahli, vitto, NebulaDev, Kevin Stephen and 1 more
The problem is that you do want to retain the show rule for nested content not generated by the rule (consider list show rules on a list in a list). You only do not want it on the element itself and content generated by the rule. Otherwise, fixing the recursion bug would be easy.
I wasn't trying to say it was a simple thing, I'm sorry if you understood that. I was just throwing out an idea on the previous suggestion without thinking about the implementation. 😔
The design on this feature is not yet finalized because there wasn't consensus on what it should and shouldn't do, so it will likely still take a while. The latest discussion about it is in the styling forge thread.
I think it should be #unshow, personally. Also, perhaps #show could return a unique identifier that could then be used to revoke that particular layer of redefinition?
More support for introspection on show and set would be excellent as well.
At the very least, there should be a way to specify within the #show declaration itself that the definition should NOT be applied recursively. In fact, I think this behavior (non-recursion) should be the default, and an extra keyword or keyword suffix (#show*, #show!, etc) should be required to activate recursive application of a #show rule. (For consistency's sake, #set could also have this behavior.)
This is very useful when you have some text you want to substitute (or transform) throughout the document, but in rare cases you need to insert it verbatim/leave it as-is. But now this doesn't work:
Which is apparently a fixed bug and not a broken feature. Currently, there is no way to work around this, other than using variable, with the substituted content and/or using locally scoped show rule. This has several downsides:
The text looks a little off, since now you have # in certain places, or the whole variable can be unintentionally highlighted by the IDE (for Typst and the default color scheme it's colored in purple), making unnecessary accent on such substitutions.
The spell checker that I use won't recognize the variable as a word, which can lead to undesired warnings and possibly uncaught mistakes.
Using locally scoped show rules is much more verbose than just one global rule (depends on the number of usages in a particular document).
Using variable requires manual importing it in every file (if document has many files), which is also more verbose and messy than a single root-scoped show rule.
With the revoke syntax it can be more manageable, but it is still more verbose and won't work in certain situations.
The particular situation I have in mind is when you have a paragraph in your (big) document where want to use the substitution in one instance, and in the other you want the text verbatim:
#show"Writer": "LibreOffice Writer"
Writer --- #lorem(7). It #lorem(10).\Writer #lorem(20)
Here, with the backslash "bug", you can easily cancel one rare occasion where you don't want to substitute text. Using any other method would result in a (messy and) more verbose solution. I like the backslash as it only 1-char-fix and since it's rarely used in the document, it's not a big deal at all.
I would like to potentially bring this bug back and rebrand it as a feature instead. One place of conflict is the \u{} syntax for inserting a Unicode code point like this:
A can be inserted as \u{41}.
Currently, this also matches the show rule the same way, the verbatim Unicode code point is inserted. I.e., show "A" will apply to A and to \u{41}. And here comes the decision: will the \\u{41} produce A that won't match the show "A", or will it produce \u{41}? In any case, I think this is a super niche thing, to escape a dedicated/special syntax for inserting Unicode code points that is rarely used in of itself (but some do use it more actively than others). I don't think it makes much sense to escape the show rule by prepending a backslash, but what is more practical is printing \u{41} verbatim (when showing examples etc.)
Other than this tiny detail, I think it should be possible. Of course, someone might want to match "\text" in a show rule, but now we are literally talking LaTeX macros (ain't no one wants those in Typst, amiright). But this also can be the second point of discussion.
Just wanted to toss my two cents into the discussion. Apologies if these points have already been brought up.
I find that show/set rules work excellently for adjusting the appearance of text marked up with Typst's custom syntax. For example, = Heading being styled with show heading: it => [ ❗ #it ❗].
If one element should look different than the rest, then a custom function could be made. For example, #let h1-special(body) = { heading(level: 1, [✨ #body ✨]) }.
However, since show rules apply globally, even to elements inside custom functions, if one custom function is made, then ALL show rules must be converted to custom functions as to not affect other custom functions.
This essentially eliminates the usefulness of the custom syntax in the markup language.
In my last project, I found that once I had a case of = One Special Heading that had to be converted to h1-special[One Special Heading], I had to convert all usages of = Heading to h1[Heading].
This isn't unusable, but it'd be nice to leverage Typst's markup syntax, such as _emphasis_, = Heading, *strong*, and so on.
Unapplying show rules, I believe, would fix this, but I'd definitely be interested in alternative ways to solve this problem.
#letspecial(body) = {
showheading: it=>..body
}
#special[= One special heading]
Then, depending on whether you use it or it.body in the show rule, you get the effect of the more global rule or you don't.
Writing the show rule that uses it.body can be a bit annoying and that's something we're aware of. A mechanism to revoke the rule would help with this, but only to return to the default style, not to tweak it. To do this nicely, we need something more general. I haven't yet put my thoughts on the matter into text form, but I gave a talk on it at the last Typst meetup.
I just wanted to leave a comment for anyone else looking for a workaround from within odd circumstances.
You can use labels to filter your styling. In my case, I want all links, citations, and references to have the same blue, underlined look. However, I just added a "badge", which links to external GitHub URLs. As a result, I have used my "badge" as the body of link. To avoid the styling, I have added a label and modified my show rule:
This can be implemented much cleaner, but it shows the general idea. Hopefully this is useful to someone else who needs a quick-and-dirty escape hatch.
Adding another use case: a template package that I installed automatically adds the underline show rule to links, and I naturally don't want to change the original package. I do, however, want to "unapply" this show rule within a particular function I've written to use on top of this template, however, I'm unsure of how to do this. Naturally, the existing "wrap it in its own block" solution doesn't apply to me, since the block that sets that styling exists in Typst code that came with the package. Tough!
@laurmaedje I found a similar solution elsewhere, and that's exactly what I did! Didn't realize that underline was an actual element, rather than a property. Definitely still a novice here, lol.
I did, however, see that rule revocation is on the roadmap, and naturally being 0.x software I'm content in recognizing that there's still things being actively developed. Excited to keep using it!
Activity
[-]Resetting `show` to its default[/-][+]Resetting `show` and `set` to its default[/+]user202729 commentedon Mar 29, 2023
Related: #229, #351.
user202729 commentedon Mar 29, 2023
In this particular case one working way is
I think it's cleaner than TeX's "save stack" way to handle these things, but it doesn't solve everything.
FedericoStra commentedon Mar 29, 2023
Yes, I'm aware that one can localize the effect with a block
I was thinking more about the case where one wants to revert some change introduced by an imported template.
rauberdaniel commentedon Jul 5, 2023
Another currently (I think) unsolvable example:
I have defined a custom
showfor headings so they are wrapped within a block with a stroke. However, in some special cases (not dependent on level or similar) this should not be the case.laurmaedje commentedon Jul 5, 2023
You might be aware, but you can reconstruct the heading from its body:
In theory, "Hello again" should now be completely plain and unstyled, but through another bug it keeps the compiler-default show-set rule that increases weight and size. But in any case, you can get rid of the original show rule here by reconstructing the heading from scratch. But you also need to take care of adding the numbering etc. again so it's not really a satisfactory solution.
istudyatuni commentedon Aug 21, 2023
Maybe something like
PgBiel commentedon Oct 21, 2023
So, I had this crazy idea:
Zheoni commentedon Nov 8, 2023
This could also fix #229 by manually stopping recursion. Something like
or
laurmaedje commentedon Nov 8, 2023
The problem is that you do want to retain the show rule for nested content not generated by the rule (consider list show rules on a list in a list). You only do not want it on the element itself and content generated by the rule. Otherwise, fixing the recursion bug would be easy.
Zheoni commentedon Nov 8, 2023
I wasn't trying to say it was a simple thing, I'm sorry if you understood that. I was just throwing out an idea on the previous suggestion without thinking about the implementation. 😔
laurmaedje commentedon Nov 8, 2023
No no, don't worry. It's good to see ideas thrown around, I was just pointing out a possible problem with the approach to add to the discussion.
yochem commentedon Dec 6, 2023
Might be related: there is currently no way to see the default show rule set by typst. That would be very useful to tweak minor parts of an element.
15 remaining items
laurmaedje commentedon Jan 16, 2024
Note that the idea was only to replace
show: xwithapply xnotshow x: y.polazarus commentedon May 2, 2024
Another way to get around it would be to provide access to raw and immutable commands in some kind of "builtin" namespace.
zhc7 commentedon May 12, 2024
Can we know when will the feature be implemented? Or are there some sort of thread that tracks this?
laurmaedje commentedon May 13, 2024
The design on this feature is not yet finalized because there wasn't consensus on what it should and shouldn't do, so it will likely still take a while. The latest discussion about it is in the styling forge thread.
CheeseTurtle commentedon Jul 16, 2024
I think it should be
#unshow, personally. Also, perhaps#showcould return a unique identifier that could then be used to revoke that particular layer of redefinition?More support for introspection on
showandsetwould be excellent as well.At the very least, there should be a way to specify within the
#showdeclaration itself that the definition should NOT be applied recursively. In fact, I think this behavior (non-recursion) should be the default, and an extra keyword or keyword suffix (#show*,#show!, etc) should be required to activate recursive application of a#showrule. (For consistency's sake,#setcould also have this behavior.)Andrew15-5 commentedon Sep 26, 2024
This was mentioned in https://forum.typst.app/t/how-to-make-a-table-formatting-condition-for-just-one-table/713/2.
Andrew15-5 commentedon Oct 15, 2024
Based on #5199, I want to add a similar issue that I faced with 0.12.0-rc1.
Previously, when I was using string/text substitution in my documents, I would escape/cancel the show rule, which worked as expected:
This is very useful when you have some text you want to substitute (or transform) throughout the document, but in rare cases you need to insert it verbatim/leave it as-is. But now this doesn't work:
Which is apparently a fixed bug and not a broken feature. Currently, there is no way to work around this, other than using variable, with the substituted content and/or using locally scoped show rule. This has several downsides:
#in certain places, or the whole variable can be unintentionally highlighted by the IDE (for Typst and the default color scheme it's colored in purple), making unnecessary accent on such substitutions.The particular situation I have in mind is when you have a paragraph in your (big) document where want to use the substitution in one instance, and in the other you want the text verbatim:
Here, with the backslash "bug", you can easily cancel one rare occasion where you don't want to substitute text. Using any other method would result in a (messy and) more verbose solution. I like the backslash as it only 1-char-fix and since it's rarely used in the document, it's not a big deal at all.
I would like to potentially bring this bug back and rebrand it as a feature instead. One place of conflict is the
\u{}syntax for inserting a Unicode code point like this:A can be inserted as \u{41}.Currently, this also matches the show rule the same way, the verbatim Unicode code point is inserted. I.e.,
show "A"will apply toAand to\u{41}. And here comes the decision: will the\\u{41}produceAthat won't match theshow "A", or will it produce\u{41}? In any case, I think this is a super niche thing, to escape a dedicated/special syntax for inserting Unicode code points that is rarely used in of itself (but some do use it more actively than others). I don't think it makes much sense to escape the show rule by prepending a backslash, but what is more practical is printing\u{41}verbatim (when showing examples etc.)Other than this tiny detail, I think it should be possible. Of course, someone might want to match "\text" in a show rule, but now we are literally talking LaTeX macros (ain't no one wants those in Typst, amiright). But this also can be the second point of discussion.
Related: #5209.
bluss commentedon May 19, 2025
Does this issue include revoking default rules? Use case: I want a
rawblock that inherits the document'stext.font,text.size.Edit: Now issue #6302. Feel free to edit it.
laurmaedje commentedon May 19, 2025
@bluss I think that is worthy of its own issue.
TehBrian commentedon May 4, 2026
Just wanted to toss my two cents into the discussion. Apologies if these points have already been brought up.
I find that show/set rules work excellently for adjusting the appearance of text marked up with Typst's custom syntax. For example,
= Headingbeing styled withshow heading: it => [ ❗ #it ❗].If one element should look different than the rest, then a custom function could be made. For example,
#let h1-special(body) = { heading(level: 1, [✨ #body ✨]) }.However, since show rules apply globally, even to elements inside custom functions, if one custom function is made, then ALL show rules must be converted to custom functions as to not affect other custom functions.
This essentially eliminates the usefulness of the custom syntax in the markup language.
In my last project, I found that once I had a case of
= One Special Headingthat had to be converted toh1-special[One Special Heading], I had to convert all usages of= Headingtoh1[Heading].This isn't unusable, but it'd be nice to leverage Typst's markup syntax, such as
_emphasis_,= Heading,*strong*, and so on.Unapplying show rules, I believe, would fix this, but I'd definitely be interested in alternative ways to solve this problem.
Thanks for reading :-)
laurmaedje commentedon May 5, 2026
The more idiomatic way would be to keep the styling rule-based, but local, like this:
or even
Then, depending on whether you use
itorit.bodyin the show rule, you get the effect of the more global rule or you don't.Writing the show rule that uses
it.bodycan be a bit annoying and that's something we're aware of. A mechanism to revoke the rule would help with this, but only to return to the default style, not to tweak it. To do this nicely, we need something more general. I haven't yet put my thoughts on the matter into text form, but I gave a talk on it at the last Typst meetup.TimeTravelPenguin commentedon Aug 20, 2026
I just wanted to leave a comment for anyone else looking for a workaround from within odd circumstances.
You can use labels to filter your styling. In my case, I want all links, citations, and references to have the same blue, underlined look. However, I just added a "badge", which links to external GitHub URLs. As a result, I have used my "badge" as the body of
link. To avoid the styling, I have added a label and modified my show rule:This can be implemented much cleaner, but it shows the general idea. Hopefully this is useful to someone else who needs a quick-and-dirty escape hatch.
MMachado05 commentedon Sep 21, 2026
Adding another use case: a template package that I installed automatically adds the
underlineshow rule to links, and I naturally don't want to change the original package. I do, however, want to "unapply" this show rule within a particular function I've written to use on top of this template, however, I'm unsure of how to do this. Naturally, the existing "wrap it in its own block" solution doesn't apply to me, since the block that sets that styling exists in Typst code that came with the package. Tough!laurmaedje commentedon Sep 21, 2026
@MMachado05 For that particular problem, you can hack around it like this:
But yeah, it would be a good use case for revoke.
MMachado05 commentedon Sep 21, 2026
@laurmaedje I found a similar solution elsewhere, and that's exactly what I did! Didn't realize that
underlinewas an actual element, rather than a property. Definitely still a novice here, lol.I did, however, see that rule revocation is on the roadmap, and naturally being 0.x software I'm content in recognizing that there's still things being actively developed. Excited to keep using it!