Add support for Latin-1, Cyrillic, and CJK characters inside \text{} (#508)

Summary:
This diff provides support for Latin-1, Cyrillic, and CJK characters
inside \text{} groups.  For Latin-1 and Cyrillic characters we use
glyph metrics from a glyph from Basic Latin that has roughly the same
bounding box.  We use the metrics for a capital 'M' to approximate the
full-width CJK characters.  Half-width characters are not supported yet.

Test Plan:
- make test
- make screenshots

Reviewers: emily
This commit is contained in:
Kevin Barabash
2016-08-01 17:51:40 -07:00
committed by GitHub
parent 92bbbffbc8
commit ec62ec39d8
15 changed files with 348 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -114,6 +114,7 @@ Symbols1: |
\maltese\degree\pounds\$
\text{\maltese\degree}
Text: \frac{a}{b}\text{c~ {ab} \ e}+fg
Unicode: \begin{matrix}\text{ÀàÇçÉéÏïÖöÛû} \\ \text{БГДЖЗЙЛФЦШЫЮЯ} \\ \text{여보세요} \\ \text{私はバナナです} \end{matrix}
UnsupportedCmds:
tex: \err\,\frac\fracerr3\,2^\superr_\suberr\,\sqrt\sqrterr
noThrow: 1

View File

@@ -11,6 +11,20 @@
body {
font-family: "DejaVu Serif",serif;
}
@font-face {
font-family: "Mincho";
src: url("unicode-fonts/mincho/font_1_honokamin.ttf") format("truetype");
}
@font-face {
font-family: "Batang";
src: url("unicode-fonts/batang/batang.ttf") format("truetype");
}
.katex .cjk_fallback {
font-family: "Mincho",serif;
}
.katex .hangul_fallback {
font-family: "Batang",serif;
}
</style>
</head>
<body>

103
test/unicode-spec.js Normal file
View File

@@ -0,0 +1,103 @@
/* eslint max-len:0 */
/* global beforeEach: false */
/* global jasmine: false */
/* global expect: false */
/* global it: false */
/* global describe: false */
var ParseError = require("../src/ParseError");
var parseTree = require("../src/parseTree");
var Settings = require("../src/Settings");
var defaultSettings = new Settings({});
var parseAndSetResult = function(expr, result, settings) {
try {
return parseTree(expr, settings || defaultSettings);
} catch (e) {
result.pass = false;
if (e instanceof ParseError) {
result.message = "'" + expr + "' failed " +
"parsing with error: " + e.message;
} else {
result.message = "'" + expr + "' failed " +
"parsing with unknown error: " + e.message;
}
}
};
describe("unicode", function() {
beforeEach(function() {
jasmine.addMatchers({
toParse: function() {
return {
compare: function(actual, settings) {
var usedSettings = settings ? settings : defaultSettings;
var result = {
pass: true,
message: "'" + actual + "' succeeded parsing",
};
parseAndSetResult(actual, result, usedSettings);
return result;
},
};
},
toNotParse: function() {
return {
compare: function(actual, settings) {
var usedSettings = settings ? settings : defaultSettings;
var result = {
pass: false,
message: "Expected '" + actual + "' to fail " +
"parsing, but it succeeded",
};
try {
parseTree(actual, usedSettings);
} catch (e) {
if (e instanceof ParseError) {
result.pass = true;
result.message = "'" + actual + "' correctly " +
"didn't parse with error: " + e.message;
} else {
result.message = "'" + actual + "' failed " +
"parsing with unknown error: " + e.message;
}
}
return result;
},
};
},
});
});
it("should parse Latin-1 inside \\text{}", function() {
expect('\\text{ÀàÇçÉéÏïÖöÛû}').toParse();
});
it("should not parse Latin-1 outside \\text{}", function() {
expect('ÀàÇçÉéÏïÖöÛû').toNotParse();
});
it("should parse Cyrillic inside \\text{}", function() {
expect('\\text{БГДЖЗЙЛФЦШЫЮЯ}').toParse();
});
it("should not parse Cyrillic outside \\text{}", function() {
expect('БГДЖЗЙЛФЦШЫЮЯ').toNotParse();
});
it("should parse CJK inside \\text{}", function() {
expect('\\text{私はバナナです}').toParse();
expect('\\text{여보세요}').toParse();
});
it("should not parse CJK outside \\text{}", function() {
expect('私はバナナです。').toNotParse();
expect('여보세요').toNotParse();
});
});