diff --git a/docs/support_table.md b/docs/support_table.md index 340eabe2..ce3ac8de 100644 --- a/docs/support_table.md +++ b/docs/support_table.md @@ -617,6 +617,7 @@ table td { |\mathinner|$ab\mathinner{\text{inside}}cd$|`ab\mathinner{\text{inside}}cd`| |\mathit|$\mathit{AaBb}$|`\mathit{AaBb}`
KaTeX supports A-Za-z| |\mathllap|${=}\mathllap{/\,}$|`{=}\mathllap{/\,}`| +|\mathnormal|$\mathnormal{AaBb}$|`\mathnormal{AaBb}`
KaTeX supports A-Za-z| |\mathop|$\mathop{\star}_a^b$|`\mathop{\star}_a^b`| |\mathopen|$a + \mathopen\lt b) + c$|`a + \mathopen\lt b) + c`| |\mathord|$1\mathord{,}234{,}567$|`1\mathord{,}234{,}567`| diff --git a/docs/supported.md b/docs/supported.md index 5b4fd607..6fa48d89 100644 --- a/docs/supported.md +++ b/docs/supported.md @@ -515,14 +515,14 @@ For color definition, KaTeX color functions will accept the standard HTML [pred |||| |:------------------------------|:------------------------------|:----- |$\mathrm{Ab0}$ `\mathrm{Ab0}` |$\mathbf{Ab0}$ `\mathbf{Ab0}` |$\mathit{Ab}$ `\mathit{Ab}` -|$\textrm{Ab0}$ `\textrm{Ab0}` |$\textbf{Ab0}$ `\textbf{Ab0}` |$\textit{Ab}$ `\textit{Ab}` -|$\rm Ab0$ `\rm Ab0` |$\bf Ab0$ `\bf Ab0` |$\it Ab$ `\it Ab` -|$\textnormal{Ab0}$ `\textnormal{Ab0}`|$\bold{Ab0}$ `\bold{Ab0}`|$\Bbb{AB}$ `\Bbb{AB}` -|$\text{Ab0}$ `\text{Ab0}` |$\boldsymbol{Ab}$ `\boldsymbol{Ab}`|$\mathbb{AB}$ `\mathbb{AB}` -|$\mathsf{Ab0}$ `\mathsf{Ab0}` |$\bm{Ab}$ `\bm{Ab}` |$\frak{Ab0}$ `\frak{Ab0}` -|$\textsf{Ab0}$ `\textsf{Ab0}` |$\mathtt{Ab0}$ `\mathtt{Ab0}` |$\mathfrak{Ab0}$ `\mathfrak{Ab0}` -|$\sf Ab0$ `\sf Ab0` |$\texttt{Ab0}$ `\texttt{Ab0}` |$\mathcal{AB0}$ `\mathcal{AB0}` -| |$\tt Ab0$ `\tt Ab0` |$\mathscr{AB}$ `\mathscr{AB}` +|$\mathnormal{Ab0}$ `\mathnormal{Ab0}`|$\textbf{Ab0}$ `\textbf{Ab0}` |$\textit{Ab}$ `\textit{Ab}` +|$\textrm{Ab0}$ `\textrm{Ab0}` |$\bf Ab0$ `\bf Ab0` |$\it Ab$ `\it Ab` +|$\rm Ab0$ `\rm Ab0` |$\bold{Ab0}$ `\bold{Ab0}`|$\Bbb{AB}$ `\Bbb{AB}` +|$\textnormal{Ab0}$ `\textnormal{Ab0}`|$\boldsymbol{Ab}$ `\boldsymbol{Ab}`|$\mathbb{AB}$ `\mathbb{AB}` +|$\text{Ab0}$ `\text{Ab0}` |$\bm{Ab}$ `\bm{Ab}` |$\frak{Ab0}$ `\frak{Ab0}` +|$\mathsf{Ab0}$ `\mathsf{Ab0}` |$\mathtt{Ab0}$ `\mathtt{Ab0}` |$\mathfrak{Ab0}$ `\mathfrak{Ab0}` +|$\textsf{Ab0}$ `\textsf{Ab0}` |$\texttt{Ab0}$ `\texttt{Ab0}` |$\mathcal{AB0}$ `\mathcal{AB0}` +|$\sf Ab0$ `\sf Ab0` |$\tt Ab0$ `\tt Ab0` |$\mathscr{AB}$ `\mathscr{AB}` One can stack font family, font weight, and font shape by using the `\textXX` versions of the font functions. So `\textsf{\textbf{H}}` will produce $\textsf{\textbf{H}}$. The other versions do not stack, e.g., `\mathsf{\mathbf{H}}` will produce $\mathsf{\mathbf{H}}$. diff --git a/src/buildCommon.js b/src/buildCommon.js index d0eb6071..aec619f8 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -21,8 +21,8 @@ import type {documentFragment as HtmlDocumentFragment} from "./domTree"; import type {HtmlDomNode, DomSpan, SvgSpan, CssStyle} from "./domTree"; import type {Measurement} from "./units"; -// The following have to be loaded from Main-Italic font, using class mainit -const mainitLetters = [ +// The following have to be loaded from Main-Italic font, using class mathit +const mathitLetters = [ "\\imath", "ı", // dotless i "\\jmath", "ȷ", // dotless j "\\pounds", "\\mathsterling", "\\textsterling", "£", // pounds symbol @@ -72,7 +72,7 @@ const makeSymbol = function( let symbolNode; if (metrics) { let italic = metrics.italic; - if (mode === "text") { + if (mode === "text" || (options && options.font === "mathit")) { italic = 0; } symbolNode = new SymbolNode( @@ -133,11 +133,10 @@ const mathsym = function( /** * Determines which of the two font names (Main-Italic and Math-Italic) and - * corresponding style tags (mainit or mathit) to use for font "mathit", - * depending on the symbol. Use this function instead of fontMap for font - * "mathit". + * corresponding style tags (maindefault or mathit) to use for default math font, + * depending on the symbol. */ -const mathit = function( +const mathdefault = function( value: string, mode: Mode, options: Options, @@ -146,16 +145,46 @@ const mathit = function( if (/[0-9]/.test(value.charAt(0)) || // glyphs for \imath and \jmath do not exist in Math-Italic so we // need to use Main-Italic instead - utils.contains(mainitLetters, value)) { + utils.contains(mathitLetters, value)) { return { fontName: "Main-Italic", - fontClass: "mainit", + fontClass: "mathit", }; } else { return { fontName: "Math-Italic", + fontClass: "mathdefault", + }; + } +}; + +/** + * Determines which of the font names (Main-Italic, Math-Italic, and Caligraphic) + * and corresponding style tags (mathit, mathdefault, or mathcal) to use for font + * "mathnormal", depending on the symbol. Use this function instead of fontMap for + * font "mathnormal". + */ +const mathnormal = function( + value: string, + mode: Mode, + options: Options, + classes: string[], +): {| fontName: string, fontClass: string |} { + if (utils.contains(mathitLetters, value)) { + return { + fontName: "Main-Italic", fontClass: "mathit", }; + } else if (/[0-9]/.test(value.charAt(0))) { + return { + fontName: "Caligraphic-Regular", + fontClass: "mathcal", + }; + } else { + return { + fontName: "Math-Italic", + fontClass: "mathdefault", + }; } }; @@ -210,15 +239,15 @@ const makeOrd = function( } else if (fontOrFamily) { let fontName; let fontClasses; - if (fontOrFamily === "boldsymbol") { - const fontData = boldsymbol(text, mode, options, classes); - fontName = fontData.fontName; - fontClasses = [fontData.fontClass]; - } else if (fontOrFamily === "mathit" || - utils.contains(mainitLetters, text)) { - const fontData = mathit(text, mode, options, classes); + if (fontOrFamily === "boldsymbol" || fontOrFamily === "mathnormal") { + const fontData = fontOrFamily === "boldsymbol" + ? boldsymbol(text, mode, options, classes) + : mathnormal(text, mode, options, classes); fontName = fontData.fontName; fontClasses = [fontData.fontClass]; + } else if (utils.contains(mathitLetters, text)) { + fontName = "Main-Italic"; + fontClasses = ["mathit"]; } else if (isFont) { fontName = fontMap[fontOrFamily].fontName; fontClasses = [fontOrFamily]; @@ -245,7 +274,7 @@ const makeOrd = function( // Makes a symbol in the default font for mathords and textords. if (type === "mathord") { - const fontLookup = mathit(text, mode, options, classes); + const fontLookup = mathdefault(text, mode, options, classes); return makeSymbol(text, fontLookup.fontName, mode, options, classes.concat([fontLookup.fontClass])); } else if (type === "textord") { @@ -705,11 +734,17 @@ const fontMap: {[string]: {| variant: FontVariant, fontName: string |}} = { variant: "italic", fontName: "Main-Italic", }, + "mathit": { + variant: "italic", + fontName: "Main-Italic", + }, - // "mathit" and "boldsymbol" are missing because they require the use of two - // fonts: Main-Italic and Math-Italic for "mathit", and Math-BoldItalic and - // Main-Bold for "boldsymbol". This is handled by a special case in makeOrd - // which ends up calling mathit and boldsymbol. + // Default math font, "mathnormal" and "boldsymbol" are missing because they + // require the use of several fonts: Main-Italic and Math-Italic for default + // math font, Main-Italic, Math-Italic, Caligraphic for "mathnormal", and + // Math-BoldItalic and Main-Bold for "boldsymbol". This is handled by a + // special case in makeOrd which ends up calling mathdefault, mathnormal, + // and boldsymbol. // families "mathbb": { diff --git a/src/buildMathML.js b/src/buildMathML.js index 124ce974..20d42560 100644 --- a/src/buildMathML.js +++ b/src/buildMathML.js @@ -85,7 +85,7 @@ export const getVariant = function( } const font = options.font; - if (!font) { + if (!font || font === "mathnormal") { return null; } diff --git a/src/functions/font.js b/src/functions/font.js index 2ffe0b99..9acd6a7e 100644 --- a/src/functions/font.js +++ b/src/functions/font.js @@ -32,7 +32,7 @@ defineFunction({ type: "font", names: [ // styles, except \boldsymbol defined below - "\\mathrm", "\\mathit", "\\mathbf", + "\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", // families "\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf", diff --git a/src/katex.less b/src/katex.less index 9dd8f7ea..c26e1f9c 100644 --- a/src/katex.less +++ b/src/katex.less @@ -74,11 +74,16 @@ } // Math fonts. - .mathit { + .mathdefault { font-family: KaTeX_Math; font-style: italic; } + .mathit { + font-family: KaTeX_Main; + font-style: italic; + } + .mathrm { font-style: normal; } @@ -138,11 +143,6 @@ font-style: italic; } - .mainit { - font-family: KaTeX_Main; - font-style: italic; - } - .mainrm { font-family: KaTeX_Main; font-style: normal; diff --git a/src/wide-character.js b/src/wide-character.js index c10cc1c9..02260253 100644 --- a/src/wide-character.js +++ b/src/wide-character.js @@ -25,8 +25,8 @@ const wideLatinLetterData: Array<[string, string, string]> = [ ["mathbf", "textbf", "Main-Bold"], // A-Z bold upright ["mathbf", "textbf", "Main-Bold"], // a-z bold upright - ["mathit", "textit", "Math-Italic"], // A-Z italic - ["mathit", "textit", "Math-Italic"], // a-z italic + ["mathdefault", "textit", "Math-Italic"], // A-Z italic + ["mathdefault", "textit", "Math-Italic"], // a-z italic ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // A-Z bold italic ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // a-z bold italic diff --git a/test/__snapshots__/katex-spec.js.snap b/test/__snapshots__/katex-spec.js.snap index 7a4197cc..c826c263 100755 --- a/test/__snapshots__/katex-spec.js.snap +++ b/test/__snapshots__/katex-spec.js.snap @@ -137,7 +137,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0, "height": 0.43056, @@ -180,7 +180,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0, "height": 0.69444, @@ -268,7 +268,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0, "height": 0.43056, @@ -356,7 +356,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0, "height": 0.69444, @@ -459,7 +459,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0, "height": 0.43056, @@ -547,7 +547,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = { "classes": [ "mord", - "mathit" + "mathdefault" ], "depth": 0.19444, "height": 0.69444, diff --git a/test/katex-spec.js b/test/katex-spec.js index 4b7f6be4..5515b990 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -1483,13 +1483,15 @@ describe("A style change parser", function() { }); describe("A font parser", function() { - it("should parse \\mathrm, \\mathbb, and \\mathit", function() { + it("should parse \\mathrm, \\mathbb, \\mathit, and \\mathnormal", function() { expect`\mathrm x`.toParse(); expect`\mathbb x`.toParse(); expect`\mathit x`.toParse(); + expect`\mathnormal x`.toParse(); expect`\mathrm {x + 1}`.toParse(); expect`\mathbb {x + 1}`.toParse(); expect`\mathit {x + 1}`.toParse(); + expect`\mathnormal {x + 1}`.toParse(); }); it("should parse \\mathcal and \\mathfrak", function() { @@ -1510,6 +1512,10 @@ describe("A font parser", function() { expect(mathitParse.font).toEqual("mathit"); expect(mathitParse.type).toEqual("font"); + const mathnormalParse = getParsed`\mathnormal x`[0]; + expect(mathnormalParse.font).toEqual("mathnormal"); + expect(mathnormalParse.type).toEqual("font"); + const mathcalParse = getParsed`\mathcal C`[0]; expect(mathcalParse.font).toEqual("mathcal"); expect(mathcalParse.type).toEqual("font"); @@ -1783,6 +1789,19 @@ describe("A MathML font tree-builder", function() { expect(markup).toContain("+"); }); + it("should render \\mathnormal{" + contents + "} with the correct mathvariants", function() { + const tex = `\\mathnormal{${contents}}`; + const tree = getParsed(tex); + const markup = buildMathML(tree, tex, defaultOptions).toMarkup(); + expect(markup).toContain("A"); + expect(markup).toContain("x"); + expect(markup).toContain("2"); + expect(markup).toContain("\u03c9"); // \omega + expect(markup).toContain("\u03A9"); // \Omega + expect(markup).toContain("\u0131"); // \imath + expect(markup).toContain("+"); + }); + it("should render \\mathbf{" + contents + "} with the correct mathvariants", function() { const tex = `\\mathbf{${contents}}`; const tree = getParsed(tex); diff --git a/test/screenshotter/images/DashesAndQuotes-chrome.png b/test/screenshotter/images/DashesAndQuotes-chrome.png index f73664f5..000bc5d7 100644 Binary files a/test/screenshotter/images/DashesAndQuotes-chrome.png and b/test/screenshotter/images/DashesAndQuotes-chrome.png differ diff --git a/test/screenshotter/images/DashesAndQuotes-firefox.png b/test/screenshotter/images/DashesAndQuotes-firefox.png index 1dbc83d4..5be4346f 100644 Binary files a/test/screenshotter/images/DashesAndQuotes-firefox.png and b/test/screenshotter/images/DashesAndQuotes-firefox.png differ diff --git a/test/screenshotter/images/MathIt-chrome.png b/test/screenshotter/images/MathIt-chrome.png index b55bb3ba..d5516fcc 100644 Binary files a/test/screenshotter/images/MathIt-chrome.png and b/test/screenshotter/images/MathIt-chrome.png differ diff --git a/test/screenshotter/images/MathIt-firefox.png b/test/screenshotter/images/MathIt-firefox.png index 4369837d..bd5ca9bc 100644 Binary files a/test/screenshotter/images/MathIt-firefox.png and b/test/screenshotter/images/MathIt-firefox.png differ diff --git a/test/screenshotter/images/MathNormal-chrome.png b/test/screenshotter/images/MathNormal-chrome.png new file mode 100644 index 00000000..fab45f7a Binary files /dev/null and b/test/screenshotter/images/MathNormal-chrome.png differ diff --git a/test/screenshotter/images/MathNormal-firefox.png b/test/screenshotter/images/MathNormal-firefox.png new file mode 100644 index 00000000..cd562d5b Binary files /dev/null and b/test/screenshotter/images/MathNormal-firefox.png differ diff --git a/test/screenshotter/images/OldFont-chrome.png b/test/screenshotter/images/OldFont-chrome.png index 26b26417..19d9db33 100644 Binary files a/test/screenshotter/images/OldFont-chrome.png and b/test/screenshotter/images/OldFont-chrome.png differ diff --git a/test/screenshotter/images/OldFont-firefox.png b/test/screenshotter/images/OldFont-firefox.png index ff9331ca..f5d5833d 100644 Binary files a/test/screenshotter/images/OldFont-firefox.png and b/test/screenshotter/images/OldFont-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 5055ac15..34e55889 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -200,6 +200,7 @@ MathBf: \mathbf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} MathCal: \mathcal{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} MathFrak: \mathfrak{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} MathIt: \mathit{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} +MathNormal: \mathnormal{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} MathOp: a\mathop+b\mathop:c\mathop{\delta}e\mathop{\textrm{and}}f\mathrel{\mathop{:}}=g\sin h MathRm: \mathrm{Ax2k\breve{a}\omega\Omega\imath+\KaTeX} MathSf: \mathsf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}