| import defineFunction from "../defineFunction"; |
| import {makeSpan, makeSymbol, tryCombineChars} from "../buildCommon"; |
| import {MathNode, TextNode} from "../mathMLTree"; |
| import ParseError from "../ParseError"; |
|
|
| import type {ParseNode} from "../types/nodes"; |
|
|
| defineFunction({ |
| type: "verb", |
| names: ["\\verb"], |
| numArgs: 0, |
| allowedInText: true, |
|
|
| handler(context, args, optArgs) { |
| |
| |
| |
| |
| throw new ParseError( |
| "\\verb ended by end of line instead of matching delimiter"); |
| }, |
|
|
| htmlBuilder(group, options) { |
| const text = makeVerb(group); |
| const body = []; |
| |
| const newOptions = options.havingStyle(options.style.text()); |
| for (let i = 0; i < text.length; i++) { |
| let c = text[i]; |
| if (c === '~') { |
| c = '\\textasciitilde'; |
| } |
| body.push(makeSymbol(c, "Typewriter-Regular", |
| group.mode, newOptions, ["mord", "texttt"])); |
| } |
| return makeSpan( |
| ["mord", "text"].concat(newOptions.sizingClasses(options)), |
| tryCombineChars(body), |
| newOptions, |
| ); |
| }, |
| mathmlBuilder(group, options) { |
| const text = new TextNode(makeVerb(group)); |
| const node = new MathNode("mtext", [text]); |
| node.setAttribute("mathvariant", "monospace"); |
| return node; |
| }, |
| }); |
|
|
| |
| |
| |
| |
| |
| |
| const makeVerb = (group: ParseNode<"verb">): string => |
| group.body.replace(/ /g, group.star ? '\u2423' : '\xA0'); |
|
|