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
Headings do not always respect widow and orphan prevention #1044
I see in the February 12, 2023 changelog that "Support for widow and orphan prevention within containers" was added. I would like this to also be added for entire pages.
Use Case
This feature would allow users to focus on writing their papers instead of worrying about orphans/widows.
Reacted by sorenrade, Rémi Marche, Alekséi Naidénov, ffalcon31415, Dixon Sean Low Yan Feng, Martyn Loughran, Stephan Daus, Daniel Bershatsky, Felix Eckhofer, pembem22 and 4 more
I also meant pages with this changelog entry. It should keep the first and last two lines together and also headings attached. The latter part might be buggy though. If you have concrete examples where it doesn't work that would be helpful.
*Summarizing the algorithm:*\
+ Sample from initial Gaussian
+ Propagate according to dynamics (with process noise!)
- Compute and store conditional mean and covariance for later analysis
+ Update weights per-sample based on how well it agrees with your measurement
- Compute and store conditional mean and covariance for later analysis
+ Resample if necessary
+ Repeat 2 - 4 till you're all out of measurements
= 3. Bootstrap Particle Filter (BPF) -- With Resampling#figure(
table(image("../figures/bpf_with_re.svg")),
caption: [
Position Error and $plus.minus 3 sigma$ Interval for BPF resampled when $hat(N)_"eff" < 0.1N$
]
)
= 4. Comparison Between EKF and BPFs
```
EKF RMSE: 4.22e-02
BPF (no resampling) RMSE: 4.40e-02 (+4.4%)
BPF (with resampling) RMSE: 4.23e-02 (+0.2%)
EKF MAE: 3.67e-02
BPF (no resampling) MAE: 3.70e-02 (+1.0%)
BPF (with resampling) MAE: 3.66e-02 (-0.1%)
```
The BPF with resampling closesly trades blows with the EKF (+0.2% RMSE, -0.1% MAE), and the BPF without
resampling is only marginally worse than the EKF (+4.4% RMSE, +1.0% MAE)! I do think that the BPF without
resampling simply got lucky, however, since the trajectory sorta stagnates at the end so there's not much
of a threat posed to the few particles by highly nonlinear dynamics.
#figure(
table(image("../figures/bpf_with_re_neff.svg")),
caption: [
Number of effective particles for BPF resampled when $hat(N)_"eff" < 0.1N$
]
)
Resampling was performed 6 times. The black line demarcates the threshold. Notice that $neff$ stays above
$N_"thr"$ longer when the dynamics are greater! I'm not sure if this is because it's more nonlinear or
something else, but it's something to maybe experiment with when I have some spare time.
changed the title [-]Add support for widow and orphan prevention within pages[/-][+]Headings do not always respect widow and orphan prevention[/+]on May 8, 2023
@mattharrison, please use a details tag to hide your code block, as it's just waaay too long and makes navigating through messages hard (though it is already a closed issue). (You can edit your comment.) You can also do it for the output image.
<details><summary>Summary text</summary>
```typ// Your Typst code.```
</details>
#show heading.where(level: 2): it => {//
[#it.body]
}
Mind explaining why this causes the algorithm to stop preventing orphans? I'd argue that this show rule is something anyone could write without expecting it to break all sorts of other things. Maybe a warning would help?
Headings should be blocks, so you should write #show heading.where(level: 2): it => block(it.body). Then, it will automatically pick up the built-in rule show heading: set block(sticky: true).
Since a show rule can fully override things, it's also easy to break stuff. Documentation on best practices when writing show rules (in general, and for specific elements) would be good. But warning is not really feasible as the compiler can't guess what you want.
Reacted by Juntong Chen, Martyn Loughran, Daniel Bershatsky and Tim
Headings should be blocks, so you should write #show heading.where(level: 2): it => block(it.body). Then, it will automatically pick up the built-in rule show heading: set block(sticky: true).
Is there anywhere you'd like to cast a block to content? (I'm not sure what the exact terminology for this is though. Is a block content? Anyway, cast it to non-block)
Else I'm pretty sure a warning like You are currently mapping a block to a __non_block__, which may make it lose some of its properties, including orphans prevention.
I can't reproduce it with this minimal example. I can't manage to get orphans with this setup.
That's because you wrote #it and that way you get your show rule on top of the built-in one. In your example, you used #it.body, thus throwing away the built-in show rule.
Else I'm pretty sure a warning like You are currently mapping a block to a non_block, which may make it lose some of its properties, including orphans prevention.
In normal circumstances, headings should be blocks, but it's perfectly valid to create a non-block heading if you want a run-in heading style, where the deeper headings become part of the paragraphs. Headings aren't blocks per se, they are just usually shown as blocks.
Activity
laurmaedje commentedon Apr 30, 2023
I also meant pages with this changelog entry. It should keep the first and last two lines together and also headings attached. The latter part might be buggy though. If you have concrete examples where it doesn't work that would be helpful.
matthewelmer commentedon Apr 30, 2023
laurmaedje commentedon Apr 30, 2023
Okay, I see. The heading fails to attach if what follows isn't a paragraph.
Enivex commentedon Apr 30, 2023
Some of these will presumably improve once typst has floats.
Is the idea similar to https://ctan.org/pkg/lua-widow-control?lang=en ?
[-]Add support for widow and orphan prevention within pages[/-][+]Headings do not always respect widow and orphan prevention[/+]ecstrema commentedon Dec 1, 2023
What will floats change to that issue?
mattharrison commentedon Jan 22, 2025
I'm seeing a lot of heading orphans in my book. I'm using typst version 0.12.0.
Is this bug really fixed?
Enivex commentedon Jan 22, 2025
Can you provide a minimal example?
The most likely explanation is that you have a show rule on headings that does not use the sticky flag on the block
mattharrison commentedon Jan 22, 2025
Here's a minimal (using my preamble) example,
Section 2 of chapter 1 is hanging out by itself at the bottom of page 5
Enivex commentedon Jan 22, 2025
I'm not sure I'd call that minimal, since there's a lot of stuff there that has nothing to do with headings.
The problem is this show rule
Andrew15-5 commentedon Jan 22, 2025
@mattharrison, please use a details tag to hide your code block, as it's just waaay too long and makes navigating through messages hard (though it is already a closed issue). (You can edit your comment.) You can also do it for the output image.
Summary text
// Your Typst code.As a side note on example making, from devenv repository I discovered https://sscce.org/, which is pretty much what everyone should know about MRE etc. And it's very short, too.
ecstrema commentedon Jan 23, 2025
Mind explaining why this causes the algorithm to stop preventing orphans? I'd argue that this show rule is something anyone could write without expecting it to break all sorts of other things. Maybe a warning would help?
laurmaedje commentedon Jan 23, 2025
Headings should be blocks, so you should write
#show heading.where(level: 2): it => block(it.body). Then, it will automatically pick up the built-in ruleshow heading: set block(sticky: true).Since a show rule can fully override things, it's also easy to break stuff. Documentation on best practices when writing show rules (in general, and for specific elements) would be good. But warning is not really feasible as the compiler can't guess what you want.
ecstrema commentedon Jan 23, 2025
I'm not sure this really is the problem though.
minimum example
I can't reproduce it with this minimal example. I can't manage to get orphans with this setup.
ecstrema commentedon Jan 23, 2025
Is there anywhere you'd like to cast a block to content? (I'm not sure what the exact terminology for this is though. Is a
blockcontent? Anyway, cast it to non-block)Else I'm pretty sure a warning like
You are currently mapping a block to a __non_block__, which may make it lose some of its properties, including orphans prevention.laurmaedje commentedon Jan 23, 2025
That's because you wrote
#itand that way you get your show rule on top of the built-in one. In your example, you used#it.body, thus throwing away the built-in show rule.In normal circumstances, headings should be blocks, but it's perfectly valid to create a non-block heading if you want a run-in heading style, where the deeper headings become part of the paragraphs. Headings aren't blocks per se, they are just usually shown as blocks.