mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-17 16:58:41 +00:00
Support \cfrac (#1392)
* Support \cfrac This was an easier PR to write than #135 since KaTeX now has well established methods for pt-to-em conversions and nulldelimiter. As in #135, this does not support the LaTeX optional argument for numerator justification. It supports a `\cfrac #1 #2 ` syntax. * Added screenshotter files * fix ref to context in genfrac handler
This commit is contained in:
@@ -171,6 +171,7 @@ export type ParseNodeTypes = {
|
||||
|},
|
||||
"genfrac": {|
|
||||
type: "genfrac",
|
||||
continued: boolean,
|
||||
numer: ParseNode<*>,
|
||||
denom: ParseNode<*>,
|
||||
hasBarLine: boolean,
|
||||
|
@@ -12,7 +12,7 @@ import * as mml from "../buildMathML";
|
||||
defineFunction({
|
||||
type: "genfrac",
|
||||
names: [
|
||||
"\\dfrac", "\\frac", "\\tfrac",
|
||||
"\\cfrac", "\\dfrac", "\\frac", "\\tfrac",
|
||||
"\\dbinom", "\\binom", "\\tbinom",
|
||||
"\\\\atopfrac", // can’t be entered directly
|
||||
],
|
||||
@@ -29,6 +29,7 @@ defineFunction({
|
||||
let size = "auto";
|
||||
|
||||
switch (funcName) {
|
||||
case "\\cfrac":
|
||||
case "\\dfrac":
|
||||
case "\\frac":
|
||||
case "\\tfrac":
|
||||
@@ -49,6 +50,7 @@ defineFunction({
|
||||
}
|
||||
|
||||
switch (funcName) {
|
||||
case "\\cfrac":
|
||||
case "\\dfrac":
|
||||
case "\\dbinom":
|
||||
size = "display";
|
||||
@@ -61,6 +63,7 @@ defineFunction({
|
||||
|
||||
return new ParseNode("genfrac", {
|
||||
type: "genfrac",
|
||||
continued: funcName === "\\cfrac",
|
||||
numer: numer,
|
||||
denom: denom,
|
||||
hasBarLine: hasBarLine,
|
||||
@@ -89,6 +92,15 @@ defineFunction({
|
||||
newOptions = options.havingStyle(nstyle);
|
||||
const numerm = html.buildGroup(group.value.numer, newOptions, options);
|
||||
|
||||
if (group.value.continued) {
|
||||
// \cfrac inserts a \strut into the numerator.
|
||||
// Get \strut dimensions from TeXbook page 353.
|
||||
const hStrut = 8.5 / options.fontMetrics().ptPerEm;
|
||||
const dStrut = 3.5 / options.fontMetrics().ptPerEm;
|
||||
numerm.height = numerm.height < hStrut ? hStrut : numerm.height;
|
||||
numerm.depth = numerm.depth < dStrut ? dStrut : numerm.depth;
|
||||
}
|
||||
|
||||
newOptions = options.havingStyle(dstyle);
|
||||
const denomm = html.buildGroup(group.value.denom, newOptions, options);
|
||||
|
||||
@@ -198,7 +210,10 @@ defineFunction({
|
||||
group.value.leftDelim, delimSize, true,
|
||||
options.havingStyle(style), group.mode, ["mopen"]);
|
||||
}
|
||||
if (group.value.rightDelim == null) {
|
||||
|
||||
if (group.value.continued) {
|
||||
rightDelim = buildCommon.makeSpan([]); // zero width for \cfrac
|
||||
} else if (group.value.rightDelim == null) {
|
||||
rightDelim = html.makeNullDelimiter(options, ["mclose"]);
|
||||
} else {
|
||||
rightDelim = delimiter.customSizedDelim(
|
||||
|
Reference in New Issue
Block a user