Skip to content

Commit

Permalink
feat: Support bold Fraktur (#3777)
Browse files Browse the repository at this point in the history
* feat: Support bold Fraktur

* Evade wideCharacterFont() when inapplicable

* Avoid creating array when uneccesary

---------

Co-authored-by: Erik Demaine <edemaine@mit.edu>
  • Loading branch information
ronkok and edemaine authored Oct 2, 2023
1 parent 4f1d916 commit 240d5ae
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ Math-mode Unicode (sub|super)script characters will render as if you had written
| Italic | $\text{𝐴-𝑍 𝑎-𝑧}$ | Sans serif | $\text{𝖠-𝖹 𝖺-𝗓 𝟢-𝟫}$
| Bold Italic | $\text{𝑨-𝒁 𝒂-𝒛}$ | Sans serif bold | $\text{𝗔-𝗭 𝗮-𝘇 𝟬-𝟵}$
| Script | $\text{𝒜-𝒵}$ | Sans serif italic | $\text{𝘈-𝘡 𝘢-𝘻}$
| Fractur | $\text{𝔄-}ℨ\text{ 𝔞-𝔷}$| Monospace | $\text{𝙰-𝚉 𝚊-𝚣 𝟶-𝟿}$
| Fractur | $\text{𝔄-ℨ}\text{ 𝔞-𝔷}$| Monospace | $\text{𝙰-𝚉 𝚊-𝚣 𝟶-𝟿}$
| Bold Fractur | $\text{𝕬-𝖅}\text{𝖆-𝖟}$ | |

</div>
<div class="katex-hopscotch">
Expand Down
6 changes: 5 additions & 1 deletion src/buildCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
// Math mode or Old font (i.e. \rm)
const isFont = mode === "math" || (mode === "text" && options.font);
const fontOrFamily = isFont ? options.font : options.fontFamily;
let wideFontName = "";
let wideFontClass = "";
if (text.charCodeAt(0) === 0xD835) {
[wideFontName, wideFontClass] = wideCharacterFont(text, mode);
}
if (wideFontName.length > 0) {
// surrogate pairs get special treatment
const [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
return makeSymbol(text, wideFontName, mode, options,
classes.concat(wideFontClass));
} else if (fontOrFamily) {
Expand Down
6 changes: 6 additions & 0 deletions src/katex.less
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
font-family: KaTeX_Fraktur;
}

.mathboldfrak,
.textboldfrak {
font-family: KaTeX_Fraktur;
font-weight: bold;
}

.mathtt {
font-family: KaTeX_Typewriter;
}
Expand Down
4 changes: 4 additions & 0 deletions src/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,10 @@ for (let i = 0; i < letters.length; i++) {
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);

wideChar = String.fromCharCode(0xD835, 0xDD6C + i); // A-Z a-z bold Fractur
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);

wideChar = String.fromCharCode(0xD835, 0xDDA0 + i); // A-Z a-z sans-serif
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
Expand Down
5 changes: 3 additions & 2 deletions src/wide-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ const wideLatinLetterData: Array<[string, string, string]> = [
["mathbb", "textbb", "AMS-Regular"], // A-Z double-struck
["mathbb", "textbb", "AMS-Regular"], // k double-struck

["", "", ""], // A-Z bold Fraktur No font metrics
["", "", ""], // a-z bold Fraktur. No font.
// Note that we are using a bold font, but font metrics for regular Fraktur.
["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // A-Z bold Fraktur
["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // a-z bold Fraktur

["mathsf", "textsf", "SansSerif-Regular"], // A-Z sans-serif
["mathsf", "textsf", "SansSerif-Regular"], // a-z sans-serif
Expand Down
2 changes: 2 additions & 0 deletions test/katex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3919,6 +3919,7 @@ describe("Unicode", function() {
wideCharStr += String.fromCharCode(0xD835, 0xDC00); // bold A
wideCharStr += String.fromCharCode(0xD835, 0xDC68); // bold italic A
wideCharStr += String.fromCharCode(0xD835, 0xDD04); // Fraktur A
wideCharStr += String.fromCharCode(0xD835, 0xDD6C); // bold Fraktur A
wideCharStr += String.fromCharCode(0xD835, 0xDD38); // double-struck
wideCharStr += String.fromCharCode(0xD835, 0xDC9C); // script A
wideCharStr += String.fromCharCode(0xD835, 0xDDA0); // sans serif A
Expand All @@ -3935,6 +3936,7 @@ describe("Unicode", function() {
wideCharText += String.fromCharCode(0xD835, 0xDC00); // bold A
wideCharText += String.fromCharCode(0xD835, 0xDC68); // bold italic A
wideCharText += String.fromCharCode(0xD835, 0xDD04); // Fraktur A
wideCharStr += String.fromCharCode(0xD835, 0xDD6C); // bold Fraktur A
wideCharText += String.fromCharCode(0xD835, 0xDD38); // double-struck
wideCharText += String.fromCharCode(0xD835, 0xDC9C); // script A
wideCharText += String.fromCharCode(0xD835, 0xDDA0); // sans serif A
Expand Down

0 comments on commit 240d5ae

Please sign in to comment.