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