| Server IP : 121.121.20.254 / Your IP : 216.73.216.42 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Program Files/Microsoft VS Code/ce099c1ed2/resources/app/node_modules/katex/src/functions/ |
Upload File : |
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import ParseError from "../ParseError";
import type {ParseNode} from "../parseNode";
defineFunction({
type: "verb",
names: ["\\verb"],
props: {
numArgs: 0,
allowedInText: true,
},
handler(context, args, optArgs) {
// \verb and \verb* are dealt with directly in Parser.js.
// If we end up here, it's because of a failure to match the two delimiters
// in the regex in Lexer.js. LaTeX raises the following error when \verb is
// terminated by end of line (or file).
throw new ParseError(
"\\verb ended by end of line instead of matching delimiter");
},
htmlBuilder(group, options) {
const text = makeVerb(group);
const body = [];
// \verb enters text mode and therefore is sized like \textstyle
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(buildCommon.makeSymbol(c, "Typewriter-Regular",
group.mode, newOptions, ["mord", "texttt"]));
}
return buildCommon.makeSpan(
["mord", "text"].concat(newOptions.sizingClasses(options)),
buildCommon.tryCombineChars(body),
newOptions,
);
},
mathmlBuilder(group, options) {
const text = new mathMLTree.TextNode(makeVerb(group));
const node = new mathMLTree.MathNode("mtext", [text]);
node.setAttribute("mathvariant", "monospace");
return node;
},
});
/**
* Converts verb group into body string.
*
* \verb* replaces each space with an open box \u2423
* \verb replaces each space with a no-break space \xA0
*/
const makeVerb = (group: ParseNode<"verb">): string =>
group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');