diff --git a/src/fixtures/latex-equal/symbolic/faiil_cases_trailing_zerosPD-4410.ts b/src/fixtures/latex-equal/symbolic/faiil_cases_trailing_zerosPD-4410.ts new file mode 100644 index 0000000..ce0c9ae --- /dev/null +++ b/src/fixtures/latex-equal/symbolic/faiil_cases_trailing_zerosPD-4410.ts @@ -0,0 +1,78 @@ +export default { + mode: "symbolic", + tests: [ + { + target: "12.35", + eq: [ + "12.350", "12.350000", + ], + }, + { + target: "10.2", + eq: [ + "10.20", + ], + }, + { + target: "5.05", + eq: [ + "5.050", + ], + }, + { + target: "5.4", + eq: [ + "5.40000", + ], + }, + { + target: "3.3", + eq: [ + "3.300", + ], + }, + { + target: "0.004", + eq: [ + "0.0040", + ], + }, + { + target: "5.7", + eq: [ + "5.70", + ], + }, + { + target: "23.598", + eq: [ + "23.5980", + ], + }, + { + target: "0.00278", + eq: [ + "0.002780", + ], + }, + { + target: "32.279", + eq: [ + "32.2790", + ], + }, + { + target: "0.65", + eq: [ + "0.650", + ], + }, + { + target: "45.3", + eq: [ + "45.300", + ], + }, + ], + }; + \ No newline at end of file diff --git a/src/fixtures/latex-equal/symbolic/success_cases_trailing_zerosPD-4410.ts b/src/fixtures/latex-equal/symbolic/success_cases_trailing_zerosPD-4410.ts new file mode 100644 index 0000000..7088b8b --- /dev/null +++ b/src/fixtures/latex-equal/symbolic/success_cases_trailing_zerosPD-4410.ts @@ -0,0 +1,72 @@ +export default { + mode: "symbolic", + tests: [ + { + target: "5.5", + eq: [ + "5.50", "5.50000", + ], + }, + { + target: "15", + eq: [ + "15.000", + ], + }, + { + target: "\\frac{5}{4}", + eq: [ + "1.25000", + ], + }, + { + target: "45", + eq: [ + "45.00", + ], + }, + { + target: "-45.3", + eq: [ + "-45.300", + ], + }, + { + target: "11.25", + eq: [ + "11.250", "11.2500", + ], + }, + { + target: "11.25x", + eq: [ + "11.2500x", + ], + }, + { + target: "0.75", + eq: [ + "0.750", + ], + }, + { + target: "16", + eq: [ + "16.00", + ], + }, + { + target: "1.30", + eq: [ + "1.300", + ], + }, + { + target: "8", + eq: [ + "8.0", + ], + }, + ], + }; + \ No newline at end of file diff --git a/src/latex-equal.ts b/src/latex-equal.ts index e0a41af..a4dba3d 100644 --- a/src/latex-equal.ts +++ b/src/latex-equal.ts @@ -17,6 +17,8 @@ const lta = new LatexToAst(); const atm = new AstToMathJs(); export const latexEqual = (a: Latex, b: Latex, opts: Opts) => { + const isNumeric = (str: string): boolean => /^-?\d+(\.\d+)?$/.test(str); + if (!a || !b) { return false; } @@ -25,6 +27,16 @@ export const latexEqual = (a: Latex, b: Latex, opts: Opts) => { return true; } + if (opts.mode === "symbolic" && isNumeric(a) && isNumeric(b)) { + const numA = parseFloat(a); + const numB = parseFloat(b); + + if (numA === numB) { + + return true; + } + } + const al = lta.convert(a); const bl = lta.convert(b);