Skip to content

Wrap text around image with an irregular paragraph shape #5181

Open

Description

@mmach2000

Description

I want to wrap text around an image and make the text closely surround the image with an irregular paragraph shape, as shown in the picture below.

image

(copied from stackexchange)

In LaTeX this is achieved by \parshape, so I wonder if there is any plan to provide a similar API or other ways to typeset text with irregular shapes.

Use Case

Many books contain similar typesetting since many layout engines support this feature (InDesign, Word, etc.).

image
(copied from stackexchange)

Activity

  1. added
    feature request
    on Oct 11, 2024
  2. added
    layout
    text
    on Oct 14, 2024
  3. DorianBourgeoisat commented on Oct 23, 2024

    @DorianBourgeoisat

    Very important feature request for the future of typst, I think.
    I think #553 was closed prematurely, as the discussion within expressed numerous ideas about a more flexible floating placement system, and what was implemented for 0.12, while great, didn't fully fulfill the needs expressed in the issue, even those precisely scoped by its title, like 3 column layouts with 2 column span floating elements, a very common layout in magazines, newsletters and such.
    The more flexible text placement required by this issue would perhaps allow for an easier implementation of the ideas expressed in #553.
    The FOSS page layout design software Scribus already does this kind of text placement and its source code could be an inspiration for a typst implementation.

  4. laurmaedje commented on Oct 23, 2024

    @laurmaedje
    Member

    Wrapping text around shapes is definitely planned.

    Regarding #553: I think it was the right decision to close it because it was the canonical issue for two column figures and that's what most of the >150 people that upvoted it wanted.

    Yes, there were more requests in that issue, but it was not actionable as one work item. These other things are better served with separate issues like this one here.

  5. jdpieck commented on Feb 16, 2025

    @jdpieck

    Thought it was worth mentioning that this issue was briefly discussed on the Typst Sub-Reddit in which u/NeuralFantasy was trying to get an output found on this repository. (Image below)

    Text surrouding text

    This functionality was also discussed in this comment on the original issue #553 by @Andonome, but got lost in the thread. Below is the main image of interest.

    Text surrounding text

    I have also discussed similar functionality with insetting text on my own package. It was mentioned above.

  6. added a commit that references this issue on Sep 12, 2025
  7. marked Floating horizontally #6960 as a duplicate of this issue on Sep 25, 2025
  8. jrhaywardtdsc commented on Jan 23, 2026

    @jrhaywardtdsc

    Proposal: Native Text Flow Implementation

    Hi! I'd like to propose implementing native text-flow support in Typst to address this issue. We've done extensive research and are prepared to contribute the implementation. We believe our approach conforms to the ideas presented in @laurmaedje 's blog on layout models. https://laurmaedje.github.io/posts/layout-models/.

    The Performance Problem

    We're evaluating Typst to replace Apache FOP in our customer communications platform. While Typst dramatically outperforms FOP for standard layouts (<50ms vs 200ms), the current plugin-based text wrapping solutions work well but have a critical performance gap which will prevent us from using Typst:

    Benchmark: Newsletter with masthead column

    • Apache FOP: ~200ms
    • Typst (no wrap): <50ms (FASTER)
    • Meander plugin: ~500ms (SLOWER)
    • Wrap-it plugin: ~1200ms (SLOWER)

    Root Cause: Plugins operate in the script layer and repeatedly invoke Typst's layout engine for measurements. They can't access internal optimizations like comemo caching.

    Proposed Solution

    Implement native text flow using Typst's relayout-based architecture:

    1. Region Cutout System

    Extend regions to support rectangular exclusion zones that reduce available width at specific vertical positions:

    pub struct RegionCutout {
        y_start: Abs, y_end: Abs,  // Vertical range
        side: CutoutSide,           // Start/End (LTR-aware)
        width: Abs,                 // Width reduction
        clearance: Abs,             // Spacing
    }

    2. Variable-Width Line Breaking

    Modify Knuth-Plass to accept a width function instead of fixed width:

    fn linebreak(p: &Preparation, width_provider: &dyn WidthProvider) -> Vec<Line>

    This allows different line widths at different vertical positions while maintaining Knuth-Plass optimization.

    3. User-Facing API

    // General-purpose wrap
    #wrap(side: right)[
      #image("photo.jpg", width: 80pt)
    ]
    #lorem(100)
    
    // Newsletter masthead
    #masthead(width: 80pt, side: left)[
      *Newsletter* Issue 42
    ]
    = Article Title
    #lorem(200)
    

    4. Relayout Integration

    Uses existing Stop::Relayout mechanism - layout wrap content, create cutouts, trigger relayout for paragraphs to use cutouts. Converges in 2-3 iterations.

    Implementation Plan

    Phased approach with independent PRs:

    1. Region Cutout Foundation - Types and APIs, zero functional changes
    2. Variable-Width Line Breaking - Knuth-Plass enhancement, backward compatible
    3. Wrap Element - Element definition
    4. Flow Integration - End-to-end functionality
    5. Masthead Specialization - Newsletter-specific element
    6. Performance Optimization - Hit <200ms target
    7. Documentation - User guide and examples

    This Approach:

    • Aligns with architecture: Uses relayout model from "four architectures" blog post
    • Performance-first: Native implementation removes script overhead
    • Backward compatible: All existing tests continue passing
    • Incremental: Each phase independently reviewable
    • Extensible: Foundation for future irregular shape support

    Research Done:

    • Reviewed layout engine source (typst-layout, typst-library)
    • Analyzed Knuth-Plass implementation
    • Studied relayout mechanism and comemo integration
    • Created detailed specs (architecture, implementation guide, test strategy)
    • Benchmarked current solutions

    Security Considerations

    We're mindful of security implications including:

    • Relayout iteration limits to prevent infinite loops
    • Input validation for extreme parameter values
    • Memory bounds on cutout collections
    • Overflow-safe arithmetic in width calculations

    Implementation will follow Typst's existing security patterns and include comprehensive edge-case testing.

    Feedback

    Before implementing, would appreciate maintainer input on:

    1. Does the region cutout approach align with planned architecture?
    2. Are proposed wrap/masthead APIs appropriate?
    3. Any specific contribution requirements beyond CONTRIBUTING.md?

    We're committed to implementing this if the approach fits Typst's vision. The issue has 67 positive reactions showing strong community demand.

    About us: Team behind INTOUCH, a CCM platform migrating from Apache FOP to Typst. Happy to contribute back!


    Full technical specification available if helpful. Happy to discuss details, provide benchmarks, or clarify anything!

  9. omentic commented on Jan 23, 2026

    @omentic
    Contributor

    I think this comment was written by generative AI.

  10. laurmaedje commented on Jan 23, 2026

    @laurmaedje
    Member

    @jrhaywardtdsc This topic is unfortunately not suitable for contribution by a new contributor. It's a very complex topic and could only be tackled by a team member or contributor that has built significant trust. The fact that the description is AI-written also doesn't inspire confidence in the proposal.

    If your team would like to contribute, I would suggest working on something smaller first. If you're using Typst commercially, we also always appreciate monetary contributions.

  11. oxidebits commented on Mar 10, 2026

    @oxidebits
  12. torsteinnh commented on Mar 10, 2026

    @torsteinnh

    What's the status of this issue?

    Jumped from here : https://www.reddit.com/r/typst/s/41s99MIh9u

    I don't know about the implementation for this issue, but the meander package can work as a stopgap while waiting for a permanent solution: https://typst.app/universe/package/meander/
    I hope we get something in the compiler eventually to avoid the need for hundreds of packages like in LaTeX, but it does the job quite well for now.

  13. zral0kh commented on Apr 3, 2026

    @zral0kh

    I got another problem that might be worth considering for some eventual implementation.

    For touying's fit-to-height, we now implemented some much too basic reflow to allow text that will get scaled down to still occupy the full width. The idea is you call fit-to-height(1fr)[#lorem(50)] and have some big stuff above on the slide, and the content given will shrink to fit the remaining height. For blocks its easy, but text is a whole different story, and i really don't want to go ahead and measure individual words to get near-perfect scaling factors while also allowing reflow and going through tens or hundreds of opt steps.

    I am not familiar with what any solution to such a problem would look like if done right, but perhaps it's worth considering such use cases.

  14. wade-cheng commented on Jun 22, 2026

    @wade-cheng

    For what it's worth, meander and droplet are wonderful, but have nonzero issues from being usermode code, such that I just decide to avoid wrapping in Typst at all. (I feel a bit awkward giving this negative criticism, but it hasn't been brought up in the discussion chain yet---just wanted to provide the point!) Eagerly awaiting this feature ^^

  15. roopeshor commented on Oct 7, 2026

    @roopeshor

    Any plans to implement this? Would be highly useful if implemented in engine itself

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

    feature requestlayouttext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions