|
|
|
import defineFunction from "../defineFunction"; |
|
import mathMLTree from "../mathMLTree"; |
|
import Style from "../Style"; |
|
import {sizingGroup} from "./sizing"; |
|
|
|
import * as mml from "../buildMathML"; |
|
|
|
const styleMap = { |
|
"display": Style.DISPLAY, |
|
"text": Style.TEXT, |
|
"script": Style.SCRIPT, |
|
"scriptscript": Style.SCRIPTSCRIPT, |
|
}; |
|
|
|
defineFunction({ |
|
type: "styling", |
|
names: [ |
|
"\\displaystyle", "\\textstyle", "\\scriptstyle", |
|
"\\scriptscriptstyle", |
|
], |
|
props: { |
|
numArgs: 0, |
|
allowedInText: true, |
|
primitive: true, |
|
}, |
|
handler({breakOnTokenText, funcName, parser}, args) { |
|
|
|
const body = parser.parseExpression(true, breakOnTokenText); |
|
|
|
|
|
|
|
|
|
const style: StyleStr = funcName.slice(1, funcName.length - 5); |
|
return { |
|
type: "styling", |
|
mode: parser.mode, |
|
|
|
|
|
style, |
|
body, |
|
}; |
|
}, |
|
htmlBuilder(group, options) { |
|
|
|
const newStyle = styleMap[group.style]; |
|
const newOptions = options.havingStyle(newStyle).withFont(''); |
|
return sizingGroup(group.body, newOptions, options); |
|
}, |
|
mathmlBuilder(group, options) { |
|
|
|
const newStyle = styleMap[group.style]; |
|
const newOptions = options.havingStyle(newStyle); |
|
|
|
const inner = mml.buildExpression(group.body, newOptions); |
|
|
|
const node = new mathMLTree.MathNode("mstyle", inner); |
|
|
|
const styleAttributes = { |
|
"display": ["0", "true"], |
|
"text": ["0", "false"], |
|
"script": ["1", "false"], |
|
"scriptscript": ["2", "false"], |
|
}; |
|
|
|
const attr = styleAttributes[group.style]; |
|
|
|
node.setAttribute("scriptlevel", attr[0]); |
|
node.setAttribute("displaystyle", attr[1]); |
|
|
|
return node; |
|
}, |
|
}); |
|
|