|
|
|
|
|
import defineFunction from "../defineFunction"; |
|
import buildCommon from "../buildCommon"; |
|
import mathMLTree from "../mathMLTree"; |
|
import {assertNodeType} from "../parseNode"; |
|
|
|
import * as html from "../buildHTML"; |
|
import * as mml from "../buildMathML"; |
|
|
|
defineFunction({ |
|
type: "smash", |
|
names: ["\\smash"], |
|
props: { |
|
numArgs: 1, |
|
numOptionalArgs: 1, |
|
allowedInText: true, |
|
}, |
|
handler: ({parser}, args, optArgs) => { |
|
let smashHeight = false; |
|
let smashDepth = false; |
|
const tbArg = optArgs[0] && assertNodeType(optArgs[0], "ordgroup"); |
|
if (tbArg) { |
|
|
|
|
|
|
|
let letter = ""; |
|
for (let i = 0; i < tbArg.body.length; ++i) { |
|
const node = tbArg.body[i]; |
|
|
|
letter = node.text; |
|
if (letter === "t") { |
|
smashHeight = true; |
|
} else if (letter === "b") { |
|
smashDepth = true; |
|
} else { |
|
smashHeight = false; |
|
smashDepth = false; |
|
break; |
|
} |
|
} |
|
} else { |
|
smashHeight = true; |
|
smashDepth = true; |
|
} |
|
|
|
const body = args[0]; |
|
return { |
|
type: "smash", |
|
mode: parser.mode, |
|
body, |
|
smashHeight, |
|
smashDepth, |
|
}; |
|
}, |
|
htmlBuilder: (group, options) => { |
|
const node = buildCommon.makeSpan( |
|
[], [html.buildGroup(group.body, options)]); |
|
|
|
if (!group.smashHeight && !group.smashDepth) { |
|
return node; |
|
} |
|
|
|
if (group.smashHeight) { |
|
node.height = 0; |
|
|
|
if (node.children) { |
|
for (let i = 0; i < node.children.length; i++) { |
|
node.children[i].height = 0; |
|
} |
|
} |
|
} |
|
|
|
if (group.smashDepth) { |
|
node.depth = 0; |
|
if (node.children) { |
|
for (let i = 0; i < node.children.length; i++) { |
|
node.children[i].depth = 0; |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
const smashedNode = buildCommon.makeVList({ |
|
positionType: "firstBaseline", |
|
children: [{type: "elem", elem: node}], |
|
}, options); |
|
|
|
|
|
return buildCommon.makeSpan(["mord"], [smashedNode], options); |
|
}, |
|
mathmlBuilder: (group, options) => { |
|
const node = new mathMLTree.MathNode( |
|
"mpadded", [mml.buildGroup(group.body, options)]); |
|
|
|
if (group.smashHeight) { |
|
node.setAttribute("height", "0px"); |
|
} |
|
|
|
if (group.smashDepth) { |
|
node.setAttribute("depth", "0px"); |
|
} |
|
|
|
return node; |
|
}, |
|
}); |
|
|