Skip to content

pre-compute entry visibility once via count-all-refs()#189

Open
joelsa wants to merge 1 commit intotypst-community:masterfrom
joelsa:fix/typst-013-glossary-convergence
Open

pre-compute entry visibility once via count-all-refs()#189
joelsa wants to merge 1 commit intotypst-community:masterfrom
joelsa:fix/typst-013-glossary-convergence

Conversation

@joelsa
Copy link
Copy Markdown

@joelsa joelsa commented Apr 1, 2026

I've had some problems with non-convergent layouts. I've found in many of these cases the problem is an oscillation due to conditional content emission.

From my point of view, the ref counts can be pre-computed once. Is there a reason why this was not done before?

This PR does just that, pre-computing the reference counts. I think this will make the layout more stable and should have no negative consequences.

@joelsa
Copy link
Copy Markdown
Author

joelsa commented Apr 1, 2026

I am unsure whether using count-all-refs() like this is the right choice, as it recomputes __glossary_final_counts() N times (once per entry) when a single call would be enough. Using __glossary_final_counts() directly would be cleaner, right?

@quachpas quachpas self-requested a review April 1, 2026 13:30
Copy link
Copy Markdown
Collaborator

@quachpas quachpas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @joelsa, thanks for the patch!
Can you provide a test/showcase as well? I'd like to be able to confirm that your divergence test case is indeed fixed by this patch. I can confirm on my side that that tests pass locally. I'll run the workflow once you've got a test written up.

Using __glossary_final_counts() directly would be cleaner, right?

Yes, use internal functions as you like as long as the result is clear and concise. count-refs/count-all-refs are just more practical. In practice, I don't think the optimization is even visible because the Typst compiler does its job pretty well.
count-refs is called from print-gloss which means it's already called for each entry².

Let's not modify show-all to mean something else other than the current argument. Instead, you should add a new argument to user-print-reference and propagate it. I'll help with double checking that it's done correctly.

Then we can write in default-print-gloss

-  if show-all == true or count-refs(entry.at(KEY)) >= minimum-refs {
+ if show-all == true or entry-visible == true {

This way, things are indeed pre-computed.

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.

2 participants