Skip to content

Add warning when using fallback font - #3352

Closed
Enter-tainer wants to merge 4 commits into
typst:mainfrom
Enter-tainer:mgt/warn-fallback
Closed

Enter-tainer wants to merge 4 commits into
typst:mainfrom
Enter-tainer:mgt/warn-fallback

Conversation

@Enter-tainer

@Enter-tainer Enter-tainer commented Feb 5, 2024 •

Copy link
Copy Markdown
Contributor

Print a warning message when no font is selected and we are using heuristic method to select font.

This typically happens when inputing chinese characters without setting specific font.

related issue: #2818

@Enter-tainer

Copy link
Copy Markdown
Contributor Author

🤔 seems that test runner is not happy with new warnings. Any idea to fix this?

@laurmaedje

Copy link
Copy Markdown
Member

Some disorganized thoughts and observations:

  • I think this doesn't work as intended because before select_fallback is invoked, a well-known list of fallback fonts is traversed, which don't trigger the warning.

  • I am not sure whether the book is really the best place to emit the warning or not.

  • Regarding tests, I guess those would have to specify the warnings.

  • I am worried about warning spam if there is a large amount of text with fallback.

  • The error messages itself should be lowercase and not use debug formatting, but I guess that's WIP

  • We might need configuration to enable/disable this, e.g. fallback: false | "warn" | true.

  • I think that the warning for family & style/weight/stretch need to be considered in whole, especially regarding configuration. Do we want to warn if weight 500 is requested, but only 450 exists? If italic is requested, but only oblique exists?

@Enter-tainer

Copy link
Copy Markdown
Contributor Author

I think this doesn't work as intended because before select_fallback is invoked, a well-known list of fallback fonts is traversed, which don't trigger the warning.

Agree. It's missing. It would be better if this can also trigger the warning. But it seems that the usage of that list is somehow scattered everywhere in the code, so I didn't change it. Currently it can only produce warning when all the list is used up, like inputting Chinese characters without setting other fonts.

I can move the code which add the well-known list into consideration to select_fallback if it is desired.

I am not sure whether the book is really the best place to emit the warning or not.

idk either. I feel awkward when adding tracer: TracedMut<Tracer>, span: Span everywhere in the code path. Which place do you prefer? I'd be happy to change the code if there is a better option.

I am worried about warning spam if there is a large amount of text with fallback. We might need configuration to enable/disable this, e.g. fallback: false | "warn" | true.

Yes. We should provide a way to silent warnings. And warnings should be enabled by default.

I think that the warning for family & style/weight/stretch need to be considered in whole, especially regarding configuration. Do we want to warn if weight 500 is requested, but only 450 exists? If italic is requested, but only oblique exists?

It's hard. I think we can add warning to this as long as user can suppress it. This can help user find problems with their font config.

The error messages itself should be lowercase and not use debug formatting, but I guess that's WIP

Yes, it should be improved.

@laurmaedje

Copy link
Copy Markdown
Member

I also want to note that just adding an emoji will already trigger this warning as few people will explicitly list an emoji font in the fallback chain. One might argue that this is reasonable behaviour for a typesetting system, but at the same time it feels like bad ergonomics.

@Enivex

Enivex commented Feb 6, 2024

Copy link
Copy Markdown
Collaborator

We might need configuration to enable/disable this, e.g. fallback: false | "warn" | true.

Would it make sense for there to be a compiler flag for the level of warnings displayed? Personally I'd love to be inundated with warnings, but others might not want to see them at all.

@PgBiel

PgBiel commented Feb 6, 2024

Copy link
Copy Markdown
Contributor

In general I think we could wait for warning suppression to land. I believe there isn't an issue for that, so we could open it.

@Enter-tainer

Enter-tainer commented Feb 7, 2024 •

Copy link
Copy Markdown
Contributor Author

In general I think we could wait for warning suppression to land.

IIUC it wouldn't land in weeks or a few months. And there is a lot of design work to do. But font matching is already causing many problems. New users keep asking "doesn't typst support bold?" or "Why does typst choose X as the default Chinese font?". I think adding a warning atm would yield better UX.

@PgBiel

PgBiel commented Feb 7, 2024

Copy link
Copy Markdown
Contributor

IIUC it wouldn't land in weeks or a few months. And there is a lot of design work to do. But font matching is already causing many problems. New users keep asking "doesn't typst support bold?" or "Why does typst choose X as the default Chinese font?". I think adding a warning atm would yield better UX.

It's true that it will take a while (unless we take action now). But the alternative is to have users inadvertently stuck with warnings in their documents they can't get rid of, such as when using emoji or certain symbols, as Laurenz mentions. So, ideally, we'd use a unified system for toggleable warnings so we can add a ton of them - not just for fallback fonts.

@Enter-tainer

Enter-tainer commented Feb 7, 2024 •

Copy link
Copy Markdown
Contributor Author

They can get rid of the warning using options: fallback: false | "warn" | true. maybe a 1-liner: `#set text(fallback: true).

As for the "unified warning", can we simply add a warning filter arg or something like -wall to disable warning?

@laurmaedje laurmaedje changed the title feat: add warning when using fallback font Add warning when using fallback font Feb 7, 2024
@laurmaedje

Copy link
Copy Markdown
Member

I've posted some thoughts about warning supression and spam in the discord forge. In particular, I am now of the opinion that we

  • should not have fallback: "warn" but rather opt for a more unified interface.
  • should have a system for grouping warnings, so that all font fallback warnings are grouped together by default

@Enter-tainer

Copy link
Copy Markdown
Contributor Author

currently i'm on LNY vacation. i will give a more detailed design later.

@Enter-tainer
Enter-tainer marked this pull request as draft February 14, 2024 01:24
@laurmaedje

Copy link
Copy Markdown
Member

Someone else also started looking into this and asked a few questions, the answers to which might also be relevant here.

@Enter-tainer

Copy link
Copy Markdown
Contributor Author

Maybe i will close this since I have no plan continue working on this in near future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants