Repository navigation
Warn about unknown font families during parsing - #3854
Conversation
TextElem with unknown font familyTextElem with unknown font family and fallback: false
8229e54 to
ca40f43
Compare
The parent styles are simply not know at this point, and there could actually be multiple different ones. Consider e.g.: #let var = text(font: "non-existent")[Var]
#set text(fallback: true)
#var
#set text(fallback: false)
#varAfter thinking some more about it, I think we can just only ever warn about this and not make the warning conditional on whether fallback is enabled. When Another thing is that your current implementation doesn't work with set rules, because
If you use |
|
Okay, makes sense! I updated the PR to warn in a #text(font: "non-existing", "Hello")
#set text(font: "also-non-existing")
#let var = text(font: ("list-of", "non-existing-fonts"))[Var]I think the list of multiple fonts should use a smaller span to each single font, but maybe this is something for follow up work? If you green light these changes, I can add some tests for the warning in particular. I already had to annotate warnings in two test files, I am not sure if it was intended that these fonts are missing. Should I look into it, or should we commit the warnings for now? |
It's a common limitation. There isn't really a way to recover these spans. It's okay as-is.
Yeah, the change looks good! The existing failures aren't intentional. That's actually a problem your PR found in the existing tests! But you can commit the warnings for now. |
7439cc7 to
916e9b5
Compare
TextElem with unknown font family and fallback: false|
@laurmaedje I added the examples of my last comment to one of the test files for text, rebased on current main and separated the changes into three reasonable commits - they can probably be squashed though. |
|
Looks good. However, I decided to merge #3922 first because the whole spirit of that PR is to not merge any further large reference images, so you'll unfortunately have to merge/rebase. Sorry about that! |
916e9b5 to
d9287df
Compare
|
No problem, updated |
|
Thanks! |
|
The warning on Is there something that can be done to fix this issue? For example, would Typst maintainers agree with the idea of emitting a warning only when none of the suggested fonts can be found? Any advice on preparing a PR to implement this? |
It's a tricky situation. Sometimes, you want a fallback list because two fonts are similar, and sometimes your fallback list contains a text and an emoji font and you need both. So I'm not sure it's desirable either. The change you propose would be easy to implement, in |
|
My intuition is that we should ensure that the choice of behavior covers the common, easy/natural case (with an attention to backward-compatibility), and then possibly suggest a separate API to express the more subtle/advanced needs. From a distance my impression is that "I would like one of these fonts" is a common case, while "I need both of these fallbacks at once" is the less common case, but this is subjective, I may be biased given that I encountered precisely the first need in practice and not the second. |
|
I looked at the code that you recommended and I see why things are more complex. There are two different concerns:
Ideally as a first step we want some logic that :
I can see two approaches to do this: A. We could handle each font as if it had no cover restriction, and thus warn only if none of the fonts are available; or, Approach (A) will err on the side of not warning enough in some cases, while approach (B) will err on the side of warning too much in some cases. Both work perfectly well in the common case where there are no cover restrictions. I don't have a strong opinion between A and B; I may give B a try, given that it is closer in spirit to the current implementation (it warns too much, just like today). |
See the discussion in typst#3854 (comment)
|
I propose an implementation of approach (B) in #7272. |
See the discussion in typst#3854 (comment)
See the discussion in typst#3854 (comment)
…dded This test case predates the _unknown font family_ warning (typst#3854). I guess the original author wanted to test IBM Plex Mono, but did not realize that the font falls back to Libertinus Serif.
…dded This test case predates the _unknown font family_ warning (typst#3854). I guess the original author wanted to test IBM Plex Mono, but did not realize that the font falls back to Libertinus Serif.
First progress on #1967
Edit: This started out as a PR to error when
fallback: true, but we decided to first add a warning when encountering an unknown font, regardless offallback. Original description below:As discussed in the issue, I will try to emit errors first before thinking about warnings. This PR introduces a check for the easiest situation:
yields
However, the slightly more complicated case
does not produce an error. This is because the check is currently in
TextElem::constructand only inspects the direct arguments, not the inherited style.Another example of this is
I think this is a bit unsatisfying, but better than the status-quo. Do you think it will be difficult to do the check later when style is inherited? Or am I missing an obvious way to inspect parent styles in the constructor here?
I had some trouble with getting the span of the
fontargument, because as far as I can tell, theTextElemdoes not know the spans of its arguments after construction, so I had to get the span just before setting the style.