ed-mathml2tex 0.0.6 → 0.0.8
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/lib/mathml2latex.browser.cjs.js +34 -58
- package/lib/mathml2latex.browser.es.js +34 -58
- package/lib/mathml2latex.browser.umd.js +34 -58
- package/lib/mathml2latex.cjs.js +34 -58
- package/lib/mathml2latex.es.js +34 -58
- package/lib/mathml2latex.umd.js +34 -58
- package/package.json +1 -1
|
@@ -596,25 +596,6 @@ function getRender_joinSeparator(template, separator = '') {
|
|
|
596
596
|
};
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
function getRender_joinSeparators(template, separators) {
|
|
600
|
-
return function(node, children) {
|
|
601
|
-
const parts = renderChildren(children);
|
|
602
|
-
let content = '';
|
|
603
|
-
if (separators.length === 0) {
|
|
604
|
-
content = parts.join('');
|
|
605
|
-
} else {
|
|
606
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
607
|
-
accumulator += part;
|
|
608
|
-
if (index < parts.length - 1) {
|
|
609
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
610
|
-
}
|
|
611
|
-
return accumulator;
|
|
612
|
-
}, '');
|
|
613
|
-
}
|
|
614
|
-
return template.replace('@content', content);
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
|
|
618
599
|
function convert(mathmlHtml){
|
|
619
600
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
620
601
|
let result = toLatex(parse(math));
|
|
@@ -792,7 +773,7 @@ function escapeSpecialChars(text) {
|
|
|
792
773
|
|
|
793
774
|
function parseContainer(node, children) {
|
|
794
775
|
const render = getRender(node);
|
|
795
|
-
if(render){
|
|
776
|
+
if (render) {
|
|
796
777
|
return render(node, children);
|
|
797
778
|
} else {
|
|
798
779
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -913,11 +894,40 @@ function getRender(node) {
|
|
|
913
894
|
}
|
|
914
895
|
|
|
915
896
|
function renderTable(node, children) {
|
|
916
|
-
const template = "\\begin{
|
|
917
|
-
const render = getRender_joinSeparator(template);
|
|
897
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
898
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
918
899
|
return render(node, children);
|
|
919
900
|
}
|
|
920
901
|
|
|
902
|
+
function renderMfenced(node, children) {
|
|
903
|
+
const [open, close, separatorsStr] = [
|
|
904
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
905
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
906
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
907
|
+
];
|
|
908
|
+
|
|
909
|
+
const parts = renderChildren(children);
|
|
910
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
911
|
+
|
|
912
|
+
// Handle empty open/close brackets
|
|
913
|
+
if (open === '' && close === '|') {
|
|
914
|
+
return `|${content}|`;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// Handle absolute value notation
|
|
918
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
919
|
+
return `\\left|${content}\\right|`;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// Regular parentheses
|
|
923
|
+
if (open === '(' && close === ')') {
|
|
924
|
+
return `\\left(${content}\\right)`;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// Default case
|
|
928
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
929
|
+
}
|
|
930
|
+
|
|
921
931
|
function renderMfrac(node, children){
|
|
922
932
|
const [linethickness, bevelled] = [
|
|
923
933
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -935,9 +945,9 @@ function renderMfrac(node, children){
|
|
|
935
945
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
936
946
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
937
947
|
) {
|
|
938
|
-
render = getRender_default("\\
|
|
948
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
939
949
|
} else {
|
|
940
|
-
render = getRender_default("{}
|
|
950
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
941
951
|
}
|
|
942
952
|
} else {
|
|
943
953
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -945,40 +955,6 @@ function renderMfrac(node, children){
|
|
|
945
955
|
return render(node, children);
|
|
946
956
|
}
|
|
947
957
|
|
|
948
|
-
function renderMfenced(node, children) {
|
|
949
|
-
const [open, close, separatorsStr] = [
|
|
950
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
951
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
952
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
953
|
-
];
|
|
954
|
-
|
|
955
|
-
// Handle special case for vectors inside brackets
|
|
956
|
-
if (open === '[' && close === ']') {
|
|
957
|
-
const parts = renderChildren(children);
|
|
958
|
-
// Join parts with comma and space, preserving vector notation
|
|
959
|
-
const content = parts.join(', ');
|
|
960
|
-
return `\\left[${content}\\right]`;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// Handle special case for coordinates
|
|
964
|
-
if (open === '(' && close === ')') {
|
|
965
|
-
const parts = renderChildren(children);
|
|
966
|
-
// Join parts with semicolon
|
|
967
|
-
const content = parts.join(';');
|
|
968
|
-
return `\\left(${content}\\right)`;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
const [left, right] = [
|
|
972
|
-
Brackets.parseLeft(open),
|
|
973
|
-
Brackets.parseRight(close)
|
|
974
|
-
];
|
|
975
|
-
|
|
976
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
977
|
-
const template = `${left}@content${right}`;
|
|
978
|
-
const render = getRender_joinSeparators(template, separators);
|
|
979
|
-
return render(node, children);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
958
|
function renderMmultiscripts(node, children) {
|
|
983
959
|
if(children.length === 0) { return '' }
|
|
984
960
|
let sepIndex = -1;
|
|
@@ -594,25 +594,6 @@ function getRender_joinSeparator(template, separator = '') {
|
|
|
594
594
|
};
|
|
595
595
|
}
|
|
596
596
|
|
|
597
|
-
function getRender_joinSeparators(template, separators) {
|
|
598
|
-
return function(node, children) {
|
|
599
|
-
const parts = renderChildren(children);
|
|
600
|
-
let content = '';
|
|
601
|
-
if (separators.length === 0) {
|
|
602
|
-
content = parts.join('');
|
|
603
|
-
} else {
|
|
604
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
605
|
-
accumulator += part;
|
|
606
|
-
if (index < parts.length - 1) {
|
|
607
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
608
|
-
}
|
|
609
|
-
return accumulator;
|
|
610
|
-
}, '');
|
|
611
|
-
}
|
|
612
|
-
return template.replace('@content', content);
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
|
|
616
597
|
function convert(mathmlHtml){
|
|
617
598
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
618
599
|
let result = toLatex(parse(math));
|
|
@@ -790,7 +771,7 @@ function escapeSpecialChars(text) {
|
|
|
790
771
|
|
|
791
772
|
function parseContainer(node, children) {
|
|
792
773
|
const render = getRender(node);
|
|
793
|
-
if(render){
|
|
774
|
+
if (render) {
|
|
794
775
|
return render(node, children);
|
|
795
776
|
} else {
|
|
796
777
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -911,11 +892,40 @@ function getRender(node) {
|
|
|
911
892
|
}
|
|
912
893
|
|
|
913
894
|
function renderTable(node, children) {
|
|
914
|
-
const template = "\\begin{
|
|
915
|
-
const render = getRender_joinSeparator(template);
|
|
895
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
896
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
916
897
|
return render(node, children);
|
|
917
898
|
}
|
|
918
899
|
|
|
900
|
+
function renderMfenced(node, children) {
|
|
901
|
+
const [open, close, separatorsStr] = [
|
|
902
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
903
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
904
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
905
|
+
];
|
|
906
|
+
|
|
907
|
+
const parts = renderChildren(children);
|
|
908
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
909
|
+
|
|
910
|
+
// Handle empty open/close brackets
|
|
911
|
+
if (open === '' && close === '|') {
|
|
912
|
+
return `|${content}|`;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// Handle absolute value notation
|
|
916
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
917
|
+
return `\\left|${content}\\right|`;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// Regular parentheses
|
|
921
|
+
if (open === '(' && close === ')') {
|
|
922
|
+
return `\\left(${content}\\right)`;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// Default case
|
|
926
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
927
|
+
}
|
|
928
|
+
|
|
919
929
|
function renderMfrac(node, children){
|
|
920
930
|
const [linethickness, bevelled] = [
|
|
921
931
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -933,9 +943,9 @@ function renderMfrac(node, children){
|
|
|
933
943
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
934
944
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
935
945
|
) {
|
|
936
|
-
render = getRender_default("\\
|
|
946
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
937
947
|
} else {
|
|
938
|
-
render = getRender_default("{}
|
|
948
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
939
949
|
}
|
|
940
950
|
} else {
|
|
941
951
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -943,40 +953,6 @@ function renderMfrac(node, children){
|
|
|
943
953
|
return render(node, children);
|
|
944
954
|
}
|
|
945
955
|
|
|
946
|
-
function renderMfenced(node, children) {
|
|
947
|
-
const [open, close, separatorsStr] = [
|
|
948
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
949
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
950
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
951
|
-
];
|
|
952
|
-
|
|
953
|
-
// Handle special case for vectors inside brackets
|
|
954
|
-
if (open === '[' && close === ']') {
|
|
955
|
-
const parts = renderChildren(children);
|
|
956
|
-
// Join parts with comma and space, preserving vector notation
|
|
957
|
-
const content = parts.join(', ');
|
|
958
|
-
return `\\left[${content}\\right]`;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
// Handle special case for coordinates
|
|
962
|
-
if (open === '(' && close === ')') {
|
|
963
|
-
const parts = renderChildren(children);
|
|
964
|
-
// Join parts with semicolon
|
|
965
|
-
const content = parts.join(';');
|
|
966
|
-
return `\\left(${content}\\right)`;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
const [left, right] = [
|
|
970
|
-
Brackets.parseLeft(open),
|
|
971
|
-
Brackets.parseRight(close)
|
|
972
|
-
];
|
|
973
|
-
|
|
974
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
975
|
-
const template = `${left}@content${right}`;
|
|
976
|
-
const render = getRender_joinSeparators(template, separators);
|
|
977
|
-
return render(node, children);
|
|
978
|
-
}
|
|
979
|
-
|
|
980
956
|
function renderMmultiscripts(node, children) {
|
|
981
957
|
if(children.length === 0) { return '' }
|
|
982
958
|
let sepIndex = -1;
|
|
@@ -600,25 +600,6 @@
|
|
|
600
600
|
};
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
function getRender_joinSeparators(template, separators) {
|
|
604
|
-
return function(node, children) {
|
|
605
|
-
const parts = renderChildren(children);
|
|
606
|
-
let content = '';
|
|
607
|
-
if (separators.length === 0) {
|
|
608
|
-
content = parts.join('');
|
|
609
|
-
} else {
|
|
610
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
611
|
-
accumulator += part;
|
|
612
|
-
if (index < parts.length - 1) {
|
|
613
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
614
|
-
}
|
|
615
|
-
return accumulator;
|
|
616
|
-
}, '');
|
|
617
|
-
}
|
|
618
|
-
return template.replace('@content', content);
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
603
|
function convert(mathmlHtml){
|
|
623
604
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
624
605
|
let result = toLatex(parse(math));
|
|
@@ -796,7 +777,7 @@
|
|
|
796
777
|
|
|
797
778
|
function parseContainer(node, children) {
|
|
798
779
|
const render = getRender(node);
|
|
799
|
-
if(render){
|
|
780
|
+
if (render) {
|
|
800
781
|
return render(node, children);
|
|
801
782
|
} else {
|
|
802
783
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -917,11 +898,40 @@
|
|
|
917
898
|
}
|
|
918
899
|
|
|
919
900
|
function renderTable(node, children) {
|
|
920
|
-
const template = "\\begin{
|
|
921
|
-
const render = getRender_joinSeparator(template);
|
|
901
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
902
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
922
903
|
return render(node, children);
|
|
923
904
|
}
|
|
924
905
|
|
|
906
|
+
function renderMfenced(node, children) {
|
|
907
|
+
const [open, close, separatorsStr] = [
|
|
908
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
909
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
910
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
911
|
+
];
|
|
912
|
+
|
|
913
|
+
const parts = renderChildren(children);
|
|
914
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
915
|
+
|
|
916
|
+
// Handle empty open/close brackets
|
|
917
|
+
if (open === '' && close === '|') {
|
|
918
|
+
return `|${content}|`;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Handle absolute value notation
|
|
922
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
923
|
+
return `\\left|${content}\\right|`;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Regular parentheses
|
|
927
|
+
if (open === '(' && close === ')') {
|
|
928
|
+
return `\\left(${content}\\right)`;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Default case
|
|
932
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
933
|
+
}
|
|
934
|
+
|
|
925
935
|
function renderMfrac(node, children){
|
|
926
936
|
const [linethickness, bevelled] = [
|
|
927
937
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -939,9 +949,9 @@
|
|
|
939
949
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
940
950
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
941
951
|
) {
|
|
942
|
-
render = getRender_default("\\
|
|
952
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
943
953
|
} else {
|
|
944
|
-
render = getRender_default("{}
|
|
954
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
945
955
|
}
|
|
946
956
|
} else {
|
|
947
957
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -949,40 +959,6 @@
|
|
|
949
959
|
return render(node, children);
|
|
950
960
|
}
|
|
951
961
|
|
|
952
|
-
function renderMfenced(node, children) {
|
|
953
|
-
const [open, close, separatorsStr] = [
|
|
954
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
955
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
956
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
957
|
-
];
|
|
958
|
-
|
|
959
|
-
// Handle special case for vectors inside brackets
|
|
960
|
-
if (open === '[' && close === ']') {
|
|
961
|
-
const parts = renderChildren(children);
|
|
962
|
-
// Join parts with comma and space, preserving vector notation
|
|
963
|
-
const content = parts.join(', ');
|
|
964
|
-
return `\\left[${content}\\right]`;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
// Handle special case for coordinates
|
|
968
|
-
if (open === '(' && close === ')') {
|
|
969
|
-
const parts = renderChildren(children);
|
|
970
|
-
// Join parts with semicolon
|
|
971
|
-
const content = parts.join(';');
|
|
972
|
-
return `\\left(${content}\\right)`;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
const [left, right] = [
|
|
976
|
-
Brackets.parseLeft(open),
|
|
977
|
-
Brackets.parseRight(close)
|
|
978
|
-
];
|
|
979
|
-
|
|
980
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
981
|
-
const template = `${left}@content${right}`;
|
|
982
|
-
const render = getRender_joinSeparators(template, separators);
|
|
983
|
-
return render(node, children);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
962
|
function renderMmultiscripts(node, children) {
|
|
987
963
|
if(children.length === 0) { return '' }
|
|
988
964
|
let sepIndex = -1;
|
package/lib/mathml2latex.cjs.js
CHANGED
|
@@ -596,25 +596,6 @@ function getRender_joinSeparator(template, separator = '') {
|
|
|
596
596
|
};
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
function getRender_joinSeparators(template, separators) {
|
|
600
|
-
return function(node, children) {
|
|
601
|
-
const parts = renderChildren(children);
|
|
602
|
-
let content = '';
|
|
603
|
-
if (separators.length === 0) {
|
|
604
|
-
content = parts.join('');
|
|
605
|
-
} else {
|
|
606
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
607
|
-
accumulator += part;
|
|
608
|
-
if (index < parts.length - 1) {
|
|
609
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
610
|
-
}
|
|
611
|
-
return accumulator;
|
|
612
|
-
}, '');
|
|
613
|
-
}
|
|
614
|
-
return template.replace('@content', content);
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
|
|
618
599
|
function convert(mathmlHtml){
|
|
619
600
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
620
601
|
let result = toLatex(parse(math));
|
|
@@ -792,7 +773,7 @@ function escapeSpecialChars(text) {
|
|
|
792
773
|
|
|
793
774
|
function parseContainer(node, children) {
|
|
794
775
|
const render = getRender(node);
|
|
795
|
-
if(render){
|
|
776
|
+
if (render) {
|
|
796
777
|
return render(node, children);
|
|
797
778
|
} else {
|
|
798
779
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -913,11 +894,40 @@ function getRender(node) {
|
|
|
913
894
|
}
|
|
914
895
|
|
|
915
896
|
function renderTable(node, children) {
|
|
916
|
-
const template = "\\begin{
|
|
917
|
-
const render = getRender_joinSeparator(template);
|
|
897
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
898
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
918
899
|
return render(node, children);
|
|
919
900
|
}
|
|
920
901
|
|
|
902
|
+
function renderMfenced(node, children) {
|
|
903
|
+
const [open, close, separatorsStr] = [
|
|
904
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
905
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
906
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
907
|
+
];
|
|
908
|
+
|
|
909
|
+
const parts = renderChildren(children);
|
|
910
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
911
|
+
|
|
912
|
+
// Handle empty open/close brackets
|
|
913
|
+
if (open === '' && close === '|') {
|
|
914
|
+
return `|${content}|`;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// Handle absolute value notation
|
|
918
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
919
|
+
return `\\left|${content}\\right|`;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// Regular parentheses
|
|
923
|
+
if (open === '(' && close === ')') {
|
|
924
|
+
return `\\left(${content}\\right)`;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// Default case
|
|
928
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
929
|
+
}
|
|
930
|
+
|
|
921
931
|
function renderMfrac(node, children){
|
|
922
932
|
const [linethickness, bevelled] = [
|
|
923
933
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -935,9 +945,9 @@ function renderMfrac(node, children){
|
|
|
935
945
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
936
946
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
937
947
|
) {
|
|
938
|
-
render = getRender_default("\\
|
|
948
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
939
949
|
} else {
|
|
940
|
-
render = getRender_default("{}
|
|
950
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
941
951
|
}
|
|
942
952
|
} else {
|
|
943
953
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -945,40 +955,6 @@ function renderMfrac(node, children){
|
|
|
945
955
|
return render(node, children);
|
|
946
956
|
}
|
|
947
957
|
|
|
948
|
-
function renderMfenced(node, children) {
|
|
949
|
-
const [open, close, separatorsStr] = [
|
|
950
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
951
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
952
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
953
|
-
];
|
|
954
|
-
|
|
955
|
-
// Handle special case for vectors inside brackets
|
|
956
|
-
if (open === '[' && close === ']') {
|
|
957
|
-
const parts = renderChildren(children);
|
|
958
|
-
// Join parts with comma and space, preserving vector notation
|
|
959
|
-
const content = parts.join(', ');
|
|
960
|
-
return `\\left[${content}\\right]`;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// Handle special case for coordinates
|
|
964
|
-
if (open === '(' && close === ')') {
|
|
965
|
-
const parts = renderChildren(children);
|
|
966
|
-
// Join parts with semicolon
|
|
967
|
-
const content = parts.join(';');
|
|
968
|
-
return `\\left(${content}\\right)`;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
const [left, right] = [
|
|
972
|
-
Brackets.parseLeft(open),
|
|
973
|
-
Brackets.parseRight(close)
|
|
974
|
-
];
|
|
975
|
-
|
|
976
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
977
|
-
const template = `${left}@content${right}`;
|
|
978
|
-
const render = getRender_joinSeparators(template, separators);
|
|
979
|
-
return render(node, children);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
958
|
function renderMmultiscripts(node, children) {
|
|
983
959
|
if(children.length === 0) { return '' }
|
|
984
960
|
let sepIndex = -1;
|
package/lib/mathml2latex.es.js
CHANGED
|
@@ -594,25 +594,6 @@ function getRender_joinSeparator(template, separator = '') {
|
|
|
594
594
|
};
|
|
595
595
|
}
|
|
596
596
|
|
|
597
|
-
function getRender_joinSeparators(template, separators) {
|
|
598
|
-
return function(node, children) {
|
|
599
|
-
const parts = renderChildren(children);
|
|
600
|
-
let content = '';
|
|
601
|
-
if (separators.length === 0) {
|
|
602
|
-
content = parts.join('');
|
|
603
|
-
} else {
|
|
604
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
605
|
-
accumulator += part;
|
|
606
|
-
if (index < parts.length - 1) {
|
|
607
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
608
|
-
}
|
|
609
|
-
return accumulator;
|
|
610
|
-
}, '');
|
|
611
|
-
}
|
|
612
|
-
return template.replace('@content', content);
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
|
|
616
597
|
function convert(mathmlHtml){
|
|
617
598
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
618
599
|
let result = toLatex(parse(math));
|
|
@@ -790,7 +771,7 @@ function escapeSpecialChars(text) {
|
|
|
790
771
|
|
|
791
772
|
function parseContainer(node, children) {
|
|
792
773
|
const render = getRender(node);
|
|
793
|
-
if(render){
|
|
774
|
+
if (render) {
|
|
794
775
|
return render(node, children);
|
|
795
776
|
} else {
|
|
796
777
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -911,11 +892,40 @@ function getRender(node) {
|
|
|
911
892
|
}
|
|
912
893
|
|
|
913
894
|
function renderTable(node, children) {
|
|
914
|
-
const template = "\\begin{
|
|
915
|
-
const render = getRender_joinSeparator(template);
|
|
895
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
896
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
916
897
|
return render(node, children);
|
|
917
898
|
}
|
|
918
899
|
|
|
900
|
+
function renderMfenced(node, children) {
|
|
901
|
+
const [open, close, separatorsStr] = [
|
|
902
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
903
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
904
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
905
|
+
];
|
|
906
|
+
|
|
907
|
+
const parts = renderChildren(children);
|
|
908
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
909
|
+
|
|
910
|
+
// Handle empty open/close brackets
|
|
911
|
+
if (open === '' && close === '|') {
|
|
912
|
+
return `|${content}|`;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// Handle absolute value notation
|
|
916
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
917
|
+
return `\\left|${content}\\right|`;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// Regular parentheses
|
|
921
|
+
if (open === '(' && close === ')') {
|
|
922
|
+
return `\\left(${content}\\right)`;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// Default case
|
|
926
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
927
|
+
}
|
|
928
|
+
|
|
919
929
|
function renderMfrac(node, children){
|
|
920
930
|
const [linethickness, bevelled] = [
|
|
921
931
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -933,9 +943,9 @@ function renderMfrac(node, children){
|
|
|
933
943
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
934
944
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
935
945
|
) {
|
|
936
|
-
render = getRender_default("\\
|
|
946
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
937
947
|
} else {
|
|
938
|
-
render = getRender_default("{}
|
|
948
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
939
949
|
}
|
|
940
950
|
} else {
|
|
941
951
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -943,40 +953,6 @@ function renderMfrac(node, children){
|
|
|
943
953
|
return render(node, children);
|
|
944
954
|
}
|
|
945
955
|
|
|
946
|
-
function renderMfenced(node, children) {
|
|
947
|
-
const [open, close, separatorsStr] = [
|
|
948
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
949
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
950
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
951
|
-
];
|
|
952
|
-
|
|
953
|
-
// Handle special case for vectors inside brackets
|
|
954
|
-
if (open === '[' && close === ']') {
|
|
955
|
-
const parts = renderChildren(children);
|
|
956
|
-
// Join parts with comma and space, preserving vector notation
|
|
957
|
-
const content = parts.join(', ');
|
|
958
|
-
return `\\left[${content}\\right]`;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
// Handle special case for coordinates
|
|
962
|
-
if (open === '(' && close === ')') {
|
|
963
|
-
const parts = renderChildren(children);
|
|
964
|
-
// Join parts with semicolon
|
|
965
|
-
const content = parts.join(';');
|
|
966
|
-
return `\\left(${content}\\right)`;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
const [left, right] = [
|
|
970
|
-
Brackets.parseLeft(open),
|
|
971
|
-
Brackets.parseRight(close)
|
|
972
|
-
];
|
|
973
|
-
|
|
974
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
975
|
-
const template = `${left}@content${right}`;
|
|
976
|
-
const render = getRender_joinSeparators(template, separators);
|
|
977
|
-
return render(node, children);
|
|
978
|
-
}
|
|
979
|
-
|
|
980
956
|
function renderMmultiscripts(node, children) {
|
|
981
957
|
if(children.length === 0) { return '' }
|
|
982
958
|
let sepIndex = -1;
|
package/lib/mathml2latex.umd.js
CHANGED
|
@@ -600,25 +600,6 @@
|
|
|
600
600
|
};
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
function getRender_joinSeparators(template, separators) {
|
|
604
|
-
return function(node, children) {
|
|
605
|
-
const parts = renderChildren(children);
|
|
606
|
-
let content = '';
|
|
607
|
-
if (separators.length === 0) {
|
|
608
|
-
content = parts.join('');
|
|
609
|
-
} else {
|
|
610
|
-
content = parts.reduce((accumulator, part, index) => {
|
|
611
|
-
accumulator += part;
|
|
612
|
-
if (index < parts.length - 1) {
|
|
613
|
-
accumulator += separators[index] || separators[separators.length - 1];
|
|
614
|
-
}
|
|
615
|
-
return accumulator;
|
|
616
|
-
}, '');
|
|
617
|
-
}
|
|
618
|
-
return template.replace('@content', content);
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
603
|
function convert(mathmlHtml){
|
|
623
604
|
const math = NodeTool.parseMath(mathmlHtml);
|
|
624
605
|
let result = toLatex(parse(math));
|
|
@@ -796,7 +777,7 @@
|
|
|
796
777
|
|
|
797
778
|
function parseContainer(node, children) {
|
|
798
779
|
const render = getRender(node);
|
|
799
|
-
if(render){
|
|
780
|
+
if (render) {
|
|
800
781
|
return render(node, children);
|
|
801
782
|
} else {
|
|
802
783
|
throw new Error(`Couldn't get render function for container node: ${NodeTool.getNodeName(node)}`);
|
|
@@ -917,11 +898,40 @@
|
|
|
917
898
|
}
|
|
918
899
|
|
|
919
900
|
function renderTable(node, children) {
|
|
920
|
-
const template = "\\begin{
|
|
921
|
-
const render = getRender_joinSeparator(template);
|
|
901
|
+
const template = "\\begin{array}{l}@content\\end{array}";
|
|
902
|
+
const render = getRender_joinSeparator(template, "\\\\");
|
|
922
903
|
return render(node, children);
|
|
923
904
|
}
|
|
924
905
|
|
|
906
|
+
function renderMfenced(node, children) {
|
|
907
|
+
const [open, close, separatorsStr] = [
|
|
908
|
+
NodeTool.getAttr(node, 'open', '('),
|
|
909
|
+
NodeTool.getAttr(node, 'close', ')'),
|
|
910
|
+
NodeTool.getAttr(node, 'separators', ',')
|
|
911
|
+
];
|
|
912
|
+
|
|
913
|
+
const parts = renderChildren(children);
|
|
914
|
+
const content = parts.join(separatorsStr === '|' ? ',' : separatorsStr).trim();
|
|
915
|
+
|
|
916
|
+
// Handle empty open/close brackets
|
|
917
|
+
if (open === '' && close === '|') {
|
|
918
|
+
return `|${content}|`;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Handle absolute value notation
|
|
922
|
+
if (open === '|' && (close === '|' || close === '')) {
|
|
923
|
+
return `\\left|${content}\\right|`;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Regular parentheses
|
|
927
|
+
if (open === '(' && close === ')') {
|
|
928
|
+
return `\\left(${content}\\right)`;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Default case
|
|
932
|
+
return `\\left${open}${content}\\right${close || '.'}`;
|
|
933
|
+
}
|
|
934
|
+
|
|
925
935
|
function renderMfrac(node, children){
|
|
926
936
|
const [linethickness, bevelled] = [
|
|
927
937
|
NodeTool.getAttr(node, 'linethickness', 'medium'),
|
|
@@ -939,9 +949,9 @@
|
|
|
939
949
|
if((prevNode && NodeTool.getNodeText(prevNode).trim() === '(') &&
|
|
940
950
|
(nextNode && NodeTool.getNodeText(nextNode).trim() === ')')
|
|
941
951
|
) {
|
|
942
|
-
render = getRender_default("\\
|
|
952
|
+
render = getRender_default("\\binom{@1}{@2}");
|
|
943
953
|
} else {
|
|
944
|
-
render = getRender_default("{}
|
|
954
|
+
render = getRender_default("\\frac{@1}{@2}");
|
|
945
955
|
}
|
|
946
956
|
} else {
|
|
947
957
|
render = getRender_default("\\frac{@1}{@2}");
|
|
@@ -949,40 +959,6 @@
|
|
|
949
959
|
return render(node, children);
|
|
950
960
|
}
|
|
951
961
|
|
|
952
|
-
function renderMfenced(node, children) {
|
|
953
|
-
const [open, close, separatorsStr] = [
|
|
954
|
-
NodeTool.getAttr(node, 'open', '('),
|
|
955
|
-
NodeTool.getAttr(node, 'close', ')'),
|
|
956
|
-
NodeTool.getAttr(node, 'separators', ',')
|
|
957
|
-
];
|
|
958
|
-
|
|
959
|
-
// Handle special case for vectors inside brackets
|
|
960
|
-
if (open === '[' && close === ']') {
|
|
961
|
-
const parts = renderChildren(children);
|
|
962
|
-
// Join parts with comma and space, preserving vector notation
|
|
963
|
-
const content = parts.join(', ');
|
|
964
|
-
return `\\left[${content}\\right]`;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
// Handle special case for coordinates
|
|
968
|
-
if (open === '(' && close === ')') {
|
|
969
|
-
const parts = renderChildren(children);
|
|
970
|
-
// Join parts with semicolon
|
|
971
|
-
const content = parts.join(';');
|
|
972
|
-
return `\\left(${content}\\right)`;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
const [left, right] = [
|
|
976
|
-
Brackets.parseLeft(open),
|
|
977
|
-
Brackets.parseRight(close)
|
|
978
|
-
];
|
|
979
|
-
|
|
980
|
-
const separators = separatorsStr.split('').filter((c) => c.trim().length === 1);
|
|
981
|
-
const template = `${left}@content${right}`;
|
|
982
|
-
const render = getRender_joinSeparators(template, separators);
|
|
983
|
-
return render(node, children);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
962
|
function renderMmultiscripts(node, children) {
|
|
987
963
|
if(children.length === 0) { return '' }
|
|
988
964
|
let sepIndex = -1;
|