katex 0.15.5 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/contrib/copy-tex/README.md +9 -19
- package/contrib/copy-tex/copy-tex.js +39 -12
- package/contrib/copy-tex/katex2tex.js +16 -7
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/dist/README.md +3 -3
- package/dist/contrib/copy-tex.js +38 -24
- package/dist/contrib/copy-tex.min.js +1 -1
- package/dist/contrib/copy-tex.mjs +35 -16
- package/dist/katex.css +1 -1
- package/dist/katex.js +174 -23
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +171 -23
- package/package.json +3 -3
- package/src/MacroExpander.js +3 -1
- package/src/defineMacro.js +7 -0
- package/src/delimiter.js +68 -25
- package/src/macros.js +52 -0
- package/src/svgGeometry.js +56 -0
- package/contrib/copy-tex/copy-tex.css +0 -10
- package/contrib/copy-tex/copy-tex.webpack.js +0 -6
- package/dist/contrib/copy-tex.css +0 -13
- package/dist/contrib/copy-tex.min.css +0 -1
package/dist/katex.mjs
CHANGED
|
@@ -941,6 +941,43 @@ var path = {
|
|
|
941
941
|
shortbaraboveleftharpoon: "M7,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17c2,0.7,5,1,9,\n1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21c-32,-87.3,-82.7,-157.7,\n-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z\nM93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z",
|
|
942
942
|
shortrightharpoonabovebar: "M53,241l0,40c398570,0,399437,0,399437,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6\nc-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z\nM500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z"
|
|
943
943
|
};
|
|
944
|
+
var tallDelim = function tallDelim(label, midHeight) {
|
|
945
|
+
switch (label) {
|
|
946
|
+
case "lbrack":
|
|
947
|
+
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v1759 h347 v-84\nH403z M403 1759 V0 H319 V1759 v" + midHeight + " v1759 h84z";
|
|
948
|
+
|
|
949
|
+
case "rbrack":
|
|
950
|
+
return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v1759 H0 v84 H347z\nM347 1759 V0 H263 V1759 v" + midHeight + " v1759 h84z";
|
|
951
|
+
|
|
952
|
+
case "vert":
|
|
953
|
+
return "M145 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z";
|
|
954
|
+
|
|
955
|
+
case "doublevert":
|
|
956
|
+
return "M145 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z\nM367 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M410 15 H367 v585 v" + midHeight + " v585 h43z";
|
|
957
|
+
|
|
958
|
+
case "lfloor":
|
|
959
|
+
return "M319 602 V0 H403 V602 v" + midHeight + " v1715 h263 v84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
|
|
960
|
+
|
|
961
|
+
case "rfloor":
|
|
962
|
+
return "M319 602 V0 H403 V602 v" + midHeight + " v1799 H0 v-84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
|
|
963
|
+
|
|
964
|
+
case "lceil":
|
|
965
|
+
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v602 h84z\nM403 1759 V0 H319 V1759 v" + midHeight + " v602 h84z";
|
|
966
|
+
|
|
967
|
+
case "rceil":
|
|
968
|
+
return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v602 h84z\nM347 1759 V0 h-84 V1759 v" + midHeight + " v602 h84z";
|
|
969
|
+
|
|
970
|
+
case "lparen":
|
|
971
|
+
return "M863,9c0,-2,-2,-5,-6,-9c0,0,-17,0,-17,0c-12.7,0,-19.3,0.3,-20,1\nc-5.3,5.3,-10.3,11,-15,17c-242.7,294.7,-395.3,682,-458,1162c-21.3,163.3,-33.3,349,\n-36,557 l0," + (midHeight + 84) + "c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,\n949.7,470,1265c4.7,6,9.7,11.7,15,17c0.7,0.7,7,1,19,1c0,0,18,0,18,0c4,-4,6,-7,6,-9\nc0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,\n-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189\nl0,-" + (midHeight + 92) + "c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,\n-210,155.3,-396.3,270,-559c6.7,-9.3,10,-15.3,10,-18z";
|
|
972
|
+
|
|
973
|
+
case "rparen":
|
|
974
|
+
return "M76,0c-16.7,0,-25,3,-25,9c0,2,2,6.3,6,13c21.3,28.7,42.3,60.3,\n63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5\nc11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0," + (midHeight + 9) + "\nc-3,4,-3.3,16.7,-3.3,38c0,162,-5.7,313.7,-17,455c-18.7,248,-55.8,469.3,-111.5,664\nc-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6,11\nc0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17\nc242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558\nl0,-" + (midHeight + 144) + "c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,\n-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z";
|
|
975
|
+
|
|
976
|
+
default:
|
|
977
|
+
// We should not ever get here.
|
|
978
|
+
throw new Error("Unknown stretchy delimiter.");
|
|
979
|
+
}
|
|
980
|
+
};
|
|
944
981
|
|
|
945
982
|
/**
|
|
946
983
|
* This node represents a document fragment, which contains elements, but when
|
|
@@ -8762,6 +8799,8 @@ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, opt
|
|
|
8762
8799
|
var middle;
|
|
8763
8800
|
var repeat;
|
|
8764
8801
|
var bottom;
|
|
8802
|
+
var svgLabel = "";
|
|
8803
|
+
var viewBoxWidth = 0;
|
|
8765
8804
|
top = repeat = bottom = delim;
|
|
8766
8805
|
middle = null; // Also keep track of what font the delimiters are in
|
|
8767
8806
|
|
|
@@ -8787,44 +8826,64 @@ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, opt
|
|
|
8787
8826
|
bottom = "\\Downarrow";
|
|
8788
8827
|
} else if (utils.contains(verts, delim)) {
|
|
8789
8828
|
repeat = "\u2223";
|
|
8829
|
+
svgLabel = "vert";
|
|
8830
|
+
viewBoxWidth = 333;
|
|
8790
8831
|
} else if (utils.contains(doubleVerts, delim)) {
|
|
8791
8832
|
repeat = "\u2225";
|
|
8833
|
+
svgLabel = "doublevert";
|
|
8834
|
+
viewBoxWidth = 556;
|
|
8792
8835
|
} else if (delim === "[" || delim === "\\lbrack") {
|
|
8793
8836
|
top = "\u23a1";
|
|
8794
8837
|
repeat = "\u23a2";
|
|
8795
8838
|
bottom = "\u23a3";
|
|
8796
8839
|
font = "Size4-Regular";
|
|
8840
|
+
svgLabel = "lbrack";
|
|
8841
|
+
viewBoxWidth = 667;
|
|
8797
8842
|
} else if (delim === "]" || delim === "\\rbrack") {
|
|
8798
8843
|
top = "\u23a4";
|
|
8799
8844
|
repeat = "\u23a5";
|
|
8800
8845
|
bottom = "\u23a6";
|
|
8801
8846
|
font = "Size4-Regular";
|
|
8847
|
+
svgLabel = "rbrack";
|
|
8848
|
+
viewBoxWidth = 667;
|
|
8802
8849
|
} else if (delim === "\\lfloor" || delim === "\u230a") {
|
|
8803
8850
|
repeat = top = "\u23a2";
|
|
8804
8851
|
bottom = "\u23a3";
|
|
8805
8852
|
font = "Size4-Regular";
|
|
8853
|
+
svgLabel = "lfloor";
|
|
8854
|
+
viewBoxWidth = 667;
|
|
8806
8855
|
} else if (delim === "\\lceil" || delim === "\u2308") {
|
|
8807
8856
|
top = "\u23a1";
|
|
8808
8857
|
repeat = bottom = "\u23a2";
|
|
8809
8858
|
font = "Size4-Regular";
|
|
8859
|
+
svgLabel = "lceil";
|
|
8860
|
+
viewBoxWidth = 667;
|
|
8810
8861
|
} else if (delim === "\\rfloor" || delim === "\u230b") {
|
|
8811
8862
|
repeat = top = "\u23a5";
|
|
8812
8863
|
bottom = "\u23a6";
|
|
8813
8864
|
font = "Size4-Regular";
|
|
8865
|
+
svgLabel = "rfloor";
|
|
8866
|
+
viewBoxWidth = 667;
|
|
8814
8867
|
} else if (delim === "\\rceil" || delim === "\u2309") {
|
|
8815
8868
|
top = "\u23a4";
|
|
8816
8869
|
repeat = bottom = "\u23a5";
|
|
8817
8870
|
font = "Size4-Regular";
|
|
8871
|
+
svgLabel = "rceil";
|
|
8872
|
+
viewBoxWidth = 667;
|
|
8818
8873
|
} else if (delim === "(" || delim === "\\lparen") {
|
|
8819
8874
|
top = "\u239b";
|
|
8820
8875
|
repeat = "\u239c";
|
|
8821
8876
|
bottom = "\u239d";
|
|
8822
8877
|
font = "Size4-Regular";
|
|
8878
|
+
svgLabel = "lparen";
|
|
8879
|
+
viewBoxWidth = 875;
|
|
8823
8880
|
} else if (delim === ")" || delim === "\\rparen") {
|
|
8824
8881
|
top = "\u239e";
|
|
8825
8882
|
repeat = "\u239f";
|
|
8826
8883
|
bottom = "\u23a0";
|
|
8827
8884
|
font = "Size4-Regular";
|
|
8885
|
+
svgLabel = "rparen";
|
|
8886
|
+
viewBoxWidth = 875;
|
|
8828
8887
|
} else if (delim === "\\{" || delim === "\\lbrace") {
|
|
8829
8888
|
top = "\u23a7";
|
|
8830
8889
|
middle = "\u23a8";
|
|
@@ -8896,33 +8955,60 @@ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, opt
|
|
|
8896
8955
|
var depth = realHeightTotal / 2 - axisHeight; // Now, we start building the pieces that will go into the vlist
|
|
8897
8956
|
// Keep a list of the pieces of the stacked delimiter
|
|
8898
8957
|
|
|
8899
|
-
var stack = [];
|
|
8958
|
+
var stack = [];
|
|
8959
|
+
|
|
8960
|
+
if (svgLabel.length > 0) {
|
|
8961
|
+
// Instead of stacking glyphs, create a single SVG.
|
|
8962
|
+
// This evades browser problems with imprecise positioning of spans.
|
|
8963
|
+
var midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
|
|
8964
|
+
var viewBoxHeight = Math.round(realHeightTotal * 1000);
|
|
8965
|
+
var pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
|
|
8966
|
+
var path = new PathNode(svgLabel, pathStr);
|
|
8967
|
+
var width = (viewBoxWidth / 1000).toFixed(3) + "em";
|
|
8968
|
+
var height = (viewBoxHeight / 1000).toFixed(3) + "em";
|
|
8969
|
+
var svg = new SvgNode([path], {
|
|
8970
|
+
"width": width,
|
|
8971
|
+
"height": height,
|
|
8972
|
+
"viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight
|
|
8973
|
+
});
|
|
8974
|
+
var wrapper = buildCommon.makeSvgSpan([], [svg], options);
|
|
8975
|
+
wrapper.height = viewBoxHeight / 1000;
|
|
8976
|
+
wrapper.style.width = width;
|
|
8977
|
+
wrapper.style.height = height;
|
|
8978
|
+
stack.push({
|
|
8979
|
+
type: "elem",
|
|
8980
|
+
elem: wrapper
|
|
8981
|
+
});
|
|
8982
|
+
} else {
|
|
8983
|
+
// Stack glyphs
|
|
8984
|
+
// Start by adding the bottom symbol
|
|
8985
|
+
stack.push(makeGlyphSpan(bottom, font, mode));
|
|
8986
|
+
stack.push(lap); // overlap
|
|
8987
|
+
|
|
8988
|
+
if (middle === null) {
|
|
8989
|
+
// The middle section will be an SVG. Make it an extra 0.016em tall.
|
|
8990
|
+
// We'll overlap by 0.008em at top and bottom.
|
|
8991
|
+
var innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal + 2 * lapInEms;
|
|
8992
|
+
stack.push(makeInner(repeat, innerHeight, options));
|
|
8993
|
+
} else {
|
|
8994
|
+
// When there is a middle bit, we need the middle part and two repeated
|
|
8995
|
+
// sections
|
|
8996
|
+
var _innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
|
|
8900
8997
|
|
|
8901
|
-
|
|
8902
|
-
stack.push(lap); // overlap
|
|
8998
|
+
stack.push(makeInner(repeat, _innerHeight, options)); // Now insert the middle of the brace.
|
|
8903
8999
|
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
} else {
|
|
8910
|
-
// When there is a middle bit, we need the middle part and two repeated
|
|
8911
|
-
// sections
|
|
8912
|
-
var _innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
|
|
9000
|
+
stack.push(lap);
|
|
9001
|
+
stack.push(makeGlyphSpan(middle, font, mode));
|
|
9002
|
+
stack.push(lap);
|
|
9003
|
+
stack.push(makeInner(repeat, _innerHeight, options));
|
|
9004
|
+
} // Add the top symbol
|
|
8913
9005
|
|
|
8914
|
-
stack.push(makeInner(repeat, _innerHeight, options)); // Now insert the middle of the brace.
|
|
8915
9006
|
|
|
8916
9007
|
stack.push(lap);
|
|
8917
|
-
stack.push(makeGlyphSpan(
|
|
8918
|
-
|
|
8919
|
-
stack.push(makeInner(repeat, _innerHeight, options));
|
|
8920
|
-
} // Add the top symbol
|
|
9008
|
+
stack.push(makeGlyphSpan(top, font, mode));
|
|
9009
|
+
} // Finally, build the vlist
|
|
8921
9010
|
|
|
8922
9011
|
|
|
8923
|
-
stack.push(lap);
|
|
8924
|
-
stack.push(makeGlyphSpan(top, font, mode)); // Finally, build the vlist
|
|
8925
|
-
|
|
8926
9012
|
var newOptions = options.havingBaseStyle(Style$1.TEXT);
|
|
8927
9013
|
var inner = buildCommon.makeVList({
|
|
8928
9014
|
positionType: "bottom",
|
|
@@ -15789,7 +15875,67 @@ defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
|
|
|
15789
15875
|
defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
|
|
15790
15876
|
defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
|
|
15791
15877
|
defineMacro("\\Bra", "\\left\\langle#1\\right|");
|
|
15792
|
-
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
|
|
15878
|
+
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
|
|
15879
|
+
|
|
15880
|
+
var braketHelper = one => context => {
|
|
15881
|
+
var left = context.consumeArg().tokens;
|
|
15882
|
+
var middle = context.consumeArg().tokens;
|
|
15883
|
+
var middleDouble = context.consumeArg().tokens;
|
|
15884
|
+
var right = context.consumeArg().tokens;
|
|
15885
|
+
var oldMiddle = context.macros.get("|");
|
|
15886
|
+
var oldMiddleDouble = context.macros.get("\\|");
|
|
15887
|
+
context.macros.beginGroup();
|
|
15888
|
+
|
|
15889
|
+
var midMacro = double => context => {
|
|
15890
|
+
if (one) {
|
|
15891
|
+
// Only modify the first instance of | or \|
|
|
15892
|
+
context.macros.set("|", oldMiddle);
|
|
15893
|
+
|
|
15894
|
+
if (middleDouble.length) {
|
|
15895
|
+
context.macros.set("\\|", oldMiddleDouble);
|
|
15896
|
+
}
|
|
15897
|
+
}
|
|
15898
|
+
|
|
15899
|
+
var doubled = double;
|
|
15900
|
+
|
|
15901
|
+
if (!double && middleDouble.length) {
|
|
15902
|
+
// Mimic \@ifnextchar
|
|
15903
|
+
var nextToken = context.future();
|
|
15904
|
+
|
|
15905
|
+
if (nextToken.text === "|") {
|
|
15906
|
+
context.popToken();
|
|
15907
|
+
doubled = true;
|
|
15908
|
+
}
|
|
15909
|
+
}
|
|
15910
|
+
|
|
15911
|
+
return {
|
|
15912
|
+
tokens: doubled ? middleDouble : middle,
|
|
15913
|
+
numArgs: 0
|
|
15914
|
+
};
|
|
15915
|
+
};
|
|
15916
|
+
|
|
15917
|
+
context.macros.set("|", midMacro(false));
|
|
15918
|
+
|
|
15919
|
+
if (middleDouble.length) {
|
|
15920
|
+
context.macros.set("\\|", midMacro(true));
|
|
15921
|
+
}
|
|
15922
|
+
|
|
15923
|
+
var arg = context.consumeArg().tokens;
|
|
15924
|
+
var expanded = context.expandTokens([...right, ...arg, ...left // reversed
|
|
15925
|
+
]);
|
|
15926
|
+
context.macros.endGroup();
|
|
15927
|
+
return {
|
|
15928
|
+
tokens: expanded.reverse(),
|
|
15929
|
+
numArgs: 0
|
|
15930
|
+
};
|
|
15931
|
+
};
|
|
15932
|
+
|
|
15933
|
+
defineMacro("\\bra@ket", braketHelper(false));
|
|
15934
|
+
defineMacro("\\bra@set", braketHelper(true));
|
|
15935
|
+
defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" + "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
|
|
15936
|
+
defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" + "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
|
|
15937
|
+
defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}"); // has no support for special || or \|
|
|
15938
|
+
//////////////////////////////////////////////////////////////////////
|
|
15793
15939
|
// actuarialangle.dtx
|
|
15794
15940
|
|
|
15795
15941
|
defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
|
|
@@ -16245,7 +16391,9 @@ class MacroExpander {
|
|
|
16245
16391
|
return this.macros.has(name) ? this.expandTokens([new Token(name)]) : undefined;
|
|
16246
16392
|
}
|
|
16247
16393
|
/**
|
|
16248
|
-
* Fully expand the given token stream and return the resulting list of
|
|
16394
|
+
* Fully expand the given token stream and return the resulting list of
|
|
16395
|
+
* tokens. Note that the input tokens are in reverse order, but the
|
|
16396
|
+
* output tokens are in forward order.
|
|
16249
16397
|
*/
|
|
16250
16398
|
|
|
16251
16399
|
|
|
@@ -18106,7 +18254,7 @@ var katex = {
|
|
|
18106
18254
|
/**
|
|
18107
18255
|
* Current KaTeX version
|
|
18108
18256
|
*/
|
|
18109
|
-
version: "0.
|
|
18257
|
+
version: "0.16.1",
|
|
18110
18258
|
|
|
18111
18259
|
/**
|
|
18112
18260
|
* Renders the given LaTeX into an HTML+MathML combination, and adds
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "katex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Fast math typesetting for the web.",
|
|
5
5
|
"main": "dist/katex.js",
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dist/"
|
|
48
48
|
],
|
|
49
49
|
"license": "MIT",
|
|
50
|
-
"packageManager": "yarn@3.2.
|
|
50
|
+
"packageManager": "yarn@3.2.2",
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/core": "^7.10.4",
|
|
53
53
|
"@babel/eslint-parser": "^7.15.0",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"test": "yarn test:lint && yarn test:flow && yarn test:jest",
|
|
128
128
|
"test:lint": "yarn test:lint:js && yarn test:lint:css",
|
|
129
129
|
"test:lint:js": "eslint .",
|
|
130
|
-
"test:lint:css": "stylelint src/katex.less static/main.css
|
|
130
|
+
"test:lint:css": "stylelint src/katex.less static/main.css website/static/**/*.css",
|
|
131
131
|
"test:flow": "flow",
|
|
132
132
|
"test:jest": "jest",
|
|
133
133
|
"test:jest:watch": "jest --watch",
|
package/src/MacroExpander.js
CHANGED
|
@@ -356,7 +356,9 @@ export default class MacroExpander implements MacroContextInterface {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* Fully expand the given token stream and return the resulting list of
|
|
359
|
+
* Fully expand the given token stream and return the resulting list of
|
|
360
|
+
* tokens. Note that the input tokens are in reverse order, but the
|
|
361
|
+
* output tokens are in forward order.
|
|
360
362
|
*/
|
|
361
363
|
expandTokens(tokens: Token[]): Token[] {
|
|
362
364
|
const output = [];
|
package/src/defineMacro.js
CHANGED
|
@@ -61,6 +61,13 @@ export interface MacroContextInterface {
|
|
|
61
61
|
*/
|
|
62
62
|
expandMacroAsText(name: string): string | void;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Fully expand the given token stream and return the resulting list of
|
|
66
|
+
* tokens. Note that the input tokens are in reverse order, but the
|
|
67
|
+
* output tokens are in forward order.
|
|
68
|
+
*/
|
|
69
|
+
expandTokens(tokens: Token[]): Token[];
|
|
70
|
+
|
|
64
71
|
/**
|
|
65
72
|
* Consume an argument from the token stream, and return the resulting array
|
|
66
73
|
* of tokens and start/end token.
|
package/src/delimiter.js
CHANGED
|
@@ -25,7 +25,7 @@ import ParseError from "./ParseError";
|
|
|
25
25
|
import Style from "./Style";
|
|
26
26
|
|
|
27
27
|
import {PathNode, SvgNode, SymbolNode} from "./domTree";
|
|
28
|
-
import {sqrtPath, innerPath} from "./svgGeometry";
|
|
28
|
+
import {sqrtPath, innerPath, tallDelim} from "./svgGeometry";
|
|
29
29
|
import buildCommon from "./buildCommon";
|
|
30
30
|
import {getCharacterMetrics} from "./fontMetrics";
|
|
31
31
|
import symbols from "./symbols";
|
|
@@ -229,6 +229,8 @@ const makeStackedDelim = function(
|
|
|
229
229
|
let middle;
|
|
230
230
|
let repeat;
|
|
231
231
|
let bottom;
|
|
232
|
+
let svgLabel = "";
|
|
233
|
+
let viewBoxWidth = 0;
|
|
232
234
|
top = repeat = bottom = delim;
|
|
233
235
|
middle = null;
|
|
234
236
|
// Also keep track of what font the delimiters are in
|
|
@@ -255,44 +257,64 @@ const makeStackedDelim = function(
|
|
|
255
257
|
bottom = "\\Downarrow";
|
|
256
258
|
} else if (utils.contains(verts, delim)) {
|
|
257
259
|
repeat = "\u2223";
|
|
260
|
+
svgLabel = "vert";
|
|
261
|
+
viewBoxWidth = 333;
|
|
258
262
|
} else if (utils.contains(doubleVerts, delim)) {
|
|
259
263
|
repeat = "\u2225";
|
|
264
|
+
svgLabel = "doublevert";
|
|
265
|
+
viewBoxWidth = 556;
|
|
260
266
|
} else if (delim === "[" || delim === "\\lbrack") {
|
|
261
267
|
top = "\u23a1";
|
|
262
268
|
repeat = "\u23a2";
|
|
263
269
|
bottom = "\u23a3";
|
|
264
270
|
font = "Size4-Regular";
|
|
271
|
+
svgLabel = "lbrack";
|
|
272
|
+
viewBoxWidth = 667;
|
|
265
273
|
} else if (delim === "]" || delim === "\\rbrack") {
|
|
266
274
|
top = "\u23a4";
|
|
267
275
|
repeat = "\u23a5";
|
|
268
276
|
bottom = "\u23a6";
|
|
269
277
|
font = "Size4-Regular";
|
|
278
|
+
svgLabel = "rbrack";
|
|
279
|
+
viewBoxWidth = 667;
|
|
270
280
|
} else if (delim === "\\lfloor" || delim === "\u230a") {
|
|
271
281
|
repeat = top = "\u23a2";
|
|
272
282
|
bottom = "\u23a3";
|
|
273
283
|
font = "Size4-Regular";
|
|
284
|
+
svgLabel = "lfloor";
|
|
285
|
+
viewBoxWidth = 667;
|
|
274
286
|
} else if (delim === "\\lceil" || delim === "\u2308") {
|
|
275
287
|
top = "\u23a1";
|
|
276
288
|
repeat = bottom = "\u23a2";
|
|
277
289
|
font = "Size4-Regular";
|
|
290
|
+
svgLabel = "lceil";
|
|
291
|
+
viewBoxWidth = 667;
|
|
278
292
|
} else if (delim === "\\rfloor" || delim === "\u230b") {
|
|
279
293
|
repeat = top = "\u23a5";
|
|
280
294
|
bottom = "\u23a6";
|
|
281
295
|
font = "Size4-Regular";
|
|
296
|
+
svgLabel = "rfloor";
|
|
297
|
+
viewBoxWidth = 667;
|
|
282
298
|
} else if (delim === "\\rceil" || delim === "\u2309") {
|
|
283
299
|
top = "\u23a4";
|
|
284
300
|
repeat = bottom = "\u23a5";
|
|
285
301
|
font = "Size4-Regular";
|
|
302
|
+
svgLabel = "rceil";
|
|
303
|
+
viewBoxWidth = 667;
|
|
286
304
|
} else if (delim === "(" || delim === "\\lparen") {
|
|
287
305
|
top = "\u239b";
|
|
288
306
|
repeat = "\u239c";
|
|
289
307
|
bottom = "\u239d";
|
|
290
308
|
font = "Size4-Regular";
|
|
309
|
+
svgLabel = "lparen";
|
|
310
|
+
viewBoxWidth = 875;
|
|
291
311
|
} else if (delim === ")" || delim === "\\rparen") {
|
|
292
312
|
top = "\u239e";
|
|
293
313
|
repeat = "\u239f";
|
|
294
314
|
bottom = "\u23a0";
|
|
295
315
|
font = "Size4-Regular";
|
|
316
|
+
svgLabel = "rparen";
|
|
317
|
+
viewBoxWidth = 875;
|
|
296
318
|
} else if (delim === "\\{" || delim === "\\lbrace") {
|
|
297
319
|
top = "\u23a7";
|
|
298
320
|
middle = "\u23a8";
|
|
@@ -365,38 +387,59 @@ const makeStackedDelim = function(
|
|
|
365
387
|
// Calculate the depth
|
|
366
388
|
const depth = realHeightTotal / 2 - axisHeight;
|
|
367
389
|
|
|
368
|
-
|
|
369
390
|
// Now, we start building the pieces that will go into the vlist
|
|
370
391
|
// Keep a list of the pieces of the stacked delimiter
|
|
371
392
|
const stack = [];
|
|
372
393
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
394
|
+
if (svgLabel.length > 0) {
|
|
395
|
+
// Instead of stacking glyphs, create a single SVG.
|
|
396
|
+
// This evades browser problems with imprecise positioning of spans.
|
|
397
|
+
const midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
|
|
398
|
+
const viewBoxHeight = Math.round(realHeightTotal * 1000);
|
|
399
|
+
const pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
|
|
400
|
+
const path = new PathNode(svgLabel, pathStr);
|
|
401
|
+
const width = (viewBoxWidth / 1000).toFixed(3) + "em";
|
|
402
|
+
const height = (viewBoxHeight / 1000).toFixed(3) + "em";
|
|
403
|
+
const svg = new SvgNode([path], {
|
|
404
|
+
"width": width,
|
|
405
|
+
"height": height,
|
|
406
|
+
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
|
|
407
|
+
});
|
|
408
|
+
const wrapper = buildCommon.makeSvgSpan([], [svg], options);
|
|
409
|
+
wrapper.height = viewBoxHeight / 1000;
|
|
410
|
+
wrapper.style.width = width;
|
|
411
|
+
wrapper.style.height = height;
|
|
412
|
+
stack.push({type: "elem", elem: wrapper});
|
|
383
413
|
} else {
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
414
|
+
// Stack glyphs
|
|
415
|
+
// Start by adding the bottom symbol
|
|
416
|
+
stack.push(makeGlyphSpan(bottom, font, mode));
|
|
417
|
+
stack.push(lap); // overlap
|
|
418
|
+
|
|
419
|
+
if (middle === null) {
|
|
420
|
+
// The middle section will be an SVG. Make it an extra 0.016em tall.
|
|
421
|
+
// We'll overlap by 0.008em at top and bottom.
|
|
422
|
+
const innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal
|
|
423
|
+
+ 2 * lapInEms;
|
|
424
|
+
stack.push(makeInner(repeat, innerHeight, options));
|
|
425
|
+
} else {
|
|
426
|
+
// When there is a middle bit, we need the middle part and two repeated
|
|
427
|
+
// sections
|
|
428
|
+
const innerHeight = (realHeightTotal - topHeightTotal -
|
|
429
|
+
bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
|
|
430
|
+
stack.push(makeInner(repeat, innerHeight, options));
|
|
431
|
+
// Now insert the middle of the brace.
|
|
432
|
+
stack.push(lap);
|
|
433
|
+
stack.push(makeGlyphSpan(middle, font, mode));
|
|
434
|
+
stack.push(lap);
|
|
435
|
+
stack.push(makeInner(repeat, innerHeight, options));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Add the top symbol
|
|
392
439
|
stack.push(lap);
|
|
393
|
-
stack.push(
|
|
440
|
+
stack.push(makeGlyphSpan(top, font, mode));
|
|
394
441
|
}
|
|
395
442
|
|
|
396
|
-
// Add the top symbol
|
|
397
|
-
stack.push(lap);
|
|
398
|
-
stack.push(makeGlyphSpan(top, font, mode));
|
|
399
|
-
|
|
400
443
|
// Finally, build the vlist
|
|
401
444
|
const newOptions = options.havingBaseStyle(Style.TEXT);
|
|
402
445
|
const inner = buildCommon.makeVList({
|
package/src/macros.js
CHANGED
|
@@ -912,6 +912,58 @@ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
|
|
|
912
912
|
defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
|
|
913
913
|
defineMacro("\\Bra", "\\left\\langle#1\\right|");
|
|
914
914
|
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
|
|
915
|
+
const braketHelper = (one) => (context) => {
|
|
916
|
+
const left = context.consumeArg().tokens;
|
|
917
|
+
const middle = context.consumeArg().tokens;
|
|
918
|
+
const middleDouble = context.consumeArg().tokens;
|
|
919
|
+
const right = context.consumeArg().tokens;
|
|
920
|
+
const oldMiddle = context.macros.get("|");
|
|
921
|
+
const oldMiddleDouble = context.macros.get("\\|");
|
|
922
|
+
context.macros.beginGroup();
|
|
923
|
+
const midMacro = (double) => (context) => {
|
|
924
|
+
if (one) {
|
|
925
|
+
// Only modify the first instance of | or \|
|
|
926
|
+
context.macros.set("|", oldMiddle);
|
|
927
|
+
if (middleDouble.length) {
|
|
928
|
+
context.macros.set("\\|", oldMiddleDouble);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
let doubled = double;
|
|
932
|
+
if (!double && middleDouble.length) {
|
|
933
|
+
// Mimic \@ifnextchar
|
|
934
|
+
const nextToken = context.future();
|
|
935
|
+
if (nextToken.text === "|") {
|
|
936
|
+
context.popToken();
|
|
937
|
+
doubled = true;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
tokens: doubled ? middleDouble : middle,
|
|
942
|
+
numArgs: 0,
|
|
943
|
+
};
|
|
944
|
+
};
|
|
945
|
+
context.macros.set("|", midMacro(false));
|
|
946
|
+
if (middleDouble.length) {
|
|
947
|
+
context.macros.set("\\|", midMacro(true));
|
|
948
|
+
}
|
|
949
|
+
const arg = context.consumeArg().tokens;
|
|
950
|
+
const expanded = context.expandTokens([
|
|
951
|
+
...right, ...arg, ...left, // reversed
|
|
952
|
+
]);
|
|
953
|
+
context.macros.endGroup();
|
|
954
|
+
return {
|
|
955
|
+
tokens: expanded.reverse(),
|
|
956
|
+
numArgs: 0,
|
|
957
|
+
};
|
|
958
|
+
};
|
|
959
|
+
defineMacro("\\bra@ket", braketHelper(false));
|
|
960
|
+
defineMacro("\\bra@set", braketHelper(true));
|
|
961
|
+
defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" +
|
|
962
|
+
"{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
|
|
963
|
+
defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" +
|
|
964
|
+
"{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
|
|
965
|
+
defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
|
|
966
|
+
// has no support for special || or \|
|
|
915
967
|
|
|
916
968
|
//////////////////////////////////////////////////////////////////////
|
|
917
969
|
// actuarialangle.dtx
|
package/src/svgGeometry.js
CHANGED
|
@@ -487,3 +487,59 @@ c4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,
|
|
|
487
487
|
c-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z
|
|
488
488
|
M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
|
|
489
489
|
};
|
|
490
|
+
|
|
491
|
+
export const tallDelim = function(label: string, midHeight: number): string {
|
|
492
|
+
switch (label) {
|
|
493
|
+
case "lbrack":
|
|
494
|
+
return `M403 1759 V84 H666 V0 H319 V1759 v${midHeight} v1759 h347 v-84
|
|
495
|
+
H403z M403 1759 V0 H319 V1759 v${midHeight} v1759 h84z`;
|
|
496
|
+
case "rbrack":
|
|
497
|
+
return `M347 1759 V0 H0 V84 H263 V1759 v${midHeight} v1759 H0 v84 H347z
|
|
498
|
+
M347 1759 V0 H263 V1759 v${midHeight} v1759 h84z`;
|
|
499
|
+
case "vert":
|
|
500
|
+
return `M145 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
|
|
501
|
+
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
|
|
502
|
+
c-10,0,-16.667,5,-20,15z M188 15 H145 v585 v${midHeight} v585 h43z`;
|
|
503
|
+
case "doublevert":
|
|
504
|
+
return `M145 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
|
|
505
|
+
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
|
|
506
|
+
c-10,0,-16.667,5,-20,15z M188 15 H145 v585 v${midHeight} v585 h43z
|
|
507
|
+
M367 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
|
|
508
|
+
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
|
|
509
|
+
c-10,0,-16.667,5,-20,15z M410 15 H367 v585 v${midHeight} v585 h43z`;
|
|
510
|
+
case "lfloor":
|
|
511
|
+
return `M319 602 V0 H403 V602 v${midHeight} v1715 h263 v84 H319z
|
|
512
|
+
MM319 602 V0 H403 V602 v${midHeight} v1715 H319z`;
|
|
513
|
+
case "rfloor":
|
|
514
|
+
return `M319 602 V0 H403 V602 v${midHeight} v1799 H0 v-84 H319z
|
|
515
|
+
MM319 602 V0 H403 V602 v${midHeight} v1715 H319z`;
|
|
516
|
+
case "lceil":
|
|
517
|
+
return `M403 1759 V84 H666 V0 H319 V1759 v${midHeight} v602 h84z
|
|
518
|
+
M403 1759 V0 H319 V1759 v${midHeight} v602 h84z`;
|
|
519
|
+
case "rceil":
|
|
520
|
+
return `M347 1759 V0 H0 V84 H263 V1759 v${midHeight} v602 h84z
|
|
521
|
+
M347 1759 V0 h-84 V1759 v${midHeight} v602 h84z`;
|
|
522
|
+
case "lparen":
|
|
523
|
+
return `M863,9c0,-2,-2,-5,-6,-9c0,0,-17,0,-17,0c-12.7,0,-19.3,0.3,-20,1
|
|
524
|
+
c-5.3,5.3,-10.3,11,-15,17c-242.7,294.7,-395.3,682,-458,1162c-21.3,163.3,-33.3,349,
|
|
525
|
+
-36,557 l0,${midHeight + 84}c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,
|
|
526
|
+
949.7,470,1265c4.7,6,9.7,11.7,15,17c0.7,0.7,7,1,19,1c0,0,18,0,18,0c4,-4,6,-7,6,-9
|
|
527
|
+
c0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,
|
|
528
|
+
-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189
|
|
529
|
+
l0,-${midHeight + 92}c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,
|
|
530
|
+
-210,155.3,-396.3,270,-559c6.7,-9.3,10,-15.3,10,-18z`;
|
|
531
|
+
case "rparen":
|
|
532
|
+
return `M76,0c-16.7,0,-25,3,-25,9c0,2,2,6.3,6,13c21.3,28.7,42.3,60.3,
|
|
533
|
+
63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5
|
|
534
|
+
c11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0,${midHeight + 9}
|
|
535
|
+
c-3,4,-3.3,16.7,-3.3,38c0,162,-5.7,313.7,-17,455c-18.7,248,-55.8,469.3,-111.5,664
|
|
536
|
+
c-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6,11
|
|
537
|
+
c0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17
|
|
538
|
+
c242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558
|
|
539
|
+
l0,-${midHeight + 144}c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
540
|
+
-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;
|
|
541
|
+
default:
|
|
542
|
+
// We should not ever get here.
|
|
543
|
+
throw new Error("Unknown stretchy delimiter.");
|
|
544
|
+
}
|
|
545
|
+
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* Force selection of entire .katex/.katex-display blocks, so that we can
|
|
2
|
-
* copy/paste the entire source code. If you omit this CSS, partial
|
|
3
|
-
* selections of a formula will work, but will copy the ugly HTML
|
|
4
|
-
* representation instead of the LaTeX source code. (Full selections will
|
|
5
|
-
* still produce the LaTeX source code.)
|
|
6
|
-
*/
|
|
7
|
-
.katex,
|
|
8
|
-
.katex-display {
|
|
9
|
-
user-select: all;
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* Force selection of entire .katex/.katex-display blocks, so that we can
|
|
2
|
-
* copy/paste the entire source code. If you omit this CSS, partial
|
|
3
|
-
* selections of a formula will work, but will copy the ugly HTML
|
|
4
|
-
* representation instead of the LaTeX source code. (Full selections will
|
|
5
|
-
* still produce the LaTeX source code.)
|
|
6
|
-
*/
|
|
7
|
-
.katex,
|
|
8
|
-
.katex-display {
|
|
9
|
-
-webkit-user-select: all;
|
|
10
|
-
-moz-user-select: all;
|
|
11
|
-
user-select: all;
|
|
12
|
-
}
|
|
13
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.katex,.katex-display{-webkit-user-select:all;-moz-user-select:all;user-select:all}
|