| |
| import defineFunction from "../defineFunction"; |
| import {makeSpan, makeVList} from "../buildCommon"; |
| import {MathNode} from "../mathMLTree"; |
| import {assertNodeType, assertSymbolNodeType} from "../parseNode"; |
|
|
| import * as html from "../buildHTML"; |
| import * as mml from "../buildMathML"; |
|
|
| defineFunction({ |
| type: "smash", |
| names: ["\\smash"], |
| 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 = assertSymbolNodeType(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 = makeSpan( |
| [], [html.buildGroup(group.body, options)]); |
|
|
| if (!group.smashHeight && !group.smashDepth) { |
| return node; |
| } |
|
|
| if (group.smashHeight) { |
| node.height = 0; |
| } |
|
|
| if (group.smashDepth) { |
| node.depth = 0; |
| } |
|
|
| if (group.smashHeight && group.smashDepth) { |
| |
| return makeSpan(["mord", "smash"], [node], options); |
| } |
|
|
| |
| |
| if (node.children) { |
| for (let i = 0; i < node.children.length; i++) { |
| if (group.smashHeight) { |
| node.children[i].height = 0; |
| } |
| if (group.smashDepth) { |
| node.children[i].depth = 0; |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
|
|
| const smashedNode = makeVList({ |
| positionType: "firstBaseline", |
| children: [{type: "elem", elem: node}], |
| }, options); |
|
|
| |
| return makeSpan(["mord"], [smashedNode], options); |
| }, |
| mathmlBuilder: (group, options) => { |
| const node = new MathNode( |
| "mpadded", [mml.buildGroup(group.body, options)]); |
|
|
| if (group.smashHeight) { |
| node.setAttribute("height", "0px"); |
| } |
|
|
| if (group.smashDepth) { |
| node.setAttribute("depth", "0px"); |
| } |
|
|
| return node; |
| }, |
| }); |
|
|