Skip to content

Allow equation and tight lists/enums to be part of paragraphs - #7931

Open
mkorje wants to merge 4 commits into
typst:mainfrom
mkorje:par-math
Open

mkorje wants to merge 4 commits into
typst:mainfrom
mkorje:par-math

Conversation

@mkorje

@mkorje mkorje commented Mar 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3206.

This PR adds a new internal field inlinable to block(), which allows blocks that are next to paragraph-level content (and other inlinable blocks) to become part of the paragraph. Block equations and tight lists/enums now have this property.

The field is being kept internal for now as the design is still undecided and subject to change (if it is to be exposed at all).

The implementation is almost complete and is working, but there are some things that need discussion still - to be updated soon™.

More details

  • The inlinable field is internal.
  • An inlinable block together with paragraph-level content joins the paragraph.
  • A single inlinable block stays block-level, whereas multiple inlinable blocks together become a paragraph.
  • The rules for tight ListElems and EnumElems now construct BlockElems with inlinable: true.
  • The rule for a block EquationElem constructs a BlockElem with inlinable: true.
  • With the way tight lists/enums work you can end up with some perhaps odd/unexpected behavior:
    Blah paragraph:
    - A
    - B
    - C
    
    // This isn't a new list and par, but makes the whole list not tight!
    // Not tight list = a paragraph, a block, and another paragraph.
    - A
    - B
    - C
    New paragraph?

Todos

  • Verify that pdftags test changes are okay
  • Fix issue-6242-tight-list-attach-spacing test regression
  • Add tests
  • Sort out window/orphan need calculation in typst_layout::flow::distribute::Collector::par_children

@laurmaedje laurmaedje added math Related to math category, with its syntax, layout, etc. model Related to model category, which is all about structure and semantics. and removed math Related to math category, with its syntax, layout, etc. labels Mar 2, 2026
@SeSodesa

SeSodesa commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Without actually reviewing the code, was the edge case of a block equation being in the middle of a paragraph handled? A block equation might end a paragraph, but the text block following a block equation might also be a part of the same paragraph. Does the single proposed new field allow differentiating between these 2 cases, or is this simply handled by the usual empty lines in markup mode? What if such a paragraph is created in code mode?

A block equation starting a paragraph is never appropriate. That case does not need to be considered as a valid structure.

@Enivex

Enivex commented Mar 2, 2026 •

Copy link
Copy Markdown
Collaborator

A block equation starting a paragraph is never appropriate

I wouldn't make such categorical statements. There's a lot of diversity out there.

Edit: A simple example would be $ ... $ is known as the (...) equation. Or a "paragraph" consisting of a single equation and nothing more.

@mkorje

mkorje commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator Author

Here's a summary of the behaviour, using its hypothetical HTML equivalent to make things clear.

Note that having an equation on its own in a paragraph is not covered by this. It's just a single block then.

#lorem(20)

$ x + y $

#lorem(20)
<p>Lorem...</p>
<math>...</math>
<p>Lorem...</p>
#lorem(20)
$ x + y $

#lorem(20)
<p>
  Lorem...
  <math>...</math>
</p>
<p>Lorem...</p>
#lorem(20)

$ x + y $
#lorem(20)
<p>Lorem...</p>
<p>
  <math>...</math>
  Lorem...
</p>
#lorem(20)
$ x + y $
#lorem(20)
<p>
  Lorem...
  <math>...</math>
  Lorem...
</p>
$ x + y $
$ y + z $
<p>
  <math>...</math>
  <math>...</math>
</p>

As for creating paragraphs in code, I think it should work the same as whatever works currently. (I need to check, as I'm not entirely sure how the paragraph grouping works in code mode...)

@fabianbosshard

Copy link
Copy Markdown

A block equation starting a paragraph is never appropriate. That case does not need to be considered as a valid structure.

In most cases that may be true, but I think it’s important to leave the choice to the user.
As a student who needs to take notes, write summaries, etc., I find myself quite often in the scenario where I start with an equation and then continue with e.g. “where A is the area of…” or something like that.

@SeSodesa

SeSodesa commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

As a student who needs to take notes, write summaries, etc., I find myself quite often in the scenario where I start with an equation and then continue with e.g. “where A is the area of…” or something like that.

But you then go on to re-read your notes and fix your language, especially if you intend to send them for somebody else to read, right? I would not expect that personal quick notes necessarily conform to good writing practices, so what Typst does to the tag structure there does not really matter. But if I was your supervisor or a reviewer at a journal and you handed me your thesis or an article with an equation starting a paragraph, it would be something you would have to fix in the next revision.

A better argument for allowing an equation to start a paragraph would be that the accessible PDF standards allow it (do they?), and therefore we should not apply additional restrictions.

@SeSodesa

SeSodesa commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Note that having an equation on its own in a paragraph is not covered by this. It's just a single block then.

Yeah, this is semantically the correct thing to do. A paragraph by definition implies prose, possibly combined with other content. It would be misleading for screen readers if something that is not written discourse (which an equation by itself cannot be) would be marked as such.

Actually, because of the last point, even 2 equations side by side should really not generate a paragraph in my humble opinion. They would generate 2 separate block equations. Unless of course there is a "proper paragraph" attached to them.

@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Mar 3, 2026
@fabianbosshard

Copy link
Copy Markdown

But you then go on to re-read your notes and fix your language, especially if you intend to send them for somebody else to read, right? I would not expect that personal quick notes necessarily conform to good writing practices, so what Typst does to the tag structure there does not really matter. But if I was your supervisor or a reviewer at a journal and you handed me your thesis or an article with an equation starting a paragraph, it would be something you would have to fix in the next revision.

@SeSodesa I agree that in most cases it doesn’t make sense to start a paragraph with an equation. However, that doesn’t mean this should be enforced by the typesetting system itself. Otherwise, we could just as well argue that integral signs should be disallowed in inline math because they’re often considered poor style.

Correct me if I'm wrong, but this seems to be not merely a question of “good” style, but also one about (future) functionality. A typesetting system should not hard-code a specific editorial philosophy or writing convention.

Moreover, as @Enivex pointed out, there are legitimate cases where an equation can start a paragraph. Style requirements can still be enforced by supervisors or journals where needed. But the tool itself shouldn’t artificially prohibit structurally valid constructs.

I actually encountered this issue while experimenting with the interaction between text and display equations. In LaTeX, display equations are placed tightly relative to surrounding text when no blank lines are present: \abovedisplayskip or \abovedisplayshortskip before the equation (depending on the preceding line length), and \belowdisplayskip or \belowdisplayshortskip after it. Only when there is a blank line, an additional \parskip is added on the corresponding side.

I imagine that the variable under discussion could be used to implement a similar spacing mechanism in Typst, making the spacing more responsive to the semantics of the surrounding content. If a paragraph begins with a display equation and is followed directly by text (without a blank line), no additional paragraph spacing (parskip) should be inserted. Instead, it should use the same vertical spacing as a display equation that is surrounded by text on both sides.

@fabianbosshard

fabianbosshard commented Mar 4, 2026 •

Copy link
Copy Markdown

I just did some further experimenting and it seems my previous comment oversimplifies the exact mechanism in LaTeX. There is some other small space inserted in some cases, but to be honest I don't understand the exact rules applied here. Here is the experiment:

\documentclass[12pt]{article}
\begin{document}
\pagestyle{empty}



\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0pt minus 0pt} 

\setlength{\abovedisplayskip}{0pt plus 0pt minus 0pt}
\setlength{\abovedisplayshortskip}{0pt plus 0pt minus 0pt}
\setlength{\belowdisplayskip}{0pt plus 0pt minus 0pt}
\setlength{\belowdisplayshortskip}{0pt plus 0pt minus 0pt}



\setlength{\topsep}{0pt plus 0pt minus 0pt}
\setlength{\partopsep}{0pt plus 0pt minus 0pt}

\setlength{\baselineskip}{0pt plus 0pt minus 0pt}


% ---------------------------------

\setlength{\parskip}{20pt plus 0pt minus 0pt}

A long long long long long long long long long line
\[
E=mc^2
\]

\vspace{1em}

\textbf{is (as expected) \emph{not} the same as}

\vspace{1em}


A long long long long long long long long long line

\[
E=mc^2
\]

\setlength{\parskip}{0pt plus 0pt minus 0pt}


\vspace{4em}
-----------------------------------
\vspace{4em}




\setlength{\baselineskip}{12pt plus 0pt minus 0pt}

A long long long long long long long long long line
\[
E=mc^2
\]

\vspace{1em}

\textbf{is also \emph{not exactly} the same as}

\vspace{1em}


A long long long long long long long long long line

\[
E=mc^2
\]



\vspace{4em}
-----------------------------------
\vspace{4em}



\setlength{\baselineskip}{11pt plus 0pt minus 0pt}


A long long long long long long long long long line
\[
E=mc^2
\]

\vspace{1em}

\textbf{now it \emph{is} the same as}

\vspace{1em}


A long long long long long long long long long line

\[
E=mc^2
\]



\end{document}

In any case, the general idea still holds: the spacing around display equations in LaTeX depends on the surrounding structure (paragraph boundaries, line lengths, spacing, etc.), which allows the layout to adapt to context. A similar mechanism in Typst - where the spacing of a display equation depends on whether it appears within a paragraph, at a paragraph boundary, or as a standalone block - could make equation spacing more semantically appropriate. Additionally, if the preceding line is short relative to the width of the equation, the spacing above the display could be reduced further, similar to how TeX uses \abovedisplayshortskip in that situation. As others (#2438) have pointed out, that would not only look nicer, but also increase available space on pages with many equations.

@mkorje mkorje Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#5510 (fixed by #6242) has regressed.

@mkorje mkorje Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Whether this is actually a bug now though is unclear (at least to me). The nested tight list is now part of a single paragraph along with the rest of the list item's body. So should paragraph leading be used or not (i.e. the set list spacing) before the first list item?

Comment on lines +518 to +524
Item::Block(elem, styles) => {
// We need owned values as the `ParChild::Block` created
// will outlive inline layout.
block_elem = Some((*elem).clone());
block_styles = Some(styles.to_map());
block_idx = Some(idx);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will StyleChain::to_map() have a big performance impact?
We need to get an owned version of the StyleChain onto the ParChild::Block enum variant

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.

It's not that big of a deal. Potentially though, it could use .suffix and chain that map with the shared paragraph-wide styles. Similarly to what's done in fn repack in typst-realize. That'd be a little more efficient and also conceptually cleaner.

Comment on lines +198 to +207
// TODO: collect frames for widow/orphan prevention calculation. Should
// frames only (not blocks) participate in widow/orphan prevention?
// Regardless, the code here is a little weird.
let frames: Vec<_> = children
.iter()
.filter_map(|c| match c {
ParChild::Frame(f) => Some(f),
ParChild::Block { .. } => None,
})
.collect();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is very wrong currently (but does appear to be benign).

@saecki

saecki commented Mar 31, 2026 •

Copy link
Copy Markdown
Member

Most of the changes regarding PDF tags are fine. The paragraphs missing from some list bodies aren't an issue. What I'd consider a regression is the nesting of lists inside the list body (enum-number-override-nested and the list-tags-complex tests). This best practice guide describes that nested lists should be represented as direct children of the parent list in 4.2.5.1: https://pdfa.org/download-area/publications/Tagged-PDF-Best-Practice-Guide.pdf
typst-pdf actually has an extra pass that rearranges the tags for this:

pub fn push_body(&mut self, groups: &mut Groups, list: GroupId, body: GroupId) {

This only seems to happen if there are list items that are tightly spaced and then a widely spaced item after that:

- a
  - Indented

- b // Parbreak forces the list to be wide.

Here's the debug output of my debug-pdf-tags branch comparing main to the PR. Diffing is a sadly a little fuzzy because of the location hashes (and because the output is very verbose), but the main difference seems to be that on main there is a paragraph that groups only the text inside the first list item, and in this PR the paragraph spans the nested list too.

main
=== frames ===
[crates/typst-pdf/src/tags/tree/build.rs:201:9] &page.frame = Frame [
    Start("item", Location(17212)),
    Start("list", Location(37669)),
    Start("pdf-marker-tag", Location(59320)),
    Text("•"),
    End(Location(59320)),
    Group Frame [
        Start("pdf-marker-tag", Location(58334)),
        Start("par", Location(29122)),
        Text("a"),
        End(Location(29122)),
        Start("item", Location(54946)),
        Start("list", Location(63932)),
        Group Frame [
            Start("pdf-marker-tag", Location(20721)),
            Text("‣"),
            End(Location(20721)),
            Start("pdf-marker-tag", Location(32160)),
            Text("Indented"),
            End(Location(32160)),
        ],
        End(Location(63932)),
        End(Location(54946)),
        End(Location(58334)),
    ],
    Group Frame [
        Start("pdf-marker-tag", Location(3627)),
        Text("•"),
        End(Location(3627)),
        Start("pdf-marker-tag", Location(63598)),
        Start("par", Location(27817)),
        Text("b"),
        End(Location(27817)),
        End(Location(63598)),
    ],
    End(Location(37669)),
    End(Location(17212)),
    Start("item", Location(51167)),
    End(Location(51167)),
]

=== tags ===
START 0 item
  START 1 list
    START 2 pdf-marker-tag ListItemLabel
text
    END   2 pdf-marker-tag
> group
    START 3 pdf-marker-tag ListItemBody
      START 4 par
text
      END   4 par
      START 5 item
        START 6 list
> group
          START 7 pdf-marker-tag ListItemLabel
text
          END   7 pdf-marker-tag
          START 8 pdf-marker-tag ListItemBody
text
          END   8 pdf-marker-tag
< group
        END   6 list
      END   5 item
    END   3 pdf-marker-tag
< group
> group
    START 9 pdf-marker-tag ListItemLabel
text
    END   9 pdf-marker-tag
    START 10 pdf-marker-tag ListItemBody
      START 11 par
text
      END   11 par
    END   10 pdf-marker-tag
< group
  END   1 list
END   0 item
START 12 item
END   12 item

=== tree ===
group Root Id::<Group>(0)
  group List Id::<Group>(1)
    group Standard Id::<Group>(11)
      group ListItemLabel Id::<Group>(2)
        leaf
      group ListItemBody Id::<Group>(3)
        group Par Id::<Group>(4) (weak)
          leaf
    group List Id::<Group>(5)
      group Standard Id::<Group>(12)
        group ListItemLabel Id::<Group>(6)
          leaf
        group ListItemBody Id::<Group>(7)
          leaf
    group Standard Id::<Group>(13)
      group ListItemLabel Id::<Group>(8)
        leaf
      group ListItemBody Id::<Group>(9)
        group Par Id::<Group>(10) (weak)
          leaf
PR
=== frames ===
[crates/typst-pdf/src/tags/tree/build.rs:201:9] &page.frame = Frame [
    Start("item", Location(16966)),
    Start("list", Location(27103)),
    Start("pdf-marker-tag", Location(24678)),
    Text("•"),
    End(Location(24678)),
    Group Frame [
        Start("pdf-marker-tag", Location(40426)),
        Start("par", Location(45515)),
        Text("a"),
        Start("item", Location(39568)),
        Start("list", Location(13436)),
        Group Frame [
            Start("pdf-marker-tag", Location(21467)),
            Text("‣"),
            End(Location(21467)),
            Start("pdf-marker-tag", Location(11517)),
            Text("Indented"),
            End(Location(11517)),
            End(Location(13436)),
            End(Location(39568)),
        ],
        End(Location(45515)),
        End(Location(40426)),
    ],
    Group Frame [
        Start("pdf-marker-tag", Location(19885)),
        Text("•"),
        End(Location(19885)),
        Start("pdf-marker-tag", Location(16079)),
        Start("par", Location(26183)),
        Text("b"),
        End(Location(26183)),
        End(Location(16079)),
    ],
    End(Location(27103)),
    End(Location(16966)),
    Start("item", Location(4100)),
    End(Location(4100)),
]

=== tags ===
START 0 item
  START 1 list
    START 2 pdf-marker-tag ListItemLabel
text
    END   2 pdf-marker-tag
> group
    START 3 pdf-marker-tag ListItemBody
      START 4 par
text
        START 5 item
          START 6 list
> group
            START 7 pdf-marker-tag ListItemLabel
text
            END   7 pdf-marker-tag
            START 8 pdf-marker-tag ListItemBody
text
            END   8 pdf-marker-tag
          END   6 list
        END   5 item
< group
      END   4 par
    END   3 pdf-marker-tag
< group
> group
    START 9 pdf-marker-tag ListItemLabel
text
    END   9 pdf-marker-tag
    START 10 pdf-marker-tag ListItemBody
      START 11 par
text
      END   11 par
    END   10 pdf-marker-tag
< group
  END   1 list
END   0 item
START 12 item
END   12 item

=== tree ===
group Root Id::<Group>(0)
  group List Id::<Group>(1)
    group Standard Id::<Group>(11)
      group ListItemLabel Id::<Group>(2)
        leaf
      group ListItemBody Id::<Group>(3)
        group Par Id::<Group>(4) (weak)
          leaf
          group List Id::<Group>(5)
            group Standard Id::<Group>(12)
              group ListItemLabel Id::<Group>(6)
                leaf
              group ListItemBody Id::<Group>(7)
                leaf
    group Standard Id::<Group>(13)
      group ListItemLabel Id::<Group>(8)
        leaf
      group ListItemBody Id::<Group>(9)
        group Par Id::<Group>(10) (weak)
          leaf

@mkorje

mkorje commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

Another issue to mention: lists aren't valid inside paragraph tags in HTML...

@SeSodesa

SeSodesa commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What are the consequences of invalid tag structure in this case? Do browsers just not render the document? Do they force a paragraph break at the list start boundary as a means of recovery?

Although I guess none of this matters if we aim to be standards-compliant as much as possible. Maybe we should be the ones to just emit a paragraph end tag before lists in the case of HTML.

@laurmaedje laurmaedje left a comment

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.

I've pondered and discussed this with @reknih some more and I think I'm overall happy with the inlinable blocks concept. I would still keep it internal for now, but I think I can see it being exposed, too. My thoughts on the open design questions and the existing implementation are below.

These thoughts built up over a few hours each yesterday and today, so they are fairly fresh and not necessarily to be considered final. Consider them more an invitation for further discussion.

Design

Mixed flows (re. spacing and PDF tagging for tight lists)

On the regression of issue-6242-tight-list-attach-spacing: I think it is closely related to the issue with PDF tagging that @saecki raised. We could try to work around both issues, but the root cause is that the A text, and the B and C list items form a paragraph in:

- A
  - B
  - C
- C

I think that's semantically wrong. The semantics are also wrong on main, where just "A" is a paragraph. I think really there ought to be no paragraph here.

To fix this, I think we need to take the work I started in #5746 even further. This PR added support for non-par inline layout. What we need here is non-par mixed layout, where the inline parts of it go through non-par inline layout and the rest uses normal flow layout.

This non-par mixed layout would really be a refactored extended version of the existing non-par inline layout and would be triggered by fully inline or inlinable content in containers (dropping the change to is_fully_inline_or_neutral in the process). Proper block-level content (non-inlinable) would still force adjacent inline content into a paragraph.

Subtly, but importantly, I think the block parts of such a mixed layout would be treated as normal blocks in this flow and not as inlined blocks in a non-par inline layout. As a consequence they would get normal block treatment and respect block.spacing (unlike inlined blocks, which currently don't respect this property and I believe rightly so since paragraphs use leading).

In this setup, perhaps we could use normal block.above spacing instead of the special v attach spacing for tight lists? The existing special attach v spacing was primarily needed due to special interactions with parbreaks which would be superseded by the inlinable blocks work.

Two tight lists vs one wide list

On the issue brought up about this being one wide list instead of two paragraphs, each with a tight list:

Blah paragraph:
- A

- C
New paragraph?

With this PR it gets a little worse, but the issue already exists on main (#3062) with cases like this:

- A
- B

- A
- B

You would expect this to be two tight lists, but it's one wide list. I could potentially see adjusting the rules so that it only becomes a wide list if there are parbreaks between all items and around the full list1. That should fix both situations. (I think?)

I also recall discussing this with @isuffix, though I don't recall whether we reached the same conclusion. One thing to note is that this kind of change is definitely a candidate for very silent breakage... so, if we do this, perhaps also a candidate for upcoming migration tooling? Overall, I would say, it's probably best to deal with this issue separately from this PR. I don't think the PR worsens the situation by a lot as I imagine paragraphs starting with a list, following a paragraph ending with one, to be rather rare.

Paragraphs only consisting of inlinable blocks

My gut feeling is that it makes more sense to only create a paragraph if there is something properly inline in play. Multiple inlinable blocks following each other feel like they should remain normal blocks to me. If you really want them in a paragraph, you could wrap them in a #par(..) call.

Generally, I would probably make the inlinable property all about grouping. All it does would be to define that the block can group into a paragraph if adjacent to inline-level material. The paragraph itself would generally gain the ability to hold blocks, i.e. if I explicitly put a block into a #par(..) call, it becomes irrelevant whether it's inlinable. It's just in there. (Whereas today, it warns with "block may not occur inside of a paragraph and was ignored".) Potentially, the paragraph could also gain the ability to hold further things like place in the future. (This would help with #3967.)

Lists in paragraphs in HTML

As mentioned above, the content model of <p> forbids <ul> and <ol> elements. I dug a little deeper into why this is the case. The WhatWG mailing list has an interesting discussion from 2011 about this.

Ian Hickson (who seems to have done a lot of work on HTML5) doesn't really think the construct makes sense at all. While I disagree, at least he proposes a DOM structure to express the situation, which I think we should adopt. The proposed structure of a paragraph containing inlinable blocks would simply be a <div> containing multiple <p>s with the block content in between. I would propose adding a class (or maybe a role?) to that <div>.

Alternatives I see include (1) not writing anything extra or (2) writing a class on the "continuation" paragraphs. Non-alternatives include just ignoring the spec. Even if we wanted to do that (which we don't), it wouldn't work because the HTML parser will auto-close <p> tags when it sees a list, so the DOM would just be messed up.

Implementation

I think the implementation is a good start, but I would propose one major change and a few smaller ones. The outcomes of the design thoughts above might of course further affect implementation (in particular, the mixed flow stuff).

Inline layout

Currently, blocks are dragged all the way through inline layout. This necessitates subtle changes to inline collection, line layout, line breaking, finalization, and tag handling.

I would propose an alternative direction. Instead of treating blocks as opaque items in inline layout that are just extracted again in the end, we could already perform the splitting during collection and collect multiple sub-inline-layouts that are individually prepared, linebreaked, and finalized.

A few comments I had written up on the implementation that would be superseded by this high-level proposal.
  • The code currently crashes on Consider~$ x + y $ because icu4x does not emit a breakpoint due to the nbsp.

  • The linebreaking change could use a comment. Also, can we use \n before it instead? We already use it after it?

  • The code in fn commit looks a bit unclean... it's purpose is to get the tags and the lone block out of the Line struct. And the sorting is also an artifact of having BiDi reordering happen which is kind of pointless in the first place.

Another thing is that end tags are currently in the wrong position (at (0,0) in the frame).2 Also, end tags for breakable blocks are pushed into the first frame, when they should be put after the last frame (if spilled). Both of these could likely be solved by emitting tags as separate ParChild::Tag around the block and turning these into Child::Tag in the flow. I didn't test whether there are any issues with this, though, so take this with a grain of salt.

On the widow/orphan prevention: Probably, blocks should also participate in it? (I mean, ideally on a line-by-line basis for equations, but I'd consider that out of scope.) The code duplication for widow/orphan prevention would also be good to avoid.

Realization

I think it'd be nice to have a bit less special casing and instead introduce a new grouping effect. We could call it Tentative, but maybe there is also a semantically clearer name. The semantics would be that the tentative elements would be finished with the group if the group contains at least one trigger element, but if the group only ends up with tentative and inner elements, it is dissolved without finishing (the decision on "Paragraphs only consisting of inlinable blocks" is relevant here). We'd need to make sure to drop inner elements between tentative ones if there ends up being no trigger element or else we could end up with SpaceElems in flow layout.

The style handling code in finish_interrupted feels like a bit of hack, but I suppose it would be okay. The interruption mechanism is already a bit ad-hoc and special cases AlignElem, so this extra special case does not change things a lot. But perhaps, it should be made a bit more targeted. I think it's okay to ignore both par and align styles, but I would make the exception specific to par grouping.

Testing

One thing that I think would be good to test is the within selector on par and list for an inlined list.

Docs

We'll need to update the relevant explanations in the docs and probably adjust various docs examples (e.g. that for block.spacing)

Footnotes

  1. I could also imagine a variation where the parbreaks around are only necessary if there's inline stuff next to it, not if the stuff around is already block-level. Not sure about that. ↩

  2. Currently the position of end tags is unused, but this may change. ↩

regions.expand.y &= self.alone;
// For inline blocks, use the line width as the width constraint.
if let Some((line_width, _, _)) = self.inline {
regions.size.x = line_width;

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 seems to affect no test. What's the idea here?

let align = styles.resolve(AlignElem::alignment);
let locator = self.locator.next(&elem.span());

if breakable {

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 does not have the fr.is_some() check that the normal block branch has. Is there a reason for this?

@laurmaedje laurmaedje added waiting-on-author Pull request waits on author and removed waiting-on-review This PR is waiting to be reviewed. labels Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Related to model category, which is all about structure and semantics. waiting-on-author Pull request waits on author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paragraph should be able to contain tight lists and block-level equations

6 participants