Error
Using an explicit parenthesis such as nerdamer.convertToLaTeX("sin(30*(pi/180))") throws the following error.
Error [OperatorError]: Not a prefix operator
at new E (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:191:25)
at Parser.toRPN (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:6526:27)
at Parser.parse (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:6944:28)
at Object.latex (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:10166:33)
at Object.value (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:10375:37)
at Object.latex (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:10232:36)
at Parser.toTeX (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:7203:39)
at libExports.convertToLaTeX (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/node_modules/nerdamer/nerdamer.core.js:12070:18)
at Object.<anonymous> (/Users/rantoine/WebstormProjects/Users/rantoine/WebstormProjects/untitled/sandbox.js:12:22)
at Module._compile (node:internal/modules/cjs/loader:1688:14)
However, nerdamer.convertToLaTeX("sin(30*pi/180)") and nerdamer.convertToLaTeX("sin(30*parens(pi/180))") do not throw errors.
Solution
Using the parens function in front in place of any parentheses seems to solve the issue, so I created the following workaround.
// Adds " parens" in front of all (, but then removes it from in front of any reserved words
export const convertParens = (expr) => {
if(typeof expr !== "string" || !expr.includes("(")) return expr
expr = expr.replaceAll("(", " parens(")
nerdamer.reserved(true).forEach(w => {expr = expr.replaceAll(w+" parens", w)})
return expr
}
Error
Using an explicit parenthesis such as
nerdamer.convertToLaTeX("sin(30*(pi/180))")throws the following error.However,
nerdamer.convertToLaTeX("sin(30*pi/180)")andnerdamer.convertToLaTeX("sin(30*parens(pi/180))")do not throw errors.Solution
Using the parens function in front in place of any parentheses seems to solve the issue, so I created the following workaround.