Reorganize some glyphs, simplify font selection, break \mathcal{123} (#2156)

* Reorganize some glyphs

* Remove mathdefault

Numerals are textord and it was never reachable.

* Use PUA for \imath and \jmath

* Update katex-fonts

* Update tests

* Update src/buildCommon.js

* Update screenshots

* Add comment regarding usage of PUA in \imath and \jmath

* Update fonts

Co-authored-by: Erik Demaine <edemaine@mit.edu>
This commit is contained in:
ylemkimon
2020-07-12 03:54:28 +09:00
committed by GitHub
parent 754c601e34
commit d1c0468ef8
34 changed files with 48 additions and 113 deletions

View File

@@ -8,7 +8,6 @@
import {SymbolNode, Anchor, Span, PathNode, SvgNode, createClass} from "./domTree";
import {getCharacterMetrics} from "./fontMetrics";
import symbols, {ligatures} from "./symbols";
import utils from "./utils";
import {wideCharacterFont} from "./wide-character";
import {calculateSize} from "./units";
import {DocumentFragment} from "./tree";
@@ -21,13 +20,6 @@ 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 mathit
const mathitLetters = [
"\\imath", "ı", // dotless i
"\\jmath", "ȷ", // dotless j
"\\pounds", "\\mathsterling", "\\textsterling", "£", // pounds symbol
];
/**
* Looks up the given symbol in fontMetrics, after applying any symbol
* replacements defined in symbol.js
@@ -128,63 +120,6 @@ const mathsym = function(
}
};
/**
* Determines which of the two font names (Main-Italic and Math-Italic) and
* corresponding style tags (mathdefault or mathit) to use for default math font,
* depending on the symbol.
*/
const mathdefault = function(
value: string,
mode: Mode,
options: Options,
classes: string[],
): {| fontName: string, fontClass: string |} {
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(mathitLetters, value)) {
return {
fontName: "Main-Italic",
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",
};
}
};
/**
* Determines which of the two font names (Main-Bold and Math-BoldItalic) and
* corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
@@ -238,15 +173,10 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
} else if (fontOrFamily) {
let fontName;
let fontClasses;
if (fontOrFamily === "boldsymbol" || fontOrFamily === "mathnormal") {
const fontData = fontOrFamily === "boldsymbol"
? boldsymbol(text, mode, options, classes, type)
: mathnormal(text, mode, options, classes);
if (fontOrFamily === "boldsymbol") {
const fontData = boldsymbol(text, mode, options, classes, type);
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];
@@ -273,9 +203,8 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
// Makes a symbol in the default font for mathords and textords.
if (type === "mathord") {
const fontLookup = mathdefault(text, mode, options, classes);
return makeSymbol(text, fontLookup.fontName, mode, options,
classes.concat([fontLookup.fontClass]));
return makeSymbol(text, "Math-Italic", mode, options,
classes.concat(["mathnormal"]));
} else if (type === "textord") {
const font = symbols[mode][text] && symbols[mode][text].font;
if (font === "ams") {
@@ -754,13 +683,14 @@ const fontMap: {[string]: {| variant: FontVariant, fontName: string |}} = {
variant: "italic",
fontName: "Main-Italic",
},
"mathnormal": {
variant: "italic",
fontName: "Math-Italic",
},
// 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.
// "boldsymbol" is missing because they require the use of multiple fonts:
// Math-BoldItalic and Main-Bold. This is handled by a special case in
// makeOrd which ends up calling boldsymbol.
// families
"mathbb": {

View File

@@ -84,7 +84,7 @@
}
// Math fonts.
.mathdefault {
.mathnormal {
font-family: KaTeX_Math;
font-style: italic;
}

View File

@@ -855,6 +855,8 @@ defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}");
//////////////////////////////////////////////////////////////////////
// stmaryrd and semantic

View File

@@ -681,8 +681,11 @@ defineSymbol(math, main, accent, "\u005e", "\\hat");
defineSymbol(math, main, accent, "\u20d7", "\\vec");
defineSymbol(math, main, accent, "\u02d9", "\\dot");
defineSymbol(math, main, accent, "\u02da", "\\mathring");
defineSymbol(math, main, mathord, "\u0131", "\\imath", true);
defineSymbol(math, main, mathord, "\u0237", "\\jmath", true);
// \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
defineSymbol(math, main, mathord, "\ue131", "\\@imath");
defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
defineSymbol(math, main, textord, "\u0131", "\u0131");
defineSymbol(math, main, textord, "\u0237", "\u0237");
defineSymbol(text, main, textord, "\u0131", "\\i", true);
defineSymbol(text, main, textord, "\u0237", "\\j", true);
defineSymbol(text, main, textord, "\u00df", "\\ss", true);
@@ -731,11 +734,11 @@ defineSymbol(text, main, textord, "\u00b0", "\\degree");
// \textdegree from inputenc package
defineSymbol(text, main, textord, "\u00b0", "\\textdegree", true);
// TODO: In LaTeX, \pounds can generate a different character in text and math
// mode, but among our fonts, only Main-Italic defines this character "163".
defineSymbol(math, main, mathord, "\u00a3", "\\pounds");
defineSymbol(math, main, mathord, "\u00a3", "\\mathsterling", true);
defineSymbol(text, main, mathord, "\u00a3", "\\pounds");
defineSymbol(text, main, mathord, "\u00a3", "\\textsterling", true);
// mode, but among our fonts, only Main-Regular defines this character "163".
defineSymbol(math, main, textord, "\u00a3", "\\pounds");
defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
defineSymbol(text, main, textord, "\u00a3", "\\pounds");
defineSymbol(text, main, textord, "\u00a3", "\\textsterling", true);
defineSymbol(math, ams, textord, "\u2720", "\\maltese");
defineSymbol(text, ams, textord, "\u2720", "\\maltese");

View File

@@ -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
["mathdefault", "textit", "Math-Italic"], // A-Z italic
["mathdefault", "textit", "Math-Italic"], // a-z italic
["mathnormal", "textit", "Math-Italic"], // A-Z italic
["mathnormal", "textit", "Math-Italic"], // a-z italic
["boldsymbol", "boldsymbol", "Main-BoldItalic"], // A-Z bold italic
["boldsymbol", "boldsymbol", "Main-BoldItalic"], // a-z bold italic

View File

@@ -137,7 +137,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -180,7 +180,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.69444,
@@ -268,7 +268,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -356,7 +356,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.69444,
@@ -459,7 +459,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -547,7 +547,7 @@ exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] =
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0.19444,
"height": 0.69444,
@@ -670,7 +670,7 @@ exports[`An HTML extension builder should not affect spacing 1`] = `
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -739,7 +739,7 @@ exports[`An HTML extension builder should not affect spacing 1`] = `
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0.19444,
"height": 0.43056,
@@ -764,7 +764,7 @@ exports[`An HTML extension builder should render with trust and strict setting 1
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -793,7 +793,7 @@ exports[`An HTML extension builder should render with trust and strict setting 1
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -824,7 +824,7 @@ exports[`An HTML extension builder should render with trust and strict setting 1
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -855,7 +855,7 @@ exports[`An HTML extension builder should render with trust and strict setting 1
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -1216,7 +1216,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an
style="height:0.68333em;vertical-align:0em;"
>
</span>
<span class="mord mathdefault"
<span class="mord mathnormal"
style="margin-right:0.10903em;"
>
M
@@ -1236,7 +1236,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an
style="height:0.66666em;vertical-align:-0.08333em;"
>
</span>
<span class="mord mathdefault">
<span class="mord mathnormal">
a
</span>
<span class="mspace"
@@ -1254,7 +1254,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an
style="height:0.69444em;vertical-align:0em;"
>
</span>
<span class="mord mathdefault">
<span class="mord mathnormal">
b
</span>
</span>
@@ -1265,7 +1265,7 @@ exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel an
style="height:0.43056em;vertical-align:0em;"
>
</span>
<span class="mord mathdefault">
<span class="mord mathnormal">
c
</span>
</span>
@@ -1424,7 +1424,7 @@ exports[`href and url commands should not affect spacing around 1`] = `
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.43056,
@@ -1488,7 +1488,7 @@ exports[`href and url commands should not affect spacing around 1`] = `
{
"classes": [
"mord",
"mathdefault"
"mathnormal"
],
"depth": 0,
"height": 0.69444,

View File

@@ -1837,7 +1837,7 @@ describe("A MathML font tree-builder", function() {
expect(markup).toContain("<mn>2</mn>");
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
expect(markup).toContain("<mi mathvariant=\"normal\">\u0131</mi>"); // \imath
expect(markup).toContain("<mo>+</mo>");
});
@@ -1863,7 +1863,7 @@ describe("A MathML font tree-builder", function() {
expect(markup).toContain("<mn>2</mn>");
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
expect(markup).toContain("<mi mathvariant=\"normal\">\u0131</mi>"); // \imath
expect(markup).toContain("<mo>+</mo>");
});
@@ -1889,7 +1889,7 @@ describe("A MathML font tree-builder", function() {
expect(markup).toContain("<mn>2</mn>");
expect(markup).toContain("<mi>\u03c9</mi>"); // \omega
expect(markup).toContain("<mi mathvariant=\"normal\">\u03A9</mi>"); // \Omega
expect(markup).toContain("<mi>\u0131</mi>"); // \imath
expect(markup).toContain("<mi mathvariant=\"normal\">\u0131</mi>"); // \imath
expect(markup).toContain("<mo>+</mo>");
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB