Skip to content

Support text show rules that match their own output - #3327

Merged
laurmaedje merged 1 commit into
mainfrom
fix-recursive-text-show-rules
Feb 5, 2024
Merged

laurmaedje merged 1 commit into
mainfrom
fix-recursive-text-show-rules

Conversation

@laurmaedje

@laurmaedje laurmaedje commented Feb 2, 2024 •

Copy link
Copy Markdown
Member

This allows things like

#show "Hello": text(red)[Hello]
Hello World!

and

#show "rax": `rax`
The register rax.

without running into show rule recursion problems.

Note that Typst will still yield show rule recursion errors for self-matching non-text rules that don't use it (e.g. show list: it => list[a][b]). While this might seem bad at first glance, I think it is the correct choice. Revoking the list show rule for all content resulting from it would be wrong in the general case: The list might have contained nested lists, which then wouldn't be shown with the rule.

With a lot of effort, it might be possible to distinguish between an original nested list and a list generated by the rule, but there are further problems: Showing a list as another list yields two lists on a semantical layer. This can lead to surprising query() results and will also result in accessibility problems down the road. So I think replacing an element with one that rematches the result is bad practice. All these problems don't exist for text, so it's fine here and it's also where the lack of this recursion protection hurts the most.

Fixes #229

@Andrew15-5

Andrew15-5 commented Feb 2, 2024 •

Copy link
Copy Markdown
Contributor

What will happen here (after the merge):

#show "keyword": ```lang keyword```

keyword

`keyword`

```
expr const keyword number
```

(I ran into this problem before, and it was solved with a couple of show rules and a word joiner char. It only must change normal non-raw text.)

What if instead the show rule will multiply the number of initial applicable word?

#show "keyword": `keyword keyword`
// or
#show "keyword": "keyword keyword"

Do you have to use something like this or not:

#show "keyword": it => it + " " + it

Note that Typst will still yield show rule recursion errors for self-matching non-text rules that don't use it (e.g. show list: it => list[a][b]).

What is "non-text" exactly? There is no "text" type in Typst. You mean non-string show rules?

@laurmaedje

Copy link
Copy Markdown
Member Author

Every text show rule will apply just once. Show rules still apply to raw text, that's a separate thing. If the show rule multiplies the word, it still happens just once, so it will go 1->2 but not 2->4. You do not have to use it anymore.

What is "non-text" exactly? There is no "text" type in Typst. You mean non-string show rules?

There is a text element. The one you use with set text(..). But it was still not worded precisely from my-side because I mean string and regex show rules specifically, so show text is not affected.

@laurmaedje
laurmaedje added this pull request to the merge queue Feb 5, 2024
Merged via the queue into main with commit 92aba81 Feb 5, 2024
@laurmaedje
laurmaedje deleted the fix-recursive-text-show-rules branch February 5, 2024 09:54
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Jun 23, 2026
…relatório)

Read-only no histórico real do vanilla (main, 4476 commits, 0.14.2). I7: a
recursão auto-casante foi QUIS (typst#3327 'Support text show rules that match their
own output', Laurenz). I8: a Revocation já está implementada (não é falha
aberta). I9: o teto é limite de segurança genérico (família MAX_*_DEPTH), não
hack de perf. Veredito: o tekt NÃO achou um bug — achou uma diferença de
prioridade de design; α é melhoria condicional, não conserto. Refina o GEROU
do P347b (feature QUIS, borda-de-identidade mecânica) e corrige o enquadramento.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Dikluwe added a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
…relatório)

Read-only no histórico real do vanilla (main, 4476 commits, 0.14.2). I7: a
recursão auto-casante foi QUIS (typst#3327 'Support text show rules that match their
own output', Laurenz). I8: a Revocation já está implementada (não é falha
aberta). I9: o teto é limite de segurança genérico (família MAX_*_DEPTH), não
hack de perf. Veredito: o tekt NÃO achou um bug — achou uma diferença de
prioridade de design; α é melhoria condicional, não conserto. Refina o GEROU
do P347b (feature QUIS, borda-de-identidade mecânica) e corrige o enquadramento.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for show rules that match on their own output

2 participants