Skip to content

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

Open

Description

@Enivex

Currently, a tight list attaches to the preceding paragraph when there is no whitespace, and a new paragraph is always created after the list.

image

In this case, this behavior is not desirable, because everything here is really part of the same paragraph.

For comparison, the behavior in LaTeX is that the next line is also part of the paragraph (new paragraphs are indented by default)
image

unless whitespace is added
image

Activity

  1. added
    text
    model
    on Jan 16, 2024
  2. corvulus-morti commented on Apr 29, 2024

    @corvulus-morti

    This is related to how typst handles paragraphs. A list is a different element than a paragraph, so, no matter how many lines are placed between the list and the next piece of content, it will treat the next piece of content as its own paragraph.

    A paragraph is only indented if it follows another paragraph (and has first-line-indent != 0 and some alignment stuff). Typst doesn't consider a list a paragraph. Hence, the content that comes after the list will be its own paragraph, and that paragraph will not be indented.

    I've forked the repo, because I think the paragraph element is too limited as it is. I'm attempting to change that.

  3. changed the title [-]Interaction between lists and paragraphs[/-] [+]Interaction between paragraphs and block elements like lists and equations[/+] on Sep 17, 2024
  4. Enivex commented on Sep 17, 2024

    @Enivex
    CollaboratorAuthor

    I modified the title to reflect that this is a wider issue

  5. Enivex commented on Sep 18, 2024

    @Enivex
    CollaboratorAuthor

    Another example: Figures that are not top or bottom

  6. laurmaedje commented on Sep 18, 2024

    @laurmaedje
    Member

    I'm not really convinced that a figure really makes sense as part of a paragraph.

  7. corvulus-morti commented on Sep 18, 2024

    @corvulus-morti

    I'm not really convinced that a figure really makes sense as part of a paragraph.

    How sensical you or anyone else thinks it is doesn't matter.
    This is a typesetting software.
    Disallowing some sort of formatting because it doesn't make sense to someone would be limiting.

    A figure is a block of content.
    A paragraph is a string of connected ideas.
    If one of those ideas is best given as an equation block, code block, figure block, etc., then discriminating between content blocks is limiting to the string of connected ideas used to form the paragraph.

  8. laurmaedje commented on Sep 18, 2024

    @laurmaedje
    Member

    We don't disallow putting arbitrary stuff in paragraphs, that's what the box function is for. (For what it's worth, HTML does disallow block-level elements in paragraphs.) The question here is how various elements interact when not explicitly boxed --- that's a question of language design and thus it definitely matters what me or anyone else thinks (you obviously believe that it matters what you think after all). If you want to be constructive, you are invited to make your point. But please stay friendly.

  9. corvulus-morti commented on Sep 18, 2024

    @corvulus-morti

    I'm sorry if I seemed rude in my previous comment. I in no way meant it antagonistically. My apologies!

  10. changed the title [-]Interaction between paragraphs and block elements like lists and equations[/-] [+]Paragraph should be able to contain tight lists and block-level equations[/+] on Feb 6, 2025
  11. OrangeX4 commented on Feb 20, 2025

    @OrangeX4

    For some people who need a workaround (or maybe it's the only right solution?) :

    #set page(width: 30em)
    #set par(first-line-indent: (amount: 2em, all: true))
    #set math.equation(numbering: "(1.1)")
    
    #lorem(10), for example,
    #box[$ integral x + y = z $]
    shows that the integral of $x + y$ is $z$.
    
    #lorem(20)

    Image

  12. Enivex commented on Feb 22, 2025

    @Enivex
    CollaboratorAuthor

    Yes, that is probably more or less how "block" equations should've worked in the first place.

  13. Yangchengran commented on Mar 6, 2025

    @Yangchengran

    I tried to use the #box function, but still need to use parbreak when set the justify to be true.

    #set par(justify: true, first-line-indent: (amount:2em, all:true))
    #set math.equation(numbering: "(1.1)")
    
    This is a line
    #box($ x_1 + x_2 = x_3 $)
    This is a new line
    
    #line(length:100%)
    
    This is a line
    \ #box($ x_1 + x_2 = x_3 $)
    This is a new line

    Image

  14. 13 remaining items

  15. TheColdPot commented on Dec 13, 2025

    @TheColdPot

    not a pretty way, but if you insert this code into the end of the set and show rules, it works fine.

    #show: it => {
      let cnt = -1
      let processing = 0
      for child in it.children {
        cnt += 1
        if (processing >= 2) {
          processing -= 1
          continue
        } else if (processing == 1) {
          processing -= 1
          context h(-par.first-line-indent.amount) + child
          continue
        }
        child
        if (
          cnt < it.children.len() - 2
            and ((child.func() == math.equation and child.block) or child.func() == list.item or child.func() == enum.item)
            and it.children.at(cnt + 1).func() != parbreak
            and it.children.at(cnt + 2).func() == text
        ) {
          processing = 2
        }
      }
    }

    It still destroys the sematic features by breaking the paragraph before & after. So this does not really solve the problem - we still need a language-level feature for this. Anyhow thanks for the temporal solution <3

    At least I think it makes sense to make an equation a part of a paragraph. Simply, I would suggest giving an option to make display equations distinct from block equations, where the former appears as an independent line but act as an inline box, not a block.

    Although being a fan of Typst, I don't know that much of Typst's philosophy. So for community is it a good idea to be some sort of compiler options, bring a breaking change, or introduce a settable parameter of math.equation?

  16. N3xed commented on Jan 23, 2026

    @N3xed

    Just came across this, the current behavior of equations and lists is pretty bad. I guess manually inserting space is all that's possible at the moment. first-line-indent: (amount: 2em, all: true) actually makes the problem worse since this prevents (at least the visual) look that equations are within the same paragraph completely (without other show rule trickery, which I don't think is worth the hassle).

  17. reveperdu commented on Feb 7, 2026

    @reveperdu

    Block equations might as well be a different case from lists, I guess this is somewhat specific to chinese typesetting and might be considered part of the language support.

  18. YDX-2147483647 commented on Feb 8, 2026

    @YDX-2147483647
    Contributor

    Here's an improved version of #3206 (comment) that also supports labeled equations. (Before $ x $ <eq> After has two [ ] after the equation.)

    #set par(first-line-indent: (all: true, amount: 2em))
    
    // This show rule should be put after other show/set rules.
    #show: rest => {
      let immediately-after = false
    
      for it in rest.children {
        // If this text is immediately after special elements (block equations etc.), compensate the first-line indent.
        if immediately-after and it.func() == text {
          context h(-par.first-line-indent.amount)
        }
        it
    
        // If it is a space, consider we are still immediately after.
        // Notes:
        // - A single `\n` becomes a spaces, and a space between an equation and a label is still a space.
        // - Two consecutive `\n` become a parbreak.
        if it != [ ] {
          immediately-after = false
        }
    
        // Detect special elements.
        if (
          (it.func() == math.equation and it.block)
            or it.func() == list.item
            or it.func() == enum.item
        ) {
          immediately-after = true
        }
      }
    }

    Known limitation: If the text immediately after a special element (a block equation or similar things) starts with strong, link, or anything that makes it.func() ≠ text, then it does not work. Please manually insert a #h(-2em) or #context h(-par.first-line-indent.amount).


    It still destroys the sematic features by breaking the paragraph before & after

    In addition, the vertical spaces around block equations should be par.leading, but this workaround uses par.spacing.


    somewhat specific to chinese typesetting

    I agree. See https://gap.zhtyp.top/#indent-after-block.

    Image
  19. Enivex commented on Feb 8, 2026

    @Enivex
    CollaboratorAuthor

    Block equations might as well be a different case from lists, I guess this is somewhat specific to chinese typesetting and might be considered part of the language support.

    I don't understand why chinese typesetting is relevant here? The same problem is present regardless of language.

  20. reveperdu commented on Feb 8, 2026

    @reveperdu

    I don't understand why chinese typesetting is relevant here? The same problem is present regardless of language.

    For block equations, I notice in some English materials, the paragraph immediately after a block equation isn't indented even if they are (semantically) a new paragraph, which matches the default behavior of first-line-indent, without all:true, and some English materials don't use first line indents at all.

    So while in chinese it's common to distinguish whether the line after the block equations is a new paragraph (if a new paragraph, indent), I thought typesetting in other languages might not enforce such rules, and it won't be a problem if block equations cannot be put into the paragraph, perhaps?

  21. Shuenhoy commented on Feb 9, 2026

    @Shuenhoy

    I don't understand why chinese typesetting is relevant here? The same problem is present regardless of language.

    For block equations, I notice in some English materials, the paragraph immediately after a block equation isn't indented even if they are (semantically) a new paragraph, which matches the default behavior of first-line-indent, without all:true, and some English materials don't use first line indents at all.

    So while in chinese it's common to distinguish whether the line after the block equations is a new paragraph (if a new paragraph, indent), I thought typesetting in other languages might not enforce such rules, and it won't be a problem if block equations cannot be put into the paragraph, perhaps?

    I don't think it is specific to Chinese typesetting. By semantics, block equations should be part of a paragraph, and I cannot understand why there would be special rule that the next paragraphs of block equations should not be indented. The most possible cause I guess is that the creators of that materials were unaware.

    I randomly open an ACM publication and immediately found they properly distinguish two cases:
    Image

  22. SeSodesa commented on Feb 18, 2026

    @SeSodesa
    Contributor

    I'm not really convinced that a figure really makes sense as part of a paragraph.

    You are correct, at least from a semantic point of view. In terms of structural PDF or HTML tagging, it makes no sense to have figures inside of paragraph tags.

  23. tianyi-smile commented on Apr 30, 2026

    @tianyi-smile

    The parize package now gives an experimental solution, offering more flexible control over block-level elements and exploring how this paragraph model affects Typst typesetting.

    Performance improvements and bug fixes in version 0.2.1

    Example One:

    Image
    Code:
    #import "@preview/parize:0.2.1": *
    #set page(margin: 1cm, height: auto, width: 25cm)
    #set par(justify: true)
    #table(
    columns: (1fr, 1fr),
    [
      #import "@preview/zebraw:0.6.3": *
      #show: zebraw
      ```typst
      #import "@preview/parize:0.2.1": *
      #set par(first-line-indent: (amount: 2em, all: true))
      #show strong: set text(fill: red, size: 1.2em) // debug
      #set block(stroke: red) // debug
      #show: par-indent.with(
        include-elem: (heading, math.equation, list, enum, terms, ), // Enable paragraph indentation control for heading, math.equation, list, enum and terms
        use-par-leading: true, // Enable paragraph spacing control for list, enum and terms
      )
      #set heading(numbering: "1.")
      = Heading
    
      *Indented* #lorem(10)
    
      _Equation Test_. #lorem(8)
      $
        a^2 + b^2 = c^2
      $
      *Unindented* #lorem(10)  // This paragraph remains unindented (no parbreak before equation)
    
      #lorem(2)
    
      $
        a^2 + b^2 = c^2
      $
    
      *Indented* #lorem(10)
    
      _Tight Lists Test_. #lorem(10)
      + #lorem(2)
      + #lorem(2)
      *Unindented and par-leading* #lorem(8)  // Unindented with paragraph-leading spacing
    
      = Heading
      *Unindented* #lorem(10)
    
      + #lorem(2)
      + #lorem(2)
    
      *Indented* #lorem(10)
    
      _Non-tight Lists Test_. #lorem(2)
    
      - #lorem(2)
    
      - #lorem(2)
      *Unindented* #lorem(2)  // Paragraph following lists without empty line
      ```
    ],
    [
      #show strong: set text(fill: red, size: 1.2em) // debug
      #set block(stroke: red) // debug
      #set par(first-line-indent: (amount: 2em, all: true))
      #show: par-indent.with(
        include-elem: (heading, math.equation, list, enum, terms), // Enable paragraph indentation control for heading, math.equation, list, enum and terms
        use-par-leading: true, // Enable paragraph spacing control for list, enum and terms
      )
    
    
      #set heading(numbering: "1.")
    
      = Heading
    
      *Indented* #lorem(10)
    
      _Equation Test_. #lorem(8)
      $
        a^2 + b^2 = c^2
      $
      *Unindented* #lorem(10)  // This paragraph remains unindented (no parbreak before equation)
    
      #lorem(2)
    
      $
        a^2 + b^2 = c^2
      $
    
      *Indented* #lorem(10)
    
      _Tight Lists Test_. #lorem(10)
      + #lorem(2)
      + #lorem(2)
      *Unindented and par-leading* #lorem(8)  // Unindented with paragraph-leading spacing
    
      = Heading
      *Unindented* #lorem(10)
    
      + #lorem(2)
      + #lorem(2)
    
      *Indented* #lorem(10)
    
      _Non-tight Lists Test_. #lorem(2)
    
      - #lorem(2)
    
      - #lorem(2)
      *Unindented* #lorem(2)  // Paragraph following lists without empty line
    ],
    )
    

    Example Two:

    Image
    Code:
    #import "@preview/parize:0.2.1": *
    #set page(margin: 1cm, height: auto, width: 25cm)
    #table(
      columns: (1fr, 1fr),
      [
        #import "@preview/zebraw:0.6.3": *
        #show: zebraw
        ```typst
        #import "@preview/parize:0.2.1": *
        #set par(first-line-indent: (amount: 2em, all: true))
        #show strong: set text(fill: red, size: 1.2em) // debug
        #set block(stroke: red) // debug
        #show: par-indent.with(
          include-elem: (), // Enable paragraph indentation control for all block-level elements
          use-par-leading: (
            text-block-leading: (math.equation,),
            block-text-leading: (list, enum, terms, math.equation),
          ),
        )
    
        _Equation Test_. #lorem(8) *par.leading* // no parbreak after
        $
          a^2 + b^2 = c^2
        $
        *Unindented + par.leading* #lorem(10) // Paragraph following equation without empty line
    
        _Equation Test_. #lorem(8) *par.spacing*
    
        $
          a^2 + b^2 = c^2
        $
    
        *Indented + par.spacing* #lorem(10)
        ```
      ],
      [
        #set par(first-line-indent: (amount: 2em, all: true))
        #show strong: set text(fill: red, size: 1.2em) // debug
        #set block(stroke: red) // debug
        #show: par-indent.with(
          use-par-leading: (
            text-block-leading: (math.equation,),
            block-text-leading: (list, enum, terms, math.equation),
          ),
        )
        _Equation Test_. #lorem(8) *par.leading* // no parbreak after
        $
          a^2 + b^2 = c^2
        $
        *Unindented + par.leading* #lorem(10) // Paragraph following equation without empty line
    
    
        _Equation Test_. #lorem(8) *par.spacing*
    
        $
          a^2 + b^2 = c^2
        $
    
        *Indented + par.spacing* #lorem(10)
      ],
    )

    See https://typst.app/universe/package/parize for more configurations.

    See ex-in-elems-test.typ for details on using par-indent with the rect element when Paragraph Indentation or Paragraph Spacing is enabled.

    See also inlinable-block.pdf (source) for details on using par-indent with custom block-level containers that can be treated as part of a paragraph.

  24. wade-cheng commented on May 16, 2026

    @wade-cheng

    I'm not really convinced that a figure really makes sense as part of a paragraph.

    You are correct, at least from a semantic point of view. In terms of structural PDF or HTML tagging, it makes no sense to have figures inside of paragraph tags.

    I'm not sure what definition of semantics are being used here, but I agree with the given opinions that figures and math can be part of a paragraph. It's like how you can have a sentence that starts out as regular text and ends as a block level equation---that's still seen as a sentence, in mathy works. In the same vein, a paragraph is "just," "semantically," a bunch of stuff with the same idea (is how I see it). So, figures and math can definitely be part of an idea, just as how they can be part of a sentence.

  25. SeSodesa commented on May 27, 2026

    @SeSodesa
    Contributor

    I'm not really convinced that a figure really makes sense as part of a paragraph.

    You are correct, at least from a semantic point of view. In terms of structural PDF or HTML tagging, it makes no sense to have figures inside of paragraph tags.

    I'm not sure what definition of semantics are being used here, but I agree with the given opinions that figures and math can be part of a paragraph. It's like how you can have a sentence that starts out as regular text and ends as a block level equation---that's still seen as a sentence, in mathy works. In the same vein, a paragraph is "just," "semantically," a bunch of stuff with the same idea (is how I see it). So, figures and math can definitely be part of an idea, just as how they can be part of a sentence.

    I agree on the math part, since an equation can be a part of a sentence and a paragraph is a collection of sentences in natural language. But I would not include figures into sentences. References to figures do make sense as a part of a sentence.

  26. AstraArcane commented on Aug 27, 2026

    @AstraArcane

    Having lists and display equation within a single paragraph is extremely common in academic papers and lecture notes. The fact that Typst doesn't natively support this is actually unusual‌, so let's stop debating whether this feature is necessary and focus on how to implement it.

    Currently, a display math block forces the subsequent text into a new paragraph. This happens because Typst treats math blocks and paragraphs differently; inserting a math block essentially splits what should be a single, continuous paragraph. Writing a separate package just to patch the indentation issue feels like a hack. As a typesetting tool, Typst should address this at the language level for better usability—just like LaTeX, where a blank line creates a new paragraph and no blank line keeps the text in the same one. The block itself shouldn't implicitly insert a #parbreak; paragraph breaking should be handled during compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestmodeltext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions