Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 98ee4fb

Browse files
committed
fix!: add regex to remove the \sin syntax (#13)
1 parent 8c89603 commit 98ee4fb

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

public/src/app/graphs/page.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,36 @@ export default function DesmosGraphPage(): React.JSX.Element {
6666
useEffect(() => {
6767
if (graphRef.current) {
6868
const allExpressions = functions.map((func, index) => {
69-
const expr = func.expression.trim();
70-
let latexExpression = expr;
69+
let expr = func.expression.trim();
70+
71+
// A mapping of common functions to their LaTeX commands
72+
const latexFunctions: { [key: string]: string } = {
73+
sin: "\\sin",
74+
cos: "\\cos",
75+
tan: "\\tan",
76+
csc: "\\csc",
77+
sec: "\\sec",
78+
cot: "\\cot",
79+
log: "\\log",
80+
ln: "\\ln",
81+
sqrt: "\\sqrt",
82+
};
83+
84+
for (const funcName in latexFunctions) {
85+
const regex = new RegExp(`(?<!\\\\)\\b${funcName}\\b`, "g");
86+
expr = expr.replace(regex, latexFunctions[funcName]);
87+
}
88+
7189
if (
7290
!expr.includes("=") &&
7391
!(expr.startsWith("(") && expr.endsWith(")"))
7492
) {
75-
latexExpression = `y=${expr}`;
93+
expr = `y=${expr}`;
7694
}
95+
7796
return {
7897
id: `func-${func.id}`,
79-
latex: latexExpression,
98+
latex: expr,
8099
color: PLOT_COLORS[index % PLOT_COLORS.length],
81100
};
82101
});

0 commit comments

Comments
 (0)