Skip to content

RFC: Vertical Writing Mode #5908

Open
Open

Description

@OverflowCat

Introduction

Vertical layout remains vital across various cultures and contexts,
particularly in traditional East Asian typesetting.
This RFC proposes the implementation of vertical writing mode support in Typst.

Features to implement

Vertical writing

Image

And figure placement, accordingly:

Vertical text in graph

Image

Latin & formulae in vertical text

All block formulas are rotated 90° to the right of the entire formula block. Alphanumeric characters and mathematical symbols are all folded sideways.

mn

mn

Short inline math that fits into 1x line-height(?) can be upright (tate-chu-yoko).

ja

More Tate-Chu-Yoko (縦中横)

Numbers:

Full-width letters:

Image

https://tategaki.github.io/

https://marumarumarumori.jp/

Compression or not:

Image CC BY-NC

Image

Punctuations

Punctuation marks used in Taiwan and Hong Kong are usually positioned in the vertical and horizontal center of the square space left for them; while in vertical writing mode and horizontal writing mode, some of the punctuation marks are positioned in different directions so as to mark the corresponding characters more accurately. In Mainland China, the punctuation marks are usually positioned following the characters they are supposed to mark; while some punctuation marks might be positioned in different directions due to the vertical or horizontal writing mode. Also, different writing modes might require different punctuation marks to fulfill the same function, e.g. horizontal writing mode requires curved quotation marks while vertical writing mode requires corner brackets.

Proposed Solution

The core of this proposal is to extend Typst's text model and layout engine to accommodate vertical writing modes, providing a clear API for controlling and customizing text direction.

API changes

writing-mode text attr

Introduce writing-mode as an attribute for the text element and within style contexts that affect text layout. writing-mode should be a general typesetting instruction, independent of specific script systems. Users should be able to explicitly set the text direction.

Values for writing-mode include:

  • "horizontal-tb": Horizontal, top-to-bottom line progression (default, current horizontal mode).
  • "vertical-rl": Vertical, right-to-left column progression (traditional East Asian vertical mode).
  • "vertical-lr": Vertical, left-to-right column progression (e.g., Mongolian script).

inline and block axis

Writing mode is the direction of lines of text at the block level. rtl is the direction of text at the inline level. Properties that follows text direction are called logical ones. They will be mapped to physical ones based on writing-mode & rtl.

New functions, params and values

Existing layout functions like h(), v(), align(), move(), hline, etc. need adjustments for vertical writing modes. The proposal advocates for logical APIs that adapt their behavior based on the current writing-mode.

  • h() and v(): new logical spacing functions (inline-space(), block-space()) that maps to h()/v(). Also, hline() and vline().
  • move(di, db): Modify move(dx, dy) to move(di, db), where di is inline direction movement and db is block direction movement. move's behavior would then adapt to writing-mode.
  • height, width: block-size and inline-size.
  • alignment type: we have start and end for inline. block-start & block-end are needed.
  • direction type: maybe we need ste, ets?

Technical issues

Text shaping

Shaping engines are typically designed for horizontal text. In vertical writing mode, many glyphs require a 90-degree clockwise rotation for correct display. Traditional Mongolian (ᠮᠣᠩᠭᠣᠯ), for instance, also involves a 90-degree clockwise rotation. However, because its block axis progresses from left to right, the order of glyphs within each line needs to be reversed as well.

CJK characters and emojis, on the other hand, generally do not require rotation. To correctly display punctuation marks, it may be necessary to enable the vert OpenType feature (although Unicode provides separate code points for rotated punctuation). Currently, there are no known examples of rtl(?) vertical text.

HTML export

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values

Currently, adding a writing-mode property and all things are done.

Style export should use logical properties and values. However, there are still some values that do not have a logical version, so maybe we need to resolve the logical properties into physical ones.

Backward Compatibility

This proposal prioritizes backward compatibility. writing-mode as a new text attribute defaults to "horizontal-tb", ensuring existing Typst documents render unchanged. API modifications will be carefully designed. Retaining physical attributes alongside new logical attributes helps guarantee backward compatibility during the transition.

Resource Prioritization

Image

Given potential resource constraints, we can make the foundational logical API available first (which benefits rtl text as well — For example, we don't need to write dir.sign() or pass the rtl parameter. Instead, we can directly use the logical layout keyword). Or we will find it too late to make breaking changes.

Activity

  1. added
    feature request
    on Feb 20, 2025
  2. added
    text
    layout
    on Feb 25, 2025
  3. SaadiSave commented on May 26, 2025

    @SaadiSave

    @OverflowCat what kind of breaking changes would this require if implemented in the not-so-near future? Is it entirely impossible to implement this as a package? I do agree with your premise though, that vertical writing modes should eventually be available in the compiler. Have you already started designing the implementation, or is it on hold?

  4. vanleefxp commented on May 27, 2025

    @vanleefxp

    I am also looking forward to this feature. In a recent use case of Typst I would like to layout a literary text in Chinese with vertical writing mode. Sadly Typst does not support this natively so I investigated if other tools can do it. Options I've found include UpTeX, Word / LibreOffice Writer, InDesign and HTML + CSS. In the aforementioned methods, I think that HTML + CSS works best, as it is free and programmatic enough to cope with complicated layout. Most importantly, it is an open-source solution like Typst. However, there are still limitations. For example, page headers and footers, layout optimization over pages and creating footnotes corresponding to pages. These features are mostly page related, which Typst can handle well.

    So, has it the possibility to implement vertical writing mode by a Typst package? For example, use a function to find all the characters that need to be rotated and rotate them by 90 degrees. Currently I haven't seen such packages in Typst Universe.

  5. Andrew15-5 commented on May 27, 2025

    @Andrew15-5
    Contributor

    It's possible as long as the text stays on the same page. Multi-page layout is probably the core issue. Maybe if you know exactly how everything will flow in different situations, then you can try and hack your way through it. I would assume this is very complex and might be impossible, and some research is needed which methods are available and their key points. But Typst might be just powerful enough to pull this off, because a lot of packages use a lot of trickery hacking to be able to build incredible things.

  6. OverflowCat commented on May 27, 2025

    @OverflowCat
    ContributorAuthor
  7. SaadiSave commented on May 28, 2025

    @SaadiSave

    @OverflowCat so how must we go about convincing the project that vertical text layout is something that should be taken care of as quickly as possible?

  8. Andrew15-5 commented on May 28, 2025

    @Andrew15-5
    Contributor

    @SaadiSave, there are a lot of other things that have higher priority at the moment. There were no instances where all of a sudden a priority of one thing is completely changed from backlog to urgent, IIRC. The only thing that sounds similar was an addition of decimal data type. And even then, it's way easier to add than a proper vertical/ttb layout. Both, in terms of code and API complexity.

  9. SaadiSave commented on May 28, 2025

    @SaadiSave

    @Andrew15-5

    Is there any way to start preliminary design work in the meantime? A proof of concept perhaps? I can help and know Rust, but next to nothing about typesetting (I just use typst and wanted to typeset Japanese vertically the other day), so I cannot do it on my own.

  10. Enivex commented on May 28, 2025

    @Enivex
    Collaborator

    I would imagine adding vertical text layout requires extensive changes to typst. Not exactly an ideal candidate for a first PR.

    It's also the kind of thing I wouldn't start working on without team approval. Otherwise you run the risk of wasting a lot time and energy.

  11. Andrew15-5 commented on May 28, 2025

    @Andrew15-5
    Contributor

    Is there any way to start preliminary design work in the meantime? A proof of concept perhaps? I can help and know Rust, but next to nothing about typesetting (I just use typst and wanted to typeset Japanese vertically the other day), so I cannot do it on my own.

    I'm more or less the same. I just don't depend on it in any way other than it would be nice to have it and maybe try it out. Also I'm pretty busy most of the time.

    If you want a PoC and can't do it on your own, then you can either find someone that has the things that you need or wait for someone to take the initiative themselves.

    If you want to talk about API design, then feel free. If someone is interested, they could share their thoughts on it.

    Indeed, the PoC or the API design might not be added in the codebase, but as a standalone thing you can do whatever you want.

    But spamming a lot of messages is not great if you are the only one posting them. You can edit your messages if that's a problem. (If it becomes a monologue.)

  12. neruthes commented on Apr 20, 2026

    @neruthes

    I did some POC in userland with basic overhang/underhang. Should I make it a package?

    Image
  13. forfudan commented on Apr 20, 2026

    @forfudan

    I did some POC in userland with basic overhang/underhang. Should I make it a package?

    Great work! Looks fantastic!

  14. Andrew15-5 commented on Apr 20, 2026

    @Andrew15-5
    Contributor

    The https://x.com/kanata201612/status/2027328191757791714 post was shared a few times in the くみはんクラブ server.

    Image

    Since then there were no updates (on the server). It might not be released as a package, but someone probably can make one from the book that shows how to typeset this.

  15. neruthes commented on Apr 20, 2026

    @neruthes

    Package done. PR welcomed. Some implementation choices feel hacky; need help on edge case handling, etc.

  16. kanata2003 commented on Apr 26, 2026

    @kanata2003

    Hi,
    I’m the developer of the vertical writing feature that Mr. Andrew introduced.
    I still have a few areas I’d like to improve, and once I’ve sorted those out, I’m thinking of registering it on Typst Universe.

  17. Iktahana commented on Nov 1, 2026

    @Iktahana

    Hi! I’m the developer of Illusions, a writing application focused on Japanese literary typesetting.

    Our document engine is written in Rust, and we’re currently exploring Typst as a possible replacement for Chromium-based PDF generation, particularly to achieve consistent output across platforms.

    Native vertical writing support is one of our main requirements.

    I’d be happy to contribute to this feature, but before getting started, I’d like to ask:

    • Is there an agreed roadmap or architectural direction for implementing native vertical writing support?
    • Would the maintainers be open to incremental PRs for this feature?
    • Are there any specific parts of the implementation where contributions would be most helpful?

    We also have real-world test cases involving Japanese vertical text, ruby, kinsoku shori, tate-chu-yoko, and warichu that we’d be happy to share.

    Thanks for all your work on Typst!

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