Skip to content

Support variable fonts #185

Closed
Closed

Description

@LdBeth

for example, https://fonts.google.com/specimen/Bitter, if have the variable font version Bitter-VariableFont_wght.ttf installed, selecting font weight by #set text(font: "Bitter", weight: "medium") would still render the ExtraLight variant and setting other weight options would not change the font weight appeared in the PDF output anyway.

Activity

  1. owiecc commented on Mar 24, 2023

    @owiecc
    SponsorContributor

    Same here. With these fonts:

    QuadraatPro.otf
    QuadraatPro-Ita.otf
    QuadraatPro-Demibold.otf
    QuadraatPro-DemiboldItalic.otf
    QuadraatPro-Bold.otf
    QuadraatPro-BoldIta.otf
    

    #set text(font: "Quadraat Pro") selects Quadraat Pro Italic. I did not manage to get the Regular style. Names in the system are: Regular, Italic, Demibold, Demibold Italic, Bold, Bold Italic.

  2. changed the title [-]Having trouble select weight for variable font[/-] [+]Support variable fonts[/+] on Apr 4, 2023
  3. added
    pdfRelated to PDF export or PDF embedding.
    textRelated to the text category, which is all about text handling, shaping, etc.
    on Apr 4, 2023
  4. reknih commented on Apr 4, 2023

    @reknih
    Member

    Typst does not support variable fonts at the moment. They could be a good addition.

    @owiecc This is an unrelated bug on normal font discovery. I will file a separate issue.

  5. mattfbacon commented on Aug 30, 2023

    @mattfbacon
    Contributor

    What is missing here? Is any current work addressing this?

  6. laurmaedje commented on Aug 30, 2023

    @laurmaedje
    Member

    There is no current work. Supporting variable fonts is a major effort. It needs large changes to the font handling and to the PDF export.

  7. davelab6 commented on Jul 29, 2024

    @davelab6

    @laurmaedje I work on the Google Fonts team and I'm a big proponent for variable fonts. If you want any free consulting advice on this topic, please reach out to me or fonts@google.com :) I wrote a little about this for the Flutter team here

  8. laurmaedje commented on Aug 4, 2024

    @laurmaedje
    Member

    @davelab6 Thanks for the offer! We'll get back to it when we start work on variable fonts.

  9. davelab6 commented on Aug 6, 2024

    @davelab6
  10. Zxilly commented on Oct 22, 2024

    @Zxilly

    Currently, could we consider throwing a warning when we need to parse variable fonts?

  11. sonovice commented on Nov 22, 2024

    @sonovice

    Variable font support was recently added to the allsorts rust lib: https://github.com/yeslogic/allsorts/releases/tag/v0.15.0

    Since it also includes a font subsetter, it might come in handy for typst in that matter?

    Example: https://github.com/yeslogic/allsorts-tools/blob/master/src/subset.rs

  12. LaurenzV commented on Nov 22, 2024

    @LaurenzV
    Collaborator

    We use our own subsetter, which should be at least on par with theirs (apart from the fact that we won't support CFF2 yet): https://github.com/typst/subsetter

    Using theirs would require us to pull in all of allsorts in our dependency tree, which wouldn't be great considering that we are using the rustybuzz/ttf-parser font stack (and probably will switch to fontations in the future).

  13. Andrew15-5 commented on Feb 25, 2025

    @Andrew15-5
    Contributor

    Just faced this issue with NixOS and the default VF.otf.ttc files for Noto CJK fonts, which produces tofu even though it says that the fonts were embedded (#5277). Had to manually download the static OTF fonts. #5304 would've made the debugging a breeze.

    #5954

  14. Andrew15-5 commented on Mar 30, 2025

    @Andrew15-5
    Contributor

    Today discovered that fira-code package also uses variable font, but I've been using it for months and didn't have any problem with it. So Typst does support it, but...a subset of it?

    FiraCode-VF.ttf.zip

  15. japanoise commented on May 20, 2025

    @japanoise

    Here's a stop-gap solution I have while I wait for this feature to be implemented - fonttools has a built-in script called mutator, and you can use it to make static versions of fonts. For example:

    fonttools varLib.mutator ./garamontio.ttf wght=500 -o garamontio-medium.ttf
    

    I have a script that will do that over a range of weights + italic/not italic: https://github.com/japanoise/font-mungers/blob/main/static_cut.sh

  16. YDX-2147483647 commented on May 20, 2025

    @YDX-2147483647
    Contributor

    FYI, I wrote a guide with explanation in 2023. It uses python, which might be easier for Windows users. See #2508.

  17. ethanc8 commented on Sep 2, 2025

    @ethanc8

    Why does it not work to manually specify wght in text(features: ("wght": 700))?

  18. magistau commented on Sep 3, 2025

    @magistau
    Contributor

    Here's what I use to build static fonts with Nix:

    font-to-static = pkgs.writeShellApplication {
      name = "font-to-static";
      runtimeInputs = [ pkgs.python3Packages.fonttools ];
      text = ''
        src="$1"
        name="$(basename "$src" '.ttf')"
        for wght in 100 200 300 400 500 600 700 800 900; do
          fonttools varLib.mutator -o "$name-$wght.ttf" "$src" wght="$wght"
        done
      '';
    };
    exo2-static = (pkgs.google-fonts.override { fonts = [ "Exo 2" ]; }).overrideAttrs (
      finalAttrs: prevAttrs: {
        nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ self'.packages.font-to-static ];
        preFixup = ''
          find "$out" -name '*.ttf' -execdir font-to-static '{}' ';'
        '';
      }
    );
  19. madig commented on Oct 26, 2025

    @madig

    Here's what I use to build static fonts with Nix:

    You may want to use fonttools varLib.instancer instead, varLib.mutator is deprecated.

  20. pwelty commented on Jun 11, 2026

    @pwelty

    Tested v0.15.0-rc.1 against a real project: a 323-page 6x9 trade paperback set in Libre Baskerville, five weights via text(weight:), bold skim-layer spans, italic chapter openers, and a custom top/bottom-edge line grid.

    I'm picky about weights. Picky enough that on 0.14.2 we baked our own static instances out of the variable font with fonttools varLib.instancer, because only the default instance was readable. On rc.1 the system LibreBaskerville[wght].ttf just works: 400/500/600/700 and the italic all resolve from text(weight:) with no configuration.

    The part worth reporting: the rendered geometry from runtime variable-font instancing is identical to our hand-baked static instances. We diffed full-book pdftotext bounding boxes and got zero differences, and the glyph-width fingerprints match exactly. We can delete the workaround entirely at stable.

    Whole-book regression vs 0.14.2: body layout is page-for-page identical, all 77 chapter endings unchanged. The only difference we found was TOC dot-leader packing, consistent with the documented repeat weak/fractional spacing change.

    We love this project. Deterministic plain-text layout at this typographic quality is something some of us have wanted for a very long time.

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 requestNew feature or requestpdfRelated to PDF export or PDF embedding.textRelated to the text category, which is all about text handling, shaping, etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions