KaTeX icon indicating copy to clipboard operation
KaTeX copied to clipboard

feat: Support `\textsc` via small caps font `cmcsc10`

Open benrbray opened this issue 4 years ago • 5 comments

Fixes #471 , adding support for the \textsc command via the small caps font cmcsc10. Thanks to everyone who suggested solutions in the original thread. I'm willing to take this over the finish line, but will need a bit of assistance verifying that the changes I made are reasonable.

For future reference, these are the steps I needed to take (inside the dev container) to run the font generation scripts on my machine:

  • sudo apt install mftrace fontforge fonttools ttfautohint texlive-fonts-recommended (should these be added to the dev container?)
  • modify src/fonts/Makefile to call perl with perl -I . since @INC no longer includes the current working directory in recent Perl versions
  • sudo apt-get install python-pip
  • pip install fonttools zopfli brotli
  • ./dockers/fonts/buildMetrics.sh
  • cd src/fonts && make clean && make all

Output for \textsc{Lorem Ipsum Dolor}

image

Questions / Concerns:

  1. [ ] I'm not sure how to deal with combinations of font weight/shape/style (esp in src/buildCommon.js). Not all combinations are valid, and I'm not sure what the desired priority is, so I made my best guess.
  2. [ ] Should anything be added to src/fonts/makeFF or src/fonts/makeBolder?
  3. [x] In the Chrome inspector, unchecking the "font-style" property of any text command (like \textit, \textsc, \mathbf, etc.) causes the text to render as small caps. Why might this be? How to fix it?
  4. [ ] What's the difference between src/fonts/makeFF and src/metrics/mapping.pl? Is one generated from the other? Should they be kept in sync somehow? The changes I made to each were just my best guess.
  5. [ ] How should the documentation be updated? I see some font prefetching instructions at docs/browser.md which I suspect will need to be updated with the new font.
  6. [ ] All existing tests (jest and screenshots) pass on my machine. What kind of tests should be added for the new font and command?

benrbray avatar Jun 17 '21 18:06 benrbray

Based on the failing automated test artifacts, the new small caps font overrides the default font in some cases. There are also some strange spacing issues. I'll investigate myself, but any help would certainly be appreciated. Thanks!

benrbray avatar Jun 17 '21 18:06 benrbray

The new commit fixes the font override issue. According to the CSS spec, the font-variant property is not used by the font matching algorithm when determining which font to display. Instead, I created a separate font family for the smallcaps font.

The generated character mappings still need some attention, and the automated tests will reveal whether this fixed the spacing issues.

benrbray avatar Jun 18 '21 09:06 benrbray

This PR is ready for review, no rush though. (the tasklist just has some questions that need attention before merging). The changes to font building at #2866 might also affect this PR.

benrbray avatar Jul 06 '21 15:07 benrbray

Any update on this?

RexYuan avatar Jun 24 '23 17:06 RexYuan

Yes please can someone please review this? Thanks @benrbray ❤️

yuvaltassa avatar Oct 29 '23 13:10 yuvaltassa