mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-13 06:58:40 +00:00
Automatic mrel/mbin spacing for \boldsymbol (#1388)
* Automatic mrel/mbin spacing for \boldsymbol Fix #1154 * Add test * Add missing mode * Separate out \boldsymbol support to correct flow types * Fix ternaries thanks to @ronkok's comment * Revert package-lock.json * Add screenshot test
This commit is contained in:
@@ -30,15 +30,15 @@ const fontAliases = {
|
||||
defineFunction({
|
||||
type: "font",
|
||||
names: [
|
||||
// styles
|
||||
"\\mathrm", "\\mathit", "\\mathbf", "\\boldsymbol",
|
||||
// styles, except \boldsymbol defined below
|
||||
"\\mathrm", "\\mathit", "\\mathbf",
|
||||
|
||||
// families
|
||||
"\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf",
|
||||
"\\mathtt",
|
||||
|
||||
// aliases
|
||||
"\\Bbb", "\\bold", "\\frak", "\\bm",
|
||||
// aliases, except \bm defined below
|
||||
"\\Bbb", "\\bold", "\\frak",
|
||||
],
|
||||
props: {
|
||||
numArgs: 1,
|
||||
@@ -53,13 +53,44 @@ defineFunction({
|
||||
return new ParseNode("font", {
|
||||
type: "font",
|
||||
font: func.slice(1),
|
||||
body: body,
|
||||
body,
|
||||
}, parser.mode);
|
||||
},
|
||||
htmlBuilder,
|
||||
mathmlBuilder,
|
||||
});
|
||||
|
||||
defineFunction({
|
||||
type: "mclass",
|
||||
names: ["\\boldsymbol", "\\bm"],
|
||||
props: {
|
||||
numArgs: 1,
|
||||
greediness: 2,
|
||||
},
|
||||
handler: ({parser}, args) => {
|
||||
const body = args[0];
|
||||
// amsbsy.sty's \boldsymbol inherits the argument's bin|rel|ord status
|
||||
// (similar to \stackrel in functions/mclass.js)
|
||||
let mclass = "mord";
|
||||
const atomType = (body.type === "ordgroup" && body.value.length ?
|
||||
body.value[0].type : body.type);
|
||||
if (/^(bin|rel)$/.test(atomType)) {
|
||||
mclass = "m" + atomType;
|
||||
}
|
||||
return new ParseNode("mclass", {
|
||||
type: "mclass",
|
||||
mclass,
|
||||
value: [
|
||||
new ParseNode("font", {
|
||||
type: "font",
|
||||
font: "boldsymbol",
|
||||
body,
|
||||
}, parser.mode),
|
||||
],
|
||||
}, parser.mode);
|
||||
},
|
||||
});
|
||||
|
||||
const oldFontFuncsMap = {
|
||||
"\\rm": "mathrm",
|
||||
"\\sf": "mathsf",
|
||||
|
@@ -57,12 +57,8 @@ defineFunction({
|
||||
// LaTeX applies \binrel spacing to \overset and \underset. \binrel
|
||||
// spacing varies with (bin|rel|ord) of the atom in the argument.
|
||||
// We'll do the same.
|
||||
let atomType = "";
|
||||
if (baseArg.type === "ordgroup") {
|
||||
atomType = baseArg.value[0].type;
|
||||
} else {
|
||||
atomType = baseArg.type;
|
||||
}
|
||||
const atomType = (baseArg.type === "ordgroup" &&
|
||||
baseArg.value.length ? baseArg.value[0].type : baseArg.type);
|
||||
if (/^(bin|rel)$/.test(atomType)) {
|
||||
mclass = "m" + atomType;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user