Unicode characters in math render in text mode (#2040)

* Unicode characters in math render in text mode

Improve #2031 by rendering all supported Unicode text characters (via
supportedCodepoints) in text mode, mimicking wrapping them in `\text`,
thereby using metrics of letter M as usual.

* Add tests

* Improve documentation

* Implement review comments
This commit is contained in:
Erik Demaine
2019-08-08 20:33:09 -04:00
committed by Kevin Barabash
parent 3b80e0123b
commit 3b6ed48f5b
4 changed files with 44 additions and 16 deletions

View File

@@ -971,9 +971,16 @@ export default class Parser {
nucleus);
}
}
// All nonmathematical Unicode characters are rendered as if they
// are in text mode (wrapped in \text) because that's what it
// takes to render them in LaTeX. Setting `mode: this.mode` is
// another natural choice (the user requested math mode), but
// this makes it more difficult for getCharacterMetrics() to
// distinguish Unicode characters without metrics and those for
// which we want to simulate the letter M.
symbol = {
type: "textord",
mode: this.mode,
mode: "text",
loc: SourceLocation.range(nucleus),
text,
};

View File

@@ -80,9 +80,8 @@ const makeSymbol = function(
metrics.width, classes);
} else {
// TODO(emily): Figure out a good way to only print this in development
typeof console !== "undefined" && console.warn(
"No character metrics for '" + value + "' in style '" +
fontName + "'");
typeof console !== "undefined" && console.warn("No character metrics " +
`for '${value}' in style '${fontName}' and mode '${mode}'`);
symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
}