mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 14:08:42 +00:00
unicodeTextInMathMode setting (#1117)
* unicodeTextInMathMode setting * When `unicodeTextInMathMode` is `true`, accented letters from `unicodeSymbols.js`, and CJK and other supported languages, get added support in math mode (as requested in #895). * When `unicodeTextInMathMode` is `false, all of these stop working in math mode, and are only supported in text mode (matching XeTeX behavior). Note that this is a backwards incompatibility with some 0.9.0 alpha/betas. * Fix handling of Unicode characters ð, Å, å * Fix double handling of ð (math maps to \eth, not special Unicode character) * Remove Åå special math handling, thanks to #1125 * Forbid extraLatin when unicodeTextInMathMode is false
This commit is contained in:
committed by
Kevin Barabash
parent
7de91f73eb
commit
aed1c1e564
@@ -4,7 +4,7 @@
|
||||
import functions from "./functions";
|
||||
import environments from "./environments";
|
||||
import MacroExpander from "./MacroExpander";
|
||||
import symbols from "./symbols";
|
||||
import symbols, { extraLatin } from "./symbols";
|
||||
import { validUnit } from "./units";
|
||||
import { supportedCodepoint } from "./unicodeScripts";
|
||||
import unicodeAccents from "./unicodeAccents";
|
||||
@@ -968,9 +968,12 @@ export default class Parser {
|
||||
return newDollar(nucleus);
|
||||
}
|
||||
// At this point, we should have a symbol, possibly with accents.
|
||||
// First expand any accented base symbol according to unicodeSymbols.
|
||||
// First expand any accented base symbol according to unicodeSymbols,
|
||||
// unless we're in math mode and unicodeTextInMathMode is false
|
||||
// (XeTeX-compatible mode).
|
||||
if (unicodeSymbols.hasOwnProperty(text[0]) &&
|
||||
!symbols[this.mode][text[0]]) {
|
||||
!symbols[this.mode][text[0]] &&
|
||||
(this.settings.unicodeTextInMathMode || this.mode === "text")) {
|
||||
text = unicodeSymbols[text[0]] + text.substr(1);
|
||||
}
|
||||
// Strip off any combining characters
|
||||
@@ -986,10 +989,15 @@ export default class Parser {
|
||||
// Recognize base symbol
|
||||
let symbol = null;
|
||||
if (symbols[this.mode][text]) {
|
||||
if (this.mode === 'math' && extraLatin.indexOf(text) >= 0 &&
|
||||
!this.settings.unicodeTextInMathMode) {
|
||||
throw new ParseError(`Unicode text character ${text} used in ` +
|
||||
`math mode without unicodeTextInMathMode setting`, nucleus);
|
||||
}
|
||||
symbol = new ParseNode(symbols[this.mode][text].group,
|
||||
text, this.mode, nucleus);
|
||||
} else if (this.mode === "text" &&
|
||||
supportedCodepoint(text.charCodeAt(0))) {
|
||||
} else if (supportedCodepoint(text.charCodeAt(0)) &&
|
||||
(this.mode === "text" || this.settings.unicodeTextInMathMode)) {
|
||||
symbol = new ParseNode("textord", text, this.mode, nucleus);
|
||||
} else {
|
||||
return null; // EOF, ^, _, {, }, etc.
|
||||
|
@@ -14,6 +14,7 @@ export type SettingsOptions = {
|
||||
errorColor?: string;
|
||||
macros?: MacroMap;
|
||||
colorIsTextColor?: boolean;
|
||||
unicodeTextInMathMode?: boolean;
|
||||
maxSize?: number;
|
||||
};
|
||||
|
||||
@@ -33,6 +34,7 @@ class Settings {
|
||||
errorColor: string;
|
||||
macros: MacroMap;
|
||||
colorIsTextColor: boolean;
|
||||
unicodeTextInMathMode: boolean;
|
||||
maxSize: number;
|
||||
|
||||
constructor(options: SettingsOptions) {
|
||||
@@ -43,6 +45,8 @@ class Settings {
|
||||
this.errorColor = utils.deflt(options.errorColor, "#cc0000");
|
||||
this.macros = options.macros || {};
|
||||
this.colorIsTextColor = utils.deflt(options.colorIsTextColor, false);
|
||||
this.unicodeTextInMathMode =
|
||||
utils.deflt(options.unicodeTextInMathMode, false);
|
||||
this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
|
||||
}
|
||||
}
|
||||
|
@@ -739,7 +739,7 @@ for (let i = 0; i < letters.length; i++) {
|
||||
// but they are not actually in the font, nor are they supported by the
|
||||
// Unicode accent mechanism, so they fall back to Times font and look ugly.
|
||||
// TODO(edemaine): Fix this.
|
||||
const extraLatin = "ÇÐÞçþ";
|
||||
export const extraLatin = "ÇÐÞçþ";
|
||||
for (let i = 0; i < extraLatin.length; i++) {
|
||||
const ch = extraLatin.charAt(i);
|
||||
defineSymbol(math, main, mathord, ch, ch);
|
||||
|
Reference in New Issue
Block a user