mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-04 18:58:39 +00:00
* Support \operatorname. Resolove #145 * Fix quote mark typo * Fix test escapes * Remove poorly written tests * operatorname screenshots * Remove nits * Use documentFragment. Eliminate macro.
This commit is contained in:
@@ -372,6 +372,9 @@ groupTypes.op = function(group, options) {
|
||||
// operators, like \limsup.
|
||||
node = new mathMLTree.MathNode(
|
||||
"mi", [new mathMLTree.TextNode(group.value.body.slice(1))]);
|
||||
|
||||
// TODO(ron): Append an <mo>⁡</mo> as in \operatorname
|
||||
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.2
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@@ -329,6 +329,8 @@ defineFunction(["\\mathop"], {
|
||||
};
|
||||
});
|
||||
|
||||
import "./functions/operators";
|
||||
|
||||
// Fractions
|
||||
defineFunction([
|
||||
"\\dfrac", "\\frac", "\\tfrac",
|
||||
|
76
src/functions/operators.js
Normal file
76
src/functions/operators.js
Normal file
@@ -0,0 +1,76 @@
|
||||
// @flow
|
||||
import defineFunction, {ordargument} from "../defineFunction";
|
||||
import buildCommon from "../buildCommon";
|
||||
import mathMLTree from "../mathMLTree";
|
||||
import domTree from "../domTree";
|
||||
|
||||
import * as html from "../buildHTML";
|
||||
import * as mml from "../buildMathML";
|
||||
|
||||
// \operatorname
|
||||
// amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@
|
||||
defineFunction({
|
||||
type: "operatorname",
|
||||
names: ["\\operatorname"],
|
||||
props: {
|
||||
numArgs: 1,
|
||||
},
|
||||
handler: (context, args) => {
|
||||
const body = args[0];
|
||||
return {
|
||||
type: "operatorname",
|
||||
value: ordargument(body),
|
||||
};
|
||||
},
|
||||
|
||||
htmlBuilder: (group, options) => {
|
||||
const output = [];
|
||||
if (group.value.value.length > 0) {
|
||||
let letter = "";
|
||||
let mode = "";
|
||||
|
||||
// Consolidate Greek letter function names into symbol characters.
|
||||
const temp = html.buildExpression(group.value.value, options, true);
|
||||
|
||||
// All we want from temp are the letters. With them, we'll
|
||||
// create a text operator similar to \tan or \cos.
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
letter = temp[i].value;
|
||||
|
||||
// In the amsopn package, \newmcodes@ changes four
|
||||
// characters, *-/:’, from math operators back into text.
|
||||
// Given what is in temp, we have to address two of them.
|
||||
letter = letter.replace(/\u2212/, "-"); // minus => hyphen
|
||||
letter = letter.replace(/\u2217/, "*");
|
||||
|
||||
// Use math mode for Greek letters
|
||||
mode = (/[\u0391-\u03D7]/.test(letter) ? "math" : "text");
|
||||
output.push(buildCommon.mathsym(letter, mode));
|
||||
}
|
||||
}
|
||||
return buildCommon.makeSpan(["mop"], output, options);
|
||||
},
|
||||
|
||||
mathmlBuilder: (group, options) => {
|
||||
// The steps taken here are similar to the html version.
|
||||
let output = [];
|
||||
if (group.value.value.length > 0) {
|
||||
let temp = mml.buildExpression(group.value.value, options);
|
||||
|
||||
let word = "";
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
word += temp[i].children[0].text;
|
||||
}
|
||||
word = word.replace(/\u2212/g, "-");
|
||||
word = word.replace(/\u2217/g, "*");
|
||||
output = [new mathMLTree.TextNode(word)];
|
||||
}
|
||||
const identifier = new mathMLTree.MathNode("mi", output);
|
||||
identifier.setAttribute("mathvariant", "normal");
|
||||
|
||||
const operator = new mathMLTree.MathNode("mo",
|
||||
[mml.makeText("⁡", "text")]);
|
||||
|
||||
return new domTree.documentFragment([identifier, operator]);
|
||||
},
|
||||
});
|
BIN
test/screenshotter/images/OperatorName-chrome.png
Normal file
BIN
test/screenshotter/images/OperatorName-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
test/screenshotter/images/OperatorName-firefox.png
Normal file
BIN
test/screenshotter/images/OperatorName-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@@ -172,6 +172,11 @@ OldFont: |
|
||||
\text{\rm rm} & \text{rm} & \text{\it it} & \text{\bf bf} & \text{\sf sf} & \text{\tt tt} \\
|
||||
i\rm r\it i & \text{r\it i\rm r}
|
||||
\end{matrix}
|
||||
OperatorName: |
|
||||
\begin{matrix}
|
||||
\operatorname g (z) + 5\operatorname{g}z + \operatorname{Gam-ma}(z) \\
|
||||
\operatorname{Gam ma}(z) + \operatorname{\Gamma}(z) + \operatorname{}x
|
||||
\end{matrix}
|
||||
OpLimits: |
|
||||
{\sin_2^2 \lim_2^2 \int_2^2 \sum_2^2}
|
||||
{\displaystyle \lim_2^2 \int_2^2 \intop_2^2 \sum_2^2}
|
||||
|
Reference in New Issue
Block a user