ed-mathml2tex 0.1.4 → 0.1.6

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.
@@ -643,15 +643,16 @@ function toLatex(result) {
643
643
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
644
644
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
645
645
 
646
+ // Remove or comment out these lines in toLatex function
646
647
  // Thêm xử lý các ký hiệu toán học phổ biến
647
- result = result.replace(/≤/g, "\\leq");
648
- result = result.replace(/≥/g, "\\geq");
649
- result = result.replace(/≠/g, "\\neq");
650
- result = result.replace(/≈/g, "\\approx");
651
- result = result.replace(/π/g, "\\pi");
652
- result = result.replace(/α/g, "\\alpha");
653
- result = result.replace(/β/g, "\\beta");
654
- result = result.replace(/γ/g, "\\gamma");
648
+ // result = result.replace(/≤/g, "\\leq");
649
+ // result = result.replace(/≥/g, "\\geq");
650
+ // result = result.replace(/≠/g, "\\neq");
651
+ // result = result.replace(/≈/g, "\\approx");
652
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
653
+ // result = result.replace(/α/g, "\\alpha");
654
+ // result = result.replace(/β/g, "\\beta");
655
+ // result = result.replace(/γ/g, "\\gamma");
655
656
 
656
657
  return result;
657
658
  }
@@ -774,9 +775,25 @@ function parseElementMs(node) {
774
775
 
775
776
  // Math Text
776
777
  function parseElementMtext(node) {
777
- const content = NodeTool.getNodeText(node);
778
- const it = escapeSpecialChars(content);
779
- return `\\text{${it}}`;
778
+ let content = NodeTool.getNodeText(node)
779
+ // Handle operators and spacing only
780
+ .replace(/\s*=\s*/g, ' = ')
781
+ .replace(/\s*\.\s*/g, ' \\cdot ')
782
+ .trim();
783
+
784
+ // Handle units with proper \mathrm formatting
785
+ if (content.includes('(') && content.includes(')')) {
786
+ const parts = content.split(/(\([^)]+\))/);
787
+ content = parts.map(part => {
788
+ if (part.startsWith('(') && part.endsWith(')')) {
789
+ // Keep original characters in units
790
+ return `\\mathrm{${part}}`;
791
+ }
792
+ return part;
793
+ }).join('');
794
+ }
795
+
796
+ return content;
780
797
  }
781
798
 
782
799
  // Math glyph (image)
@@ -919,6 +936,14 @@ function getRender(node) {
919
936
  return getRender_joinSeparator("@content")(node, childrenArray);
920
937
  }
921
938
 
939
+ if (firstOp === '[' && lastOp === ']') {
940
+ const innerContent = childrenArray
941
+ .slice(1, -1)
942
+ .map(child => parse(child))
943
+ .join('');
944
+ return `[${innerContent}]`;
945
+ }
946
+
922
947
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
923
948
  if (firstOp === '[') {
924
949
  const innerContent = childrenArray
@@ -1070,6 +1095,12 @@ function getRender(node) {
1070
1095
  const over = parse(childrenArray[2]);
1071
1096
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1072
1097
 
1098
+ // Special handling for chemical reaction arrow
1099
+ if (baseText === '→' &&
1100
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1101
+ return `\\xrightarrow[${under}]{${over}}`;
1102
+ }
1103
+
1073
1104
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1074
1105
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1075
1106
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
@@ -641,15 +641,16 @@ function toLatex(result) {
641
641
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
642
642
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
643
643
 
644
+ // Remove or comment out these lines in toLatex function
644
645
  // Thêm xử lý các ký hiệu toán học phổ biến
645
- result = result.replace(/≤/g, "\\leq");
646
- result = result.replace(/≥/g, "\\geq");
647
- result = result.replace(/≠/g, "\\neq");
648
- result = result.replace(/≈/g, "\\approx");
649
- result = result.replace(/π/g, "\\pi");
650
- result = result.replace(/α/g, "\\alpha");
651
- result = result.replace(/β/g, "\\beta");
652
- result = result.replace(/γ/g, "\\gamma");
646
+ // result = result.replace(/≤/g, "\\leq");
647
+ // result = result.replace(/≥/g, "\\geq");
648
+ // result = result.replace(/≠/g, "\\neq");
649
+ // result = result.replace(/≈/g, "\\approx");
650
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
651
+ // result = result.replace(/α/g, "\\alpha");
652
+ // result = result.replace(/β/g, "\\beta");
653
+ // result = result.replace(/γ/g, "\\gamma");
653
654
 
654
655
  return result;
655
656
  }
@@ -772,9 +773,25 @@ function parseElementMs(node) {
772
773
 
773
774
  // Math Text
774
775
  function parseElementMtext(node) {
775
- const content = NodeTool.getNodeText(node);
776
- const it = escapeSpecialChars(content);
777
- return `\\text{${it}}`;
776
+ let content = NodeTool.getNodeText(node)
777
+ // Handle operators and spacing only
778
+ .replace(/\s*=\s*/g, ' = ')
779
+ .replace(/\s*\.\s*/g, ' \\cdot ')
780
+ .trim();
781
+
782
+ // Handle units with proper \mathrm formatting
783
+ if (content.includes('(') && content.includes(')')) {
784
+ const parts = content.split(/(\([^)]+\))/);
785
+ content = parts.map(part => {
786
+ if (part.startsWith('(') && part.endsWith(')')) {
787
+ // Keep original characters in units
788
+ return `\\mathrm{${part}}`;
789
+ }
790
+ return part;
791
+ }).join('');
792
+ }
793
+
794
+ return content;
778
795
  }
779
796
 
780
797
  // Math glyph (image)
@@ -917,6 +934,14 @@ function getRender(node) {
917
934
  return getRender_joinSeparator("@content")(node, childrenArray);
918
935
  }
919
936
 
937
+ if (firstOp === '[' && lastOp === ']') {
938
+ const innerContent = childrenArray
939
+ .slice(1, -1)
940
+ .map(child => parse(child))
941
+ .join('');
942
+ return `[${innerContent}]`;
943
+ }
944
+
920
945
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
921
946
  if (firstOp === '[') {
922
947
  const innerContent = childrenArray
@@ -1068,6 +1093,12 @@ function getRender(node) {
1068
1093
  const over = parse(childrenArray[2]);
1069
1094
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1070
1095
 
1096
+ // Special handling for chemical reaction arrow
1097
+ if (baseText === '→' &&
1098
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1099
+ return `\\xrightarrow[${under}]{${over}}`;
1100
+ }
1101
+
1071
1102
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1072
1103
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1073
1104
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
@@ -647,15 +647,16 @@
647
647
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
648
648
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
649
649
 
650
+ // Remove or comment out these lines in toLatex function
650
651
  // Thêm xử lý các ký hiệu toán học phổ biến
651
- result = result.replace(/≤/g, "\\leq");
652
- result = result.replace(/≥/g, "\\geq");
653
- result = result.replace(/≠/g, "\\neq");
654
- result = result.replace(/≈/g, "\\approx");
655
- result = result.replace(/π/g, "\\pi");
656
- result = result.replace(/α/g, "\\alpha");
657
- result = result.replace(/β/g, "\\beta");
658
- result = result.replace(/γ/g, "\\gamma");
652
+ // result = result.replace(/≤/g, "\\leq");
653
+ // result = result.replace(/≥/g, "\\geq");
654
+ // result = result.replace(/≠/g, "\\neq");
655
+ // result = result.replace(/≈/g, "\\approx");
656
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
657
+ // result = result.replace(/α/g, "\\alpha");
658
+ // result = result.replace(/β/g, "\\beta");
659
+ // result = result.replace(/γ/g, "\\gamma");
659
660
 
660
661
  return result;
661
662
  }
@@ -778,9 +779,25 @@
778
779
 
779
780
  // Math Text
780
781
  function parseElementMtext(node) {
781
- const content = NodeTool.getNodeText(node);
782
- const it = escapeSpecialChars(content);
783
- return `\\text{${it}}`;
782
+ let content = NodeTool.getNodeText(node)
783
+ // Handle operators and spacing only
784
+ .replace(/\s*=\s*/g, ' = ')
785
+ .replace(/\s*\.\s*/g, ' \\cdot ')
786
+ .trim();
787
+
788
+ // Handle units with proper \mathrm formatting
789
+ if (content.includes('(') && content.includes(')')) {
790
+ const parts = content.split(/(\([^)]+\))/);
791
+ content = parts.map(part => {
792
+ if (part.startsWith('(') && part.endsWith(')')) {
793
+ // Keep original characters in units
794
+ return `\\mathrm{${part}}`;
795
+ }
796
+ return part;
797
+ }).join('');
798
+ }
799
+
800
+ return content;
784
801
  }
785
802
 
786
803
  // Math glyph (image)
@@ -923,6 +940,14 @@
923
940
  return getRender_joinSeparator("@content")(node, childrenArray);
924
941
  }
925
942
 
943
+ if (firstOp === '[' && lastOp === ']') {
944
+ const innerContent = childrenArray
945
+ .slice(1, -1)
946
+ .map(child => parse(child))
947
+ .join('');
948
+ return `[${innerContent}]`;
949
+ }
950
+
926
951
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
927
952
  if (firstOp === '[') {
928
953
  const innerContent = childrenArray
@@ -1074,6 +1099,12 @@
1074
1099
  const over = parse(childrenArray[2]);
1075
1100
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1076
1101
 
1102
+ // Special handling for chemical reaction arrow
1103
+ if (baseText === '→' &&
1104
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1105
+ return `\\xrightarrow[${under}]{${over}}`;
1106
+ }
1107
+
1077
1108
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1078
1109
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1079
1110
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
@@ -643,15 +643,16 @@ function toLatex(result) {
643
643
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
644
644
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
645
645
 
646
+ // Remove or comment out these lines in toLatex function
646
647
  // Thêm xử lý các ký hiệu toán học phổ biến
647
- result = result.replace(/≤/g, "\\leq");
648
- result = result.replace(/≥/g, "\\geq");
649
- result = result.replace(/≠/g, "\\neq");
650
- result = result.replace(/≈/g, "\\approx");
651
- result = result.replace(/π/g, "\\pi");
652
- result = result.replace(/α/g, "\\alpha");
653
- result = result.replace(/β/g, "\\beta");
654
- result = result.replace(/γ/g, "\\gamma");
648
+ // result = result.replace(/≤/g, "\\leq");
649
+ // result = result.replace(/≥/g, "\\geq");
650
+ // result = result.replace(/≠/g, "\\neq");
651
+ // result = result.replace(/≈/g, "\\approx");
652
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
653
+ // result = result.replace(/α/g, "\\alpha");
654
+ // result = result.replace(/β/g, "\\beta");
655
+ // result = result.replace(/γ/g, "\\gamma");
655
656
 
656
657
  return result;
657
658
  }
@@ -774,9 +775,25 @@ function parseElementMs(node) {
774
775
 
775
776
  // Math Text
776
777
  function parseElementMtext(node) {
777
- const content = NodeTool.getNodeText(node);
778
- const it = escapeSpecialChars(content);
779
- return `\\text{${it}}`;
778
+ let content = NodeTool.getNodeText(node)
779
+ // Handle operators and spacing only
780
+ .replace(/\s*=\s*/g, ' = ')
781
+ .replace(/\s*\.\s*/g, ' \\cdot ')
782
+ .trim();
783
+
784
+ // Handle units with proper \mathrm formatting
785
+ if (content.includes('(') && content.includes(')')) {
786
+ const parts = content.split(/(\([^)]+\))/);
787
+ content = parts.map(part => {
788
+ if (part.startsWith('(') && part.endsWith(')')) {
789
+ // Keep original characters in units
790
+ return `\\mathrm{${part}}`;
791
+ }
792
+ return part;
793
+ }).join('');
794
+ }
795
+
796
+ return content;
780
797
  }
781
798
 
782
799
  // Math glyph (image)
@@ -919,6 +936,14 @@ function getRender(node) {
919
936
  return getRender_joinSeparator("@content")(node, childrenArray);
920
937
  }
921
938
 
939
+ if (firstOp === '[' && lastOp === ']') {
940
+ const innerContent = childrenArray
941
+ .slice(1, -1)
942
+ .map(child => parse(child))
943
+ .join('');
944
+ return `[${innerContent}]`;
945
+ }
946
+
922
947
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
923
948
  if (firstOp === '[') {
924
949
  const innerContent = childrenArray
@@ -1070,6 +1095,12 @@ function getRender(node) {
1070
1095
  const over = parse(childrenArray[2]);
1071
1096
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1072
1097
 
1098
+ // Special handling for chemical reaction arrow
1099
+ if (baseText === '→' &&
1100
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1101
+ return `\\xrightarrow[${under}]{${over}}`;
1102
+ }
1103
+
1073
1104
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1074
1105
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1075
1106
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
@@ -641,15 +641,16 @@ function toLatex(result) {
641
641
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
642
642
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
643
643
 
644
+ // Remove or comment out these lines in toLatex function
644
645
  // Thêm xử lý các ký hiệu toán học phổ biến
645
- result = result.replace(/≤/g, "\\leq");
646
- result = result.replace(/≥/g, "\\geq");
647
- result = result.replace(/≠/g, "\\neq");
648
- result = result.replace(/≈/g, "\\approx");
649
- result = result.replace(/π/g, "\\pi");
650
- result = result.replace(/α/g, "\\alpha");
651
- result = result.replace(/β/g, "\\beta");
652
- result = result.replace(/γ/g, "\\gamma");
646
+ // result = result.replace(/≤/g, "\\leq");
647
+ // result = result.replace(/≥/g, "\\geq");
648
+ // result = result.replace(/≠/g, "\\neq");
649
+ // result = result.replace(/≈/g, "\\approx");
650
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
651
+ // result = result.replace(/α/g, "\\alpha");
652
+ // result = result.replace(/β/g, "\\beta");
653
+ // result = result.replace(/γ/g, "\\gamma");
653
654
 
654
655
  return result;
655
656
  }
@@ -772,9 +773,25 @@ function parseElementMs(node) {
772
773
 
773
774
  // Math Text
774
775
  function parseElementMtext(node) {
775
- const content = NodeTool.getNodeText(node);
776
- const it = escapeSpecialChars(content);
777
- return `\\text{${it}}`;
776
+ let content = NodeTool.getNodeText(node)
777
+ // Handle operators and spacing only
778
+ .replace(/\s*=\s*/g, ' = ')
779
+ .replace(/\s*\.\s*/g, ' \\cdot ')
780
+ .trim();
781
+
782
+ // Handle units with proper \mathrm formatting
783
+ if (content.includes('(') && content.includes(')')) {
784
+ const parts = content.split(/(\([^)]+\))/);
785
+ content = parts.map(part => {
786
+ if (part.startsWith('(') && part.endsWith(')')) {
787
+ // Keep original characters in units
788
+ return `\\mathrm{${part}}`;
789
+ }
790
+ return part;
791
+ }).join('');
792
+ }
793
+
794
+ return content;
778
795
  }
779
796
 
780
797
  // Math glyph (image)
@@ -917,6 +934,14 @@ function getRender(node) {
917
934
  return getRender_joinSeparator("@content")(node, childrenArray);
918
935
  }
919
936
 
937
+ if (firstOp === '[' && lastOp === ']') {
938
+ const innerContent = childrenArray
939
+ .slice(1, -1)
940
+ .map(child => parse(child))
941
+ .join('');
942
+ return `[${innerContent}]`;
943
+ }
944
+
920
945
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
921
946
  if (firstOp === '[') {
922
947
  const innerContent = childrenArray
@@ -1068,6 +1093,12 @@ function getRender(node) {
1068
1093
  const over = parse(childrenArray[2]);
1069
1094
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1070
1095
 
1096
+ // Special handling for chemical reaction arrow
1097
+ if (baseText === '→' &&
1098
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1099
+ return `\\xrightarrow[${under}]{${over}}`;
1100
+ }
1101
+
1071
1102
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1072
1103
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1073
1104
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
@@ -647,15 +647,16 @@
647
647
  result = result.replace(/([A-Za-z0-9]+)_([0-9])\^\{\\rightarrow\}/g, "\\overrightarrow{$1_$2}");
648
648
  result = result.replace(/(\([^()]+\))\^\{\\rightarrow\}/g, "\\overrightarrow{$1}");
649
649
 
650
+ // Remove or comment out these lines in toLatex function
650
651
  // Thêm xử lý các ký hiệu toán học phổ biến
651
- result = result.replace(/≤/g, "\\leq");
652
- result = result.replace(/≥/g, "\\geq");
653
- result = result.replace(/≠/g, "\\neq");
654
- result = result.replace(/≈/g, "\\approx");
655
- result = result.replace(/π/g, "\\pi");
656
- result = result.replace(/α/g, "\\alpha");
657
- result = result.replace(/β/g, "\\beta");
658
- result = result.replace(/γ/g, "\\gamma");
652
+ // result = result.replace(/≤/g, "\\leq");
653
+ // result = result.replace(/≥/g, "\\geq");
654
+ // result = result.replace(/≠/g, "\\neq");
655
+ // result = result.replace(/≈/g, "\\approx");
656
+ // result = result.replace(/π/g, "\\pi"); // Comment out or remove this line
657
+ // result = result.replace(/α/g, "\\alpha");
658
+ // result = result.replace(/β/g, "\\beta");
659
+ // result = result.replace(/γ/g, "\\gamma");
659
660
 
660
661
  return result;
661
662
  }
@@ -778,9 +779,25 @@
778
779
 
779
780
  // Math Text
780
781
  function parseElementMtext(node) {
781
- const content = NodeTool.getNodeText(node);
782
- const it = escapeSpecialChars(content);
783
- return `\\text{${it}}`;
782
+ let content = NodeTool.getNodeText(node)
783
+ // Handle operators and spacing only
784
+ .replace(/\s*=\s*/g, ' = ')
785
+ .replace(/\s*\.\s*/g, ' \\cdot ')
786
+ .trim();
787
+
788
+ // Handle units with proper \mathrm formatting
789
+ if (content.includes('(') && content.includes(')')) {
790
+ const parts = content.split(/(\([^)]+\))/);
791
+ content = parts.map(part => {
792
+ if (part.startsWith('(') && part.endsWith(')')) {
793
+ // Keep original characters in units
794
+ return `\\mathrm{${part}}`;
795
+ }
796
+ return part;
797
+ }).join('');
798
+ }
799
+
800
+ return content;
784
801
  }
785
802
 
786
803
  // Math glyph (image)
@@ -923,6 +940,14 @@
923
940
  return getRender_joinSeparator("@content")(node, childrenArray);
924
941
  }
925
942
 
943
+ if (firstOp === '[' && lastOp === ']') {
944
+ const innerContent = childrenArray
945
+ .slice(1, -1)
946
+ .map(child => parse(child))
947
+ .join('');
948
+ return `[${innerContent}]`;
949
+ }
950
+
926
951
  // Xử lý đặc biệt cho dấu ngoặc vuông chứa mtable
927
952
  if (firstOp === '[') {
928
953
  const innerContent = childrenArray
@@ -1074,6 +1099,12 @@
1074
1099
  const over = parse(childrenArray[2]);
1075
1100
  const baseText = NodeTool.getNodeText(childrenArray[0]).trim();
1076
1101
 
1102
+ // Special handling for chemical reaction arrow
1103
+ if (baseText === '→' &&
1104
+ NodeTool.getNodeName(childrenArray[1]) === 'msup') {
1105
+ return `\\xrightarrow[${under}]{${over}}`;
1106
+ }
1107
+
1077
1108
  if (baseText === '∫') return `\\int_{${under}}^{${over}}`;
1078
1109
  if (baseText === '∑') return `\\sum_{${under}}^{${over}}`;
1079
1110
  if (baseText === '∏') return `\\prod_{${under}}^{${over}}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ed-mathml2tex",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Convert mathml to latex.",
5
5
  "author": "Mika",
6
6
  "license": "MIT",