Skip to content
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

feat: Support bold Fraktur #3777

Merged
merged 7 commits into from Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/supported.md
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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid the array creation in the negative case. How about this:

let wideFontName, wideFontClass;
if (text.charCodeAt(0) === 0xD835) {
  [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
}
if (wideFontName) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

// 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
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
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
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
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