Skip to content

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

FreyaHolmer
Copy link

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

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!
@FreyaHolmer FreyaHolmer changed the title fix(css): fefault to font-display: swap; closes #2242 fix(css): Default to font-display: swap; closes #2242 Mar 21, 2024
@yao-genius
Copy link

Why hasn't this fix been approved yet? I had the same problem.

@edemaine
Copy link
Member

edemaine commented Oct 8, 2024

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 .css builds with different settings. I think block and swap are the two natural choices here, depending on whether you want to flash empty content (current behavior I guess) or flash incorrectly styled content.

@edemaine edemaine changed the title fix(css): Default to font-display: swap; closes #2242 feat(css): provide katex-swap.css that uses font-display: swap Dec 8, 2024
Copy link
Member

@edemaine edemaine left a 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 and katex.min.css use font-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 and katex-swap.min.css use font-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.

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.

Use font-display: swap to prevent invisible text on load
3 participants