mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 03:38:39 +00:00
Support stretchy wide elements. (#670)
This commit is contained in:
@@ -634,19 +634,99 @@ defineFunction([
|
||||
defineFunction([
|
||||
"\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve",
|
||||
"\\check", "\\hat", "\\vec", "\\dot",
|
||||
// We don't support expanding accents yet
|
||||
// "\\widetilde", "\\widehat"
|
||||
"\\widehat", "\\widetilde", "\\overrightarrow", "\\overleftarrow",
|
||||
"\\Overrightarrow", "\\overleftrightarrow", "\\overgroup",
|
||||
"\\overlinesegment", "\\overleftharpoon", "\\overrightharpoon",
|
||||
], {
|
||||
numArgs: 1,
|
||||
}, function(context, args) {
|
||||
const base = args[0];
|
||||
|
||||
const isStretchy = !utils.contains([
|
||||
"\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve",
|
||||
"\\check", "\\hat", "\\vec", "\\dot",
|
||||
], context.funcName);
|
||||
|
||||
const isShifty = !isStretchy || utils.contains([
|
||||
"\\widehat", "\\widetilde",
|
||||
], context.funcName);
|
||||
|
||||
return {
|
||||
type: "accent",
|
||||
label: context.funcName,
|
||||
isStretchy: isStretchy,
|
||||
isShifty: isShifty,
|
||||
value: ordargument(base),
|
||||
base: base,
|
||||
};
|
||||
});
|
||||
|
||||
// Horizontal stretchy braces
|
||||
defineFunction([
|
||||
"\\overbrace", "\\underbrace",
|
||||
], {
|
||||
numArgs: 1,
|
||||
}, function(context, args) {
|
||||
const base = args[0];
|
||||
return {
|
||||
type: "accent",
|
||||
accent: context.funcName,
|
||||
type: "horizBrace",
|
||||
label: context.funcName,
|
||||
isOver: /^\\over/.test(context.funcName),
|
||||
base: base,
|
||||
};
|
||||
});
|
||||
|
||||
// Stretchy accents under the body
|
||||
defineFunction([
|
||||
"\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow",
|
||||
"\\undergroup", "\\underlinesegment", "\\undertilde",
|
||||
], {
|
||||
numArgs: 1,
|
||||
}, function(context, args) {
|
||||
const body = args[0];
|
||||
return {
|
||||
type: "accentUnder",
|
||||
label: context.funcName,
|
||||
value: ordargument(body),
|
||||
body: body,
|
||||
};
|
||||
});
|
||||
|
||||
// Stretchy arrows with an optional argument
|
||||
defineFunction([
|
||||
"\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow",
|
||||
"\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow",
|
||||
"\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown",
|
||||
"\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup",
|
||||
"\\xrightleftharpoons", "\\xleftrightharpoons", "\\xLongequal",
|
||||
"\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xLongequal",
|
||||
"\\xtofrom",
|
||||
], {
|
||||
numArgs: 1,
|
||||
numOptionalArgs: 1,
|
||||
}, function(context, args) {
|
||||
const below = args[0];
|
||||
const body = args[1];
|
||||
return {
|
||||
type: "xArrow", // x for extensible
|
||||
label: context.funcName,
|
||||
body: body,
|
||||
below: below,
|
||||
};
|
||||
});
|
||||
|
||||
// enclose
|
||||
defineFunction(["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\fbox"], {
|
||||
numArgs: 1,
|
||||
}, function(context, args) {
|
||||
const body = args[0];
|
||||
return {
|
||||
type: "enclose",
|
||||
label: context.funcName,
|
||||
body: body,
|
||||
};
|
||||
});
|
||||
|
||||
// Infix generalized fractions
|
||||
defineFunction(["\\over", "\\choose", "\\atop"], {
|
||||
numArgs: 0,
|
||||
|
Reference in New Issue
Block a user