Skip to content

More configurable text overhang #261

Open

Description

@bdarcus

I'm new to typst, so forgive me if I'm missing something.

Could you add more advanced, microtype/InDesign-like, things like protrusion?

Or if you already do support it (I see mention HZ algorithm), maybe take a look at the below.

Using Minion Pro, typst:

typst-prot

LuaLaTeX with microtype:

tex-protrusion

Activity

  1. hirschenberger commented on Mar 25, 2023

    @hirschenberger

    I'd like to implement the protrusion functionality. I did a bit of research and it seems even in texmacs and pdftex it's implemented with a heuristic lookup table Symbol -> Shift. Regardless of the font used.

    A good source is the dissertation of Hàn Thế Thành, who wrote pdftex.

    I wonder why it's done in such a simple and uncomplete way. Wouldn't it be possible to directly calculate glyph metrics like e.g. blackness, center of mass to align the border more precisely?

  2. bdarcus commented on Mar 25, 2023

    @bdarcus
    Author

    I wonder why it's done in such a simple and uncomplete way.

    I don't know. Maybe it wasn't convenient or possible to do that when it was first implemented?

    Have you checked the luatex repo? Perhaps they asked the same question when working on it?

    Or maybe just try it?

  3. Enivex commented on Mar 25, 2023

    @Enivex
    Collaborator

    I'd like to implement the protrusion functionality. I did a bit of research and it seems even in texmacs and pdftex it's implemented with a heuristic lookup table Symbol -> Shift. Regardless of the font used.

    A good source is the dissertation of Hàn Thế Thành, who wrote pdftex.

    I wonder why it's done in such a simple and uncomplete way. Wouldn't it be possible to directly calculate glyph metrics like e.g. blackness, center of mass to align the border more precisely?

    I would look to the microtype package, which is the one that implements the advanced features

    https://ctan.org/pkg/microtype?lang=en

    There's a 270 page document on implementation details.

  4. hirschenberger commented on Mar 25, 2023

    @hirschenberger

    I would look to the microtype package, which is the one that implements the advanced features

    https://ctan.org/pkg/microtype?lang=en

    There's a 270 page document on implementation details.

    Yes, I know that, but on page 148 the author mentions that his protrusion is based on the tables that Hàn Thế Thành created in the dissertiation I mentioned above.

  5. bdarcus commented on Mar 25, 2023

    @bdarcus
    Author

    In any case, I don't claim to understand the nuances here, but I agree with you @hirschenberger that it'd be ideal to calculate the metrics rather than assume some fixed table.

  6. Enivex commented on Mar 29, 2023

    @Enivex
    Collaborator

    The typesetting in the original image looks quite good. For me it looks much worse:

    test

    The problem in the algorithm used here is that when some line is too long or too short (which is not really that problematic),
    the line is just broken and everything is kept like it is. That's a very fast algorithm.
    But what is better is this one (top image).
    Instead of just breaking the line, add to all horizontal spacing within the line the same amount of additional horizontal space,
    so that the space at the end is now zero.
    With this new algorithm we will achieve the top picture in the linked wikipedia image instead of the one I linked.
    I think, this is the most important first step.

    That doesn't look right. I think justification is disabled, either by accident or some bug.

  7. laurmaedje commented on Apr 1, 2023

    @laurmaedje
    Member

    Typst already does this, but it doesn't let all characters overhang by the same amount. You can see the ratios here. The behaviour can be disabled with this property. Could be made more configurable so that you can also have full overhang.

  8. added
    layout
    text
    on Apr 1, 2023
  9. bdarcus commented on Apr 1, 2023

    @bdarcus
    Author

    Typst already does this, but it doesn't let all characters overhang by the same amount.

    Oh good, so the functionality is there; just a question of optimizing, and/or making it configurable, and/or automating optimization based on calculating the glyph metrics?

    In the two examples I posted, the tex/microtype one clearly looks better, and that's without me doing any configuration.

  10. hirschenberger commented on Apr 1, 2023

    @hirschenberger

    I'm currently working on a PR with a more complete protrusion table based on the values texmacs uses.

  11. bdarcus commented on Jun 22, 2023

    @bdarcus
    Author

    Am I wrong, or did this get fixed at some point, so that you can close this?

  12. Enivex commented on Jun 22, 2023

    @Enivex
    Collaborator

    Am I wrong, or did this get fixed at some point, so that you can close this?

    It was never broken. I think it's still open because it can still be improved.

  13. changed the title [-]Line layout, protrusion[/-] [+]More configurable text overhang[/+] on Nov 5, 2023
  14. added
    feature request
    on Nov 5, 2023
  15. hurzl commented on May 23, 2024

    @hurzl

    With LaTeX's microtype package

    1. you can define protrusion amounts individually per symbol, and
    2. protrusion is also applied to the left side.
  16. adamkrellenstein commented on Jun 16, 2026

    @adamkrellenstein

    In case it's useful: as of 0.15.0 text.overhang is still a bool, and the overhang amounts are a hardcoded table in typst-layout/src/inline/line.rs covering only dashes, hyphens, .,:; and two Arabic marks — letters get 0, so caps like W/A/V/T at a flush-left line start don't protrude. Looks like #7782 would make this configurable per-glyph (incl. by glyph name) on both margins.

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