-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(css): provide katex-swap.css
that uses font-display: swap
#3940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Google fonts seem to default to swap, and mixing them with katex makes it so that katex is invisible briefly on page load, unlike google fonts which make use of fallbacks while loading. This would unify their behavior. Ideally there'd be an option for this, and a ?display=swap in the cdn url (like google fonts: https://developers.google.com/fonts/docs/css2#use_font-display), but I don't know if jsdelivr supports that!
Why hasn't this fix been approved yet? I had the same problem. |
This PR needs to be ported from less to scss, though I suspect that would be easy. There's also a question of what's the best default. Actually, we could offer multiple |
katex-swap.css
that uses font-display: swap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this, and apologies for the long delay.
I modified the PR to work as follows:
katex.css
andkatex.min.css
usefont-display: block
, roughly the same as before. I believe this is still a useful configuration to avoid "flash of unstyled text" (FOUT), but instead have "flash of invisible content" (FOIT) (more info).- In particular, I hesitate to modify the default here, because so many people use KaTeX and this might be a significant deviation from expected behavior.
katex-swap.css
andkatex-swap.min.css
usefont-display: swap
to enable "flash of unstyled text" (FOIT) instead of "flash of invisible content" (FOUT)- Variable
$font-display
is still overridable (now via SCSS instead of Less)
TLDR: if you want font-display: swap
, you use katex-swap.css
instead of katex.css
. But default remains roughly the same.
I'd appreciate any feedback on this approach (from original poster or anyone else interested in this feature) before merging.
Use `webpack-remove-empty-scripts` instead of `splitChunks`
Google fonts seem to default to swap, and mixing them with katex makes it so that katex is invisible briefly on page load, unlike google fonts which make use of fallbacks while loading. This would unify their behavior.
Ideally there'd be an option for this, and a ?display=swap in the cdn url (like google fonts: https://developers.google.com/fonts/docs/css2#use_font-display), but I don't know if jsdelivr supports that!
What is the previous behavior before this PR?
Katex fonts would be invisible until loaded
What is the new behavior after this PR?
Katex fonts will now render a fallback until fonts have been loaded
BREAKING CHANGE: changes font loading behavior to font-display: swap,
which means equations will render a fallback before loaded
instead of being invisible
Closes #2242