Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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",
],
},
],
};

Original file line number Diff line number Diff line change
@@ -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",
],
},
],
};

12 changes: 12 additions & 0 deletions src/latex-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down