Skip to content

unequivocal-ams: Made headings sticky to avoid orphaned headings - #94

Open
btmy87 wants to merge 3 commits into
typst:mainfrom
btmy87:feature/unequivocal-ams/sticky-headings
Open

btmy87 wants to merge 3 commits into
typst:mainfrom
btmy87:feature/unequivocal-ams/sticky-headings

Conversation

@btmy87

@btmy87 btmy87 commented Aug 29, 2026

Copy link
Copy Markdown

Making headings sticky to avoid orphaned headings.

Typst headings are wrapped in sticky blocks by default to avoid orphaned headings. The show rule that configures the AMS style headings access the body element directly, which removed the sticky behavior. This updates adds a sticky block into the show rule to restore the default behavior. This technique is recommended in the Typst documentation: https://typst.app/docs/reference/model/heading/

Changes:
Updated unequivocal-ams/lib.typ to add sticky blocks around headings.

Updated unequivocal-ams/template/main.typ to demonstrate sticky headings. With the previous template, the "REFERENCES" heading is orphaned. With the new template, it is no longer orphaned. To see the updated behavior, you'll need to point the import to the lib.typ file directly, instead of loading from @Preview.

Updated unequivocal-ams/lib.typ to add sticky blocks around headings.

Updated unequivocal-ams/template/main.typ to demonstrate sticky
headings.  With the previous template, the "REFERENCES" heading is
orphaned.  With the new template, it is no longer orphaned.  To see the
updated behavior, you'll need to point the import to the lib.typ file
directly, instead of loading from @Preview.
@elegaanz

Copy link
Copy Markdown
Member

Thank you for the fix. Can you just revert the changes made to template/main.typ please? It was useful to demonstrate the fix, but I don't think the default placeholder text should be that long. And the formatting should also not be touched.

Comment thread unequivocal-ams/lib.typ Outdated
set align(center)
set text(size: normal-size)
smallcaps[
block(sticky: true, smallcaps[

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A block but without sticky: true should be enough since there is a built-in show heading: set block(sticky: true).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are correct, wrapping in a plane block achieves the same effect. I'll make this change.

Comment thread unequivocal-ams/lib.typ Outdated
let styled = if it.level == 2 { strong } else { emph }
styled(it.body + [. ])
h(7pt, weak: true)
block(sticky: true, {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The block breaks the intent of the level 2+ headings being run-in. Moreover, with the v(11pt, weak: true) and similar being inside of the block now, the spacing is not the same as before (though I cannot test it right now). Overall, the change set feels not well-tested to me.

Unfortunately, I just noticed, the run-in style was already previously broken in 019502e. :/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree. Moving the vertical space outside of the block restores the prior spacing while preserving the sticky effect.

Not sure about the intent of the horizontal space at the end of the block. Should this be outside the block as well. Do you have an example that demonstrates the intended effect?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The intended effect can be observed by reverting 019502e. The heading is supposed to be run-in, i.e. in line with the following text. The h is supposed to add a little space between heading and contents.

It should look roughly like this:

end of the previous paragraph ...

A section.    And here are its contents.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This run-in style is fundamentally incompatible with using a block. But it's also inherently sticky, so that shouldn't be an issue per se.

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.

3 participants