From 23aad265bdc8a7b0aa192dc4bf58800fadbb286e Mon Sep 17 00:00:00 2001 From: Ron Kok Date: Wed, 18 Jan 2023 11:15:57 -0800 Subject: [PATCH 1/3] feat: Support bold Fraktur --- docs/supported.md | 3 ++- src/katex.less | 6 ++++++ src/symbols.js | 4 ++++ src/wide-character.js | 5 +++-- test/katex-spec.js | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/supported.md b/docs/supported.md index 508ce41317..bfec5bdb60 100644 --- a/docs/supported.md +++ b/docs/supported.md @@ -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{𝖆-𝖟}$ | |
diff --git a/src/katex.less b/src/katex.less index 2222fbc7ca..18a8d9294f 100644 --- a/src/katex.less +++ b/src/katex.less @@ -129,6 +129,12 @@ font-family: KaTeX_Fraktur; } + .mathboldfrak, + .textboldfrak { + font-family: KaTeX_Fraktur; + font-weight: bold; + } + .mathtt { font-family: KaTeX_Typewriter; } diff --git a/src/symbols.js b/src/symbols.js index ae495801d0..6971d37f5d 100644 --- a/src/symbols.js +++ b/src/symbols.js @@ -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); diff --git a/src/wide-character.js b/src/wide-character.js index f9e680d756..af5335c502 100644 --- a/src/wide-character.js +++ b/src/wide-character.js @@ -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 diff --git a/test/katex-spec.js b/test/katex-spec.js index a2b088b323..394cd65db1 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -3857,6 +3857,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 @@ -3873,6 +3874,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 From 3c4d289ee8ee25cd1839ab00b1a360a0f94b11d1 Mon Sep 17 00:00:00 2001 From: Ron Kok Date: Wed, 18 Jan 2023 13:42:56 -0800 Subject: [PATCH 2/3] Evade wideCharacterFont() when inapplicable --- src/buildCommon.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/buildCommon.js b/src/buildCommon.js index 5f0bbae61e..14b6753822 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -165,9 +165,11 @@ const makeOrd = function( // Math mode or Old font (i.e. \rm) const isFont = mode === "math" || (mode === "text" && options.font); const fontOrFamily = isFont ? options.font : options.fontFamily; - if (text.charCodeAt(0) === 0xD835) { + const [wideFontName, wideFontClass] = text.charCodeAt(0) !== 0xD835 + ? ["", ""] + : 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) { From 29ee8da24f5b92784afd4412ae9bf144f9ed1d40 Mon Sep 17 00:00:00 2001 From: Ron Kok Date: Mon, 2 Oct 2023 13:00:03 -0700 Subject: [PATCH 3/3] Avoid creating array when uneccesary --- src/buildCommon.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/buildCommon.js b/src/buildCommon.js index 14b6753822..4c8ab98d45 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -165,9 +165,11 @@ const makeOrd = function( // Math mode or Old font (i.e. \rm) const isFont = mode === "math" || (mode === "text" && options.font); const fontOrFamily = isFont ? options.font : options.fontFamily; - const [wideFontName, wideFontClass] = text.charCodeAt(0) !== 0xD835 - ? ["", ""] - : wideCharacterFont(text, mode); + let wideFontName = ""; + let wideFontClass = ""; + if (text.charCodeAt(0) === 0xD835) { + [wideFontName, wideFontClass] = wideCharacterFont(text, mode); + } if (wideFontName.length > 0) { // surrogate pairs get special treatment return makeSymbol(text, wideFontName, mode, options,