Skip to content

A way to avoid font-not-found warning if alternative font is found #6010

Open

Description

@jounathaen

Description

I have written a template that uses the CMU fonts. However, on some systems, there is only the alternative Font "New Computer Modern" available and vice versa. Both Fonts are almost the same (at least for Latin characters), so either is a perfectly valid choice for all use-cases I have. Therefore, in my template I have the following code:

  set text(
    font: (
      "CMU Sans Serif",
      "New Computer Modern Sans",
    ),
    size: 12pt,
  )

Unfortunately, since #2818 this produces the following warning on systems where only one of these font families is installed:

warning: unknown font family: new computer modern sans
    ┌─ template/foobar.typ:105:10
    │  
105 │       font: (
    │ ╭───────────^
106 │ │       "CMU Sans Serif",
107 │ │       "New Computer Modern Sans",
108 │ │     ),
    │ ╰─────^

Maybe I'm following an antipattern here, but I think it'd be great if the warning is only thrown if no valid font (for actually used character sets) is found.

Use Case

Described above.

Activity

  1. added
    feature request
    on Mar 5, 2025
  2. changed the title [-]Disable _font not found_ warning if alternative font is found.[/-] [+]Disable *font not found* warning if alternative font is found.[/+] on Mar 5, 2025
  3. changed the title [-]Disable *font not found* warning if alternative font is found.[/-] [+]Disable font-not-found warning if alternative font is found.[/+] on Mar 5, 2025
  4. added
    text
    change request
    and removed
    feature request
    on Mar 5, 2025
  5. janosh commented on Mar 13, 2025

    @janosh
    Sponsor

    also, would be great if the warning could specify which fallback font is being used instead such that users can change to that one to silence the warning

  6. YDX-2147483647 commented on Apr 16, 2025

    @YDX-2147483647
    Contributor

    Previous discussions on the Forum

    Is it possible to suppress the warning about Noto CJK / Source Han duality? - Questions - Typst Forum

    I have a rough feeling that there are two kinds of font fallback.

    • Fallback for environments: the same document for different browsers, OS’s , machines, etc.
      You want to select one available font in a list of similar fonts.
    • Fallback for graphemes: different languages (or scripts?) in the same document.
      Your document contains Latin, Han, and Emoji characters, and you want to combine several completely different fonts to cover them all.

    The font fallback mechanism of CSS is mainly/originally designed for the first kind, while that of typst mainly designed for the second kind?

    A (not quite usable) workaround: typst compile … --input HOSTNAME=$(hostname).

    A possible interface?

    #set text(
      font: (
        (name: "CMU Sans Serif", if-unknown: "ok"),
        "New Computer Modern Sans",
        (name: "…", if-unknown: "warning"),
      ),
    )
  7. YDX-2147483647 commented on Nov 12, 2025

    @YDX-2147483647
    Contributor

    Hi @gasche! I see your discussion in #3854 (comment) and your PR #7272.
    I'm replying here, because I think it's a better place for general discussions.

    When template authors…
    …we should ensure that the choice of behavior covers the common, easy/natural case…

    I agree that the current font warning is very unfriendly for template authors who need to fallback for environment, but I want to argue that falling back for graphemes is equally common.
    (The two kinds of font fallback was explained above.)

    • Han (CJ or CJK — I'm not sure)

      It is extremely common to use different fonts for Han and Latin characters.
      There are thousands of Han characters and font designers spend their main effort on them. As a result, the Latin parts of most Han fonts are provided only for compatibility and poorly designed. Therefore, these Han fonts have to be combined with specialized Latin fonts. The situation is improving these years, but traditional fonts (they're still widely used) remain the same.

      Image

      SimSun is a well-known Han font in China. The first page of the GitHub search result for lang:typst SimSun is as the following. You can see that falling back for graphemes is indeed common in this scenario.

      • 11 repos fallback only for graphemes
      • 4 repos fallback for both environments and graphemes
      • 4 repos fallback only for environments
      • 1 repo does not use a fallback list
    • Math

      It looks like that show math.equation: set text(font: (A, B, C, …)) always means to fallback for graphemes? For example, using additional fonts for non-Latin texts in math, or using a special math font to cover ∅.
      This is a new feature, though.

    Another thing to consider: There are far more document authors than template authors.
    Those who need to fallback for environments are mainly template authors, while those who need to fallback for graphemes include both.

  8. gasche commented on Nov 12, 2025

    @gasche

    Thanks for the extra information. If we look at one example of usage in the github search:

        (
          (name: "Times New Roman", covers: "latin-in-cjk"),
          "SimSun",
          "Songti SC",
          "STSongti",
        ),
    

    The behavior of my PR on this font list is to ignore "Times New Roman" because it has a cover restriction, and then emit a warning if none of "SimSun", "Songti SC" or "STSongti" are available. My understanding is that this is a reasonable behavior for the intended use-case.

  9. YDX-2147483647 commented on Nov 12, 2025

    @YDX-2147483647
    Contributor

    Sorry I didn't read the code carefully and misunderstood "latin-in-cjk" as unrestricted, because it's a regex that matches anything but 11 special characters…

    this is a reasonable behavior for the intended use-case.

    Indeed.

    There are two kinds of configurations. One is what you mentioned, and the other one can be changed as follows after your PR.

        (
    -     "Times New Roman"
    +     (name: "Times New Roman", covers: regex(".")),
          "SimSun",
          "Songti SC",
          "STSongti",
        ),

    However, problems on emoji and math fonts are still not covered.

  10. gasche commented on Nov 12, 2025

    @gasche

    However, problems on emoji and math fonts are still not covered.

    Can you explain a concrete example of emoji or math font that you have in mind? (What does it become as a FontList passed to check_font_list?) My goal with my PR #7272 is not necessarily to fix all issues related to font warnings, I would be happy with a first step that solves only some of the issues, but we should check that there is no regression on common use-cases. So I would be happy for "no worse than before" behavior in those more advanced cases.

  11. YDX-2147483647 commented on Nov 12, 2025

    @YDX-2147483647
    Contributor

    Can you explain a concrete example of emoji or math font that you have in mind? (What does it become as a FontList passed to check_font_list?)

    It looks like that FontList is isomorphic to set text(font: …). I'll use the latter syntax below.

    • Emoji

       #set text(font: (
         "Noto Sans",
         (name: "Noto Color Emoji", covers: regex("[🔗⛓‍💥]")),
         "Twitter Color Emoji",
         "Noto Color Emoji",
       ))

      This is extracted from Setting fonts repeatedly with different covers is not effective #6566.

      I am using Twitter Color Emoji font, but the official version didn't update after Unicode 14. Therefore, I use Noto Color Emoji as a fallback.

      However, I want to use both 🔗 link (Unicode 6.0) and ⛓‍💥 broken chain (⛓+zwj+💥, Unicode 15.1). These two emojis are used in pairs, but only the former is included in Twemoji. As a result, I want both of them fallback to Noto Color Emoji.

      I think there should be no warning if either Twitter or Noto Color Emoji is installed, but there should be a warning if neither is installed.

    • Math

       #show math.equation: set text(font: (
         (name: "Computer Modern Symbol", covers: regex("[𝒜ℬ𝒞𝒟ℰℱ𝒢ℋℐ𝒥𝒦ℒℳ𝒩-𝒬ℛ𝒮-𝒵]")),
         "New Computer Modern Math",
       ))

      This is for the LaTeX look.

      Maybe there should be no warning when Computer Modern Symbol is not installed, because it's just a stylistic choice.

    Hmm, I feel that the warning control should be more explicit.

  12. gasche commented on Nov 12, 2025

    @gasche

    With the behavior in #7272:

    • on the emoji example, "Noto Color Emoji" will be ignored as it is restricted to a cover, and there will be a warning if all of "Noto Sans", "Twitter Color Emoji" or "Noto Color Emoji" are missing.
    • on the Math example, "Computer Modern Symbol" will be ignored and you will only get a warning if "New Computer Modern Math" is missing.

    In contrast, with the current behavior you will get a warning for each one of the font that is missing (with or without cover), independently of whether the others are available.

    My understanding is that #7272 indeed improves the behavior in both of these examples, and in fact it also seems to "do the right thing", to have the reasonable behavior one would expect given the available information.

  13. laurmaedje commented on Nov 17, 2025

    @laurmaedje
    Member

    My understanding is that #7272 indeed improves the behavior in both of these examples, and in fact it also seems to "do the right thing", to have the reasonable behavior one would expect given the available information.

    I think the emoji example as presented by @YDX-2147483647 would regress with #7272 as, if I understand correctly, the goal is to use all of Noto Sans (for text), Twitter Color Emoji (for most emoji), and Noto Color Emoji (for chains and Unicode 14 stuff) in the document.

    With #7272, e.g. the mere presence of Noto Sans would silence all warnings even if no emoji font is present at all.

  14. gasche commented on Nov 19, 2025

    @gasche

    @laurmaedje I understand that I was missing something (due to my own lack of knowlege about Emoji fonts). I assumed that given the font snippet given by @YDX-2147483647

     #set text(font: (
       "Noto Sans",
       (name: "Noto Color Emoji", covers: regex("[🔗⛓‍💥]")),
       "Twitter Color Emoji",
       "Noto Color Emoji",
     ))

    then it would be the case that "Noto Sans" will be used unconditionally if it is available, for all characters (because it is first in priority list). But in fact, even though there is no cover estriction for that choice, it may be the case that the font does not support all characters, and the Typst engine will go down in the priority list for characters that are missing for that font. (I suppose that "Noto Sans" does not include any emoji characters, and this is why @YDX-2147483647 and you are writing that this font choice will use of the "Emoji" fonts for emoji characters, even if they are lower in the priority order.)

    I had missed this aspect and understand why you find the #7272 behavior suboptimal in this case. In a sense, #7272 over-approximates by assuming that each font that is listed without a cover restriction can in fact display all characters. I am not sure how you would propose to lift this restriction; should I try to access the set of characters supported by each font in check_font_list, and warn as soon as one character is supported by none of the proposed fonts?

  15. laurmaedje commented on Nov 20, 2025

    @laurmaedje
    Member

    @gasche Yeah, exactly that's the struggle. It's not specific to emoji fonts either. Typst will always traverse the font list when it fails to render some text with the first font.

    Since at the point where the set rule is defined we don't know which characters will be in use, we can't really make a definitive decision there. I fear that we'll need more information from the user, e.g. some sort of dictionary that marks a font as required or optional (similar to the if-unknown: "ok" proposed above; could also be required: true or optional: true or something like that). I'm not sure what the exact best design there is, but something in this direction is the best I see right now.

  16. gasche commented on Nov 20, 2025

    @gasche

    Since at the point where the set rule is defined we don't know which characters will be in use, we can't really make a definitive decision there.

    I thought about warning dynamically, if the list of available font bottoms out during character shaping, but I worry that the change would be significantly more invasive and performance-sensitive.
    On the other hand, maybe it would be acceptable to approximate this by saying that we warn if for some characters none of the proposed fonts are available. (Then we can do this "statically", if we know how to query a font for the set of renderable characters, and manipulate those efficiently.) This may result in spurious warnings for some exotic characters that no one supports nor uses in practice, but I wonder if this default strategy would be good enough. (The warning message could possibly be explicit about which characters are un-renderable, and then it would be possible to add an argument to the font list to exclude certain characters from consideration.)

    (I am of course happy to support a richer API where authors provide more precise information on their wishes, but this does not solve the ergonomic problem with font selections as they are provided today, where users see many more warnings than intended.)

  17. laurmaedje commented on Nov 20, 2025

    @laurmaedje
    Member

    This PR is somewhat related: #6989. It warns during runtime as well. Some form of this will probably ship, but it indeed needs more care and is more performance sensitive.

    On the other hand, maybe it would be acceptable to approximate this by saying that we warn if for some characters none of the proposed fonts are available.

    What exactly do you mean by "for some characters"? For some characters in all of Unicode? Because there are so many characters in Unicode that your font list will pretty much never cover all of it. Maybe I'm misunderstanding.

  18. changed the title [-]Disable font-not-found warning if alternative font is found.[/-] [+]A way to avoid font-not-found warning if alternative font is found[/+] on Jan 7, 2026
  19. added
    feature request
    diagnostics
    and removed
    change request
    on Jan 7, 2026
  20. foxyseta commented on May 12, 2026

    @foxyseta

    Since #7272 has been closed, does it mean that more discussion is needed within this issue before opening a new PR?

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

    diagnosticsfeature requesttext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions