Skip to content

Introduce second variant of Ignorant Behaviour and prevent weak page breaks at basically empty pages - #1929

Merged
laurmaedje merged 7 commits into
typst:mainfrom
Beiri22:ignorance
Aug 30, 2023
Merged

laurmaedje merged 7 commits into
typst:mainfrom
Beiri22:ignorance

Conversation

@Beiri22

@Beiri22 Beiri22 commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

This is inspired by and in some way alternative to #1500 and also attempts to fix #1346.

Stands for discussion.

@laurmaedje

Copy link
Copy Markdown
Member

I definitely see the value fo the page counter though. I do not really see the motivation for the weak argument on place. Is there some earlier issue where a desire for this expressed?

@laurmaedje

Copy link
Copy Markdown
Member

Moreover, I think a fifth Behaviour would be more fitting. The idea behind Ignorant is mostly that is a normal element but doesn't interact with other elements. But this is different. Perhaps Invisible?

@Beiri22

Beiri22 commented Aug 23, 2023

Copy link
Copy Markdown
Contributor Author

I definitely see the value fo the page counter though. I do not really see the motivation for the weak argument on place. Is there some earlier issue where a desire for this expressed?

As far as I remember, when coming to the behaviour of place, the discussion was unclear. Will a place trigger a weak page break or might there be cases, where a place could be invisible?

@laurmaedje

Copy link
Copy Markdown
Member

I think until it's established as a problem how place interacts with weak pagebreaks there is no reason to change it.

@Beiri22

Beiri22 commented Aug 23, 2023

Copy link
Copy Markdown
Contributor Author

ok.

@Beiri22

Beiri22 commented Aug 23, 2023 •

Copy link
Copy Markdown
Contributor Author

Please, have a look.

@Beiri22

Beiri22 commented Aug 25, 2023

Copy link
Copy Markdown
Contributor Author

Please consider #1997 to calm clippy down even more and get a test pass...

@Beiri22

Beiri22 commented Aug 25, 2023

Copy link
Copy Markdown
Contributor Author

the fmt error is addressed in #1999

@Beiri22

Beiri22 commented Aug 25, 2023

Copy link
Copy Markdown
Contributor Author

@laurmaedje You are deeper inside the code ... Are there any open concerns with this implementation?

@laurmaedje

Copy link
Copy Markdown
Member

I haven't yet merged because I wanted to carefully review to check whether it works as intended. I probably won't have time to do that in the next few days (I'm travelling at the moment), but hopefully next Wednesday or so.

@laurmaedje

Copy link
Copy Markdown
Member

I experimented a bit with it and thought a bit about it and it seems to work correctly. Thanks!

@laurmaedje

laurmaedje commented Sep 13, 2023 •

Copy link
Copy Markdown
Member

This PR broke the following snippet:

#pagebreak(weak: true)
#bibliography("...")

It nows fails with "the document does not contain a bibliography" because the weak pagebreaks stops the basically empty page after it from being used and then the bibliography metadata just vanishes into the void.

Independently of this PR, the following snippet produces a Typst document without pages:

#pagebreak(weak: true)

Unfortunately, the whole code around this is quite brittle. :/

See also: #2134

@Beiri22

Beiri22 commented Sep 13, 2023

Copy link
Copy Markdown
Contributor Author

So better revert for now and create a set of tests first that have to pass?

@laurmaedje

Copy link
Copy Markdown
Member

I would rather not revert, as that would regress the other bug that was fixed by this, which also isn't great. I hope we can find a way to fix this / make it good enough. Medium-term this all needs a refactoring ...

@Beiri22

Beiri22 commented Sep 13, 2023

Copy link
Copy Markdown
Contributor Author

Ok. What behaviour is bibliography? As the changeset was not large, it might be not too difficult to find with the debugger.

@laurmaedje

Copy link
Copy Markdown
Member

The relevant thing is MetaElem because the Bibliography itself generates no content in the first introspection iteration. But every locatable element generates a MetaElem exactly for that case. So it's Invisible. The problem is with the is_basically_empty in interrupt_page. I'm not yet sure how a good fix would look like though.

@Beiri22

Beiri22 commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Sure? I'm not with an ide or compiler now, but parbuilder seems at least suspicious to me:

if content.is::<MetaElem>() {
            if !self.0.is_basically_empty() {
                self.0.push(content.clone(), styles);
                return true;
            }

@laurmaedje

Copy link
Copy Markdown
Member

Both might be problematic, but the pagebreak is definitely more problematic because if you replace that is_basically_empty for it with a version that doesn't ignore Invisible elements, it works again. the same doesn't hold true for replacing the par builder one.

@Beiri22

Beiri22 commented Sep 14, 2023

Copy link
Copy Markdown
Contributor Author

Just a question. in behave.rs BehavedBuilder::push()

Could we handle Ignorant and invisible differently? If we pushed invisible elements directly to the builder, I mean they are invisible, would that break order in some way?

@laurmaedje

Copy link
Copy Markdown
Member

That would probably break the location.position() method and links because suddenly a metadata element after some spacing ends up before it.

@Beiri22

Beiri22 commented Sep 14, 2023 •

Copy link
Copy Markdown
Contributor Author

As far as I understand, the staged items are never simply deleted. Might there just be missing a final flush of the staged items? Normally this is done in interrupt_page() and this is indeed not happening when the page is basically empty. But should only be any problem on the last page. At every other location some pagebreak will happen and therefore do the flush.

So just a hypothesis: In the last interrupt_page() call in realize_layout(). When you have still staged elements there but no new page is created, those elements may need to be pushed onto the last page. Would that somehow suffice?

@Beiri22

Beiri22 commented Sep 14, 2023

Copy link
Copy Markdown
Contributor Author

Or can they be pushed after the page without creating a new page?

@laurmaedje

Copy link
Copy Markdown
Member

So just a hypothesis: In the last interrupt_page() call in realize_layout(). When you have still staged elements there but no new page is created, those elements may need to be pushed onto the last page. Would that somehow suffice?

I think it makes sense. I did try something like that yesterday, but didn't get it to work without breaking everything. But probably it was only because it was late and I was tired. I tried again and it seems to work this time around: #2141

@Beiri22

Beiri22 commented Sep 14, 2023 •

Copy link
Copy Markdown
Contributor Author

When you put another invisible element at the end of the document, let's say metadata (which in contrast will not generate any visible content in the document), will that result in an empty page then?

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.

weak pagebreak after page counter update always adds pagebreak

2 participants