Discontinuity Midpoint Convergence:
diff --git a/src/lib/math-engine/circuits.ts b/src/lib/math-engine/circuits.ts
index 6d1e83e5..39d68b60 100644
--- a/src/lib/math-engine/circuits.ts
+++ b/src/lib/math-engine/circuits.ts
@@ -420,7 +420,7 @@ export function createCircuitProblem(
id: `circuit-${topology}-${Date.now()}`,
topology,
components: { ...components },
- promptLatex: `\\text{Derive the transfer function } H(s) \\text{ for the } \\text{${name}} \\text{ with } R = ${R}\\Omega${circuitUsesInductor(topology) ? `, L = ${L}\\text{H}` : ""}${circuitUsesCapacitor(topology) ? `, C = ${C}\\text{F}` : ""}.`,
+ promptLatex: String.raw`\text{Derive the transfer function } H(s) \text{ for the } \text{${name}} \text{ with } R = ${R}\Omega${circuitUsesInductor(topology) ? String.raw`, L = ${L}\text{H}` : ""}${circuitUsesCapacitor(topology) ? String.raw`, C = ${C}\text{F}` : ""}.`,
referenceAnswerLatex: tf.hLatex,
solutionSteps: [
{
@@ -429,11 +429,11 @@ export function createCircuitProblem(
},
{
title: "Step 2: Apply Voltage Divider / Node Voltage Equations",
- latex: `H(s) = \\frac{Z_{out}(s)}{Z_{in}(s)} = ${tf.hLatex}`,
+ latex: String.raw`H(s) = \frac{Z_{out}(s)}{Z_{in}(s)} = ${tf.hLatex}`,
},
{
title: "Step 3: Identify Characteristic Parameters",
- latex: `\\text{Derived Transfer Function } H(s) = ${tf.hLatex}`,
+ latex: String.raw`\text{Derived Transfer Function } H(s) = ${tf.hLatex}`,
},
],
};
diff --git a/src/lib/math-engine/convolution/configuration.ts b/src/lib/math-engine/convolution/configuration.ts
index 7d3aa002..5e923e61 100644
--- a/src/lib/math-engine/convolution/configuration.ts
+++ b/src/lib/math-engine/convolution/configuration.ts
@@ -288,8 +288,8 @@ export function resolveConvolutionSignal(
latex: scaleLatex(
amplitude,
parameter === 2
- ? `\\Delta\\left(${argument}\\right)`
- : `\\Delta\\left(\\frac{2(${argument})}{${parameter}}\\right)`,
+ ? String.raw`\Delta\left(${argument}\right)`
+ : String.raw`\Delta\left(\frac{2(${argument})}{${parameter}}\right)`,
),
sections: [section(`${key}-1`, start, end)],
breakpoints: [start, shift, end],
diff --git a/src/lib/math-engine/convolution/configured-solver.ts b/src/lib/math-engine/convolution/configured-solver.ts
index 45ec41dc..e1e887ad 100644
--- a/src/lib/math-engine/convolution/configured-solver.ts
+++ b/src/lib/math-engine/convolution/configured-solver.ts
@@ -41,7 +41,7 @@ function scalarLatex(value: number, absolute = false): string {
const numerator = absolute ? Math.abs(rawNumerator) : rawNumerator;
return denominator === 1
? String(numerator)
- : `\\frac{${numerator}}{${denominator}}`;
+ : String.raw`\frac{${numerator}}{${denominator}}`;
}
function polynomialLatex(polynomial: Polynomial): string {
@@ -84,8 +84,8 @@ function uniqueSorted(values: number[]): number[] {
function intervalLabel(min: number, max: number): string {
if (!Number.isFinite(min)) return `t < ${scalarLatex(max)}`;
- if (!Number.isFinite(max)) return `t \\ge ${scalarLatex(min)}`;
- return `${scalarLatex(min)} \\le t < ${scalarLatex(max)}`;
+ if (!Number.isFinite(max)) return String.raw`t \ge ${scalarLatex(min)}`;
+ return String.raw`${scalarLatex(min)} \le t < ${scalarLatex(max)}`;
}
function intervalRanges(boundaries: number[]): Array<[number, number]> {
@@ -338,7 +338,7 @@ function solveExponentials(
const equalRates = Math.abs(x.parameter - h.parameter) < EPSILON;
const activeExpression = equalRates
? `${scalarLatex(coefficient)}(${formatShiftedTime(onset)})e^{-${x.parameter}(${formatShiftedTime(onset)})}`
- : `\\frac{${scalarLatex(coefficient)}}{${scalarLatex(h.parameter - x.parameter)}}\\left(e^{-${x.parameter}(${formatShiftedTime(onset)})}-e^{-${h.parameter}(${formatShiftedTime(onset)})}\\right)`;
+ : String.raw`\frac{${scalarLatex(coefficient)}}{${scalarLatex(h.parameter - x.parameter)}}\left(e^{-${x.parameter}(${formatShiftedTime(onset)})}-e^{-${h.parameter}(${formatShiftedTime(onset)})}\right)`;
const activeEval = (t: number): number => {
if (t < onset) return 0;
const elapsed = t - onset;
diff --git a/src/lib/math-engine/convolution/engine.ts b/src/lib/math-engine/convolution/engine.ts
index 0623acdc..d6362907 100644
--- a/src/lib/math-engine/convolution/engine.ts
+++ b/src/lib/math-engine/convolution/engine.ts
@@ -221,13 +221,13 @@ export function generateConfiguredConvolutionProblem(
title: "Identify the Two Configured Signals",
description:
"Record each signal's exact support, breakpoints, amplitude, and translation.",
- latex: `x(t)=${resolvedSignals.x.latex},\\quad h(t)=${resolvedSignals.h.latex}`,
+ latex: String.raw`x(t)=${resolvedSignals.x.latex},\quad h(t)=${resolvedSignals.h.latex}`,
},
{
title: "Build Every Geometric Overlap Region",
description:
"Add fixed and moving breakpoints, then integrate every connected overlap component.",
- latex: "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(t-\\tau)\\,d\\tau",
+ latex: String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(t-\tau)\,d\tau`,
},
{
title: "Combine Signed Contributions",
@@ -236,9 +236,9 @@ export function generateConfiguredConvolutionProblem(
latex: result.intervals
.map(
(interval) =>
- `y(t)=${interval.exprLatex}\\quad(${interval.labelLatex})`,
+ String.raw`y(t)=${interval.exprLatex}\quad(${interval.labelLatex})`,
)
- .join(",\\quad "),
+ .join(String.raw`,\quad `),
},
],
intervals: result.intervals,
diff --git a/src/lib/math-engine/convolution/its-scaffolding/evaluation-terms.ts b/src/lib/math-engine/convolution/its-scaffolding/evaluation-terms.ts
index fc55524a..e7d56a07 100644
--- a/src/lib/math-engine/convolution/its-scaffolding/evaluation-terms.ts
+++ b/src/lib/math-engine/convolution/its-scaffolding/evaluation-terms.ts
@@ -53,20 +53,20 @@ function polynomialEvaluationTerm(
String.raw`\tau`,
);
const movingPieceLatex = sanitizeLatexMath(
- `${formatConvolutionScalar(b0)}+${formatConvolutionScalar(b1)}(t-\\tau)`,
+ String.raw`${formatConvolutionScalar(b0)}+${formatConvolutionScalar(b1)}(t-\tau)`,
);
const p0 = `(${formatConvolutionScalar(a0)})(${formatConvolutionScalar(b0)}+${formatConvolutionScalar(b1)}t)`;
const p1 = `(${formatConvolutionScalar(a1)})(${formatConvolutionScalar(b0)}+${formatConvolutionScalar(b1)}t)-${formatConvolutionScalar(a0 * b1)}`;
const p2 = formatConvolutionScalar(-a1 * b1);
const integrandLatex = sanitizeLatexMath(
- `${p0}+(${p1})\\tau+(${p2})\\tau^2`,
+ String.raw`${p0}+(${p1})\tau+(${p2})\tau^2`,
);
const primitiveLatex = sanitizeLatexMath(
- `F(\\tau,t)=(${p0})\\tau+\\frac{(${p1})\\tau^2}{2}+\\frac{(${p2})\\tau^3}{3}`,
+ String.raw`F(\tau,t)=(${p0})\tau+\frac{(${p1})\tau^2}{2}+\frac{(${p2})\tau^3}{3}`,
);
const substitute = (bound: string): string =>
sanitizeLatexMath(
- `(${p0})(${bound})+\\frac{(${p1})(${bound})^2}{2}+\\frac{(${p2})(${bound})^3}{3}`,
+ String.raw`(${p0})(${bound})+\frac{(${p1})(${bound})^2}{2}+\frac{(${p2})(${bound})^3}{3}`,
);
const upperSubstitutionLatex = substitute(upperLatex);
const lowerSubstitutionLatex = substitute(lowerLatex);
@@ -166,13 +166,13 @@ function exponentialPrimitive(
rate: number,
): string {
if (Math.abs(rate) < 1e-12)
- return `${prefactor}((${timeFactor(coefficients)})\\tau${slope === 0 ? "" : `+(${toFractionLatex(slope / 2)})\\tau^2`})`;
+ return String.raw`${prefactor}((${timeFactor(coefficients)})\tau${slope === 0 ? "" : String.raw`+(${toFractionLatex(slope / 2)})\tau^2`})`;
const q0 = timeFactor([
coefficients[0] / rate - slope / (rate * rate),
coefficients[1] / rate,
]);
const q1 = slope / rate;
- return `${prefactor}e^{${formatConvolutionScalar(rate)}\\tau}((${q0})${q1 === 0 ? "" : `+(${toFractionLatex(q1)})\\tau`})`;
+ return String.raw`${prefactor}e^{${formatConvolutionScalar(rate)}\tau}((${q0})${q1 === 0 ? "" : String.raw`+(${toFractionLatex(q1)})\tau`})`;
}
/**
@@ -226,9 +226,9 @@ function exponentialEvaluationTerm(
const exponential =
Math.abs(exponentRate) < 1e-12
? ""
- : `e^{${formatConvolutionScalar(exponentRate)}\\tau}`;
+ : String.raw`e^{${formatConvolutionScalar(exponentRate)}\tau}`;
const integrandLatex = sanitizeLatexMath(
- `${prefactor}((${constant})${slope === 0 ? "" : `+(${toFractionLatex(slope)})\\tau`})${exponential}`,
+ String.raw`${prefactor}((${constant})${slope === 0 ? "" : String.raw`+(${toFractionLatex(slope)})\tau`})${exponential}`,
);
const primitiveBody = exponentialPrimitive(
prefactor,
@@ -236,7 +236,9 @@ function exponentialEvaluationTerm(
slope,
exponentRate,
);
- const primitiveLatex = sanitizeLatexMath(`F(\\tau,t)=${primitiveBody}`);
+ const primitiveLatex = sanitizeLatexMath(
+ String.raw`F(\tau,t)=${primitiveBody}`,
+ );
/** @param bound - Verified limit. @returns Primitive evaluated at that limit. */
const substitute = (bound: string): string =>
sanitizeLatexMath(
diff --git a/src/lib/math-engine/convolution/its-scaffolding/helpers.ts b/src/lib/math-engine/convolution/its-scaffolding/helpers.ts
index 727794e6..8a158a05 100644
--- a/src/lib/math-engine/convolution/its-scaffolding/helpers.ts
+++ b/src/lib/math-engine/convolution/its-scaffolding/helpers.ts
@@ -88,8 +88,8 @@ function buildTransitionGroups(
? `${moving}-${groupId}-contact-1`
: undefined,
formulationHints: [
- `The fixed breakpoint is $\\tau=${formatConvolutionScalar(fixed)}$.`,
- `After reflection and translation, moving breakpoint $${formatConvolutionScalar(movingPoint)}$ appears at $\\tau=${transformedLatex}$.`,
+ String.raw`The fixed breakpoint is $\tau=${formatConvolutionScalar(fixed)}$.`,
+ String.raw`After reflection and translation, moving breakpoint $${formatConvolutionScalar(movingPoint)}$ appears at $\tau=${transformedLatex}$.`,
`Set the breakpoint positions equal: $${equationLatex}$.`,
],
solutionHints: [
@@ -135,7 +135,7 @@ function timingPart(
start,
end,
width,
- resultLatex: `${id}_{\\mathrm{${id === "y" ? "overlap,start" : "start"}}}=${formatConvolutionScalar(start)},\\quad ${id}_{\\mathrm{${id === "y" ? "overlap,end" : "end"}}}=${formatConvolutionScalar(end)},\\quad W_{${id}${id === "y" ? ",\\mathrm{overlap}" : ""}}=${formatConvolutionScalar(width)}`,
+ resultLatex: String.raw`${id}_{\mathrm{${id === "y" ? "overlap,start" : "start"}}}=${formatConvolutionScalar(start)},\quad ${id}_{\mathrm{${id === "y" ? "overlap,end" : "end"}}}=${formatConvolutionScalar(end)},\quad W_{${id}${id === "y" ? String.raw`,\mathrm{overlap}` : ""}}=${formatConvolutionScalar(width)}`,
hints:
id === "y"
? [
@@ -194,7 +194,7 @@ export function buildConvolutionItsData(
const definitionOptions = [
{
id: "convolution-integral",
- latex: "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(t-\\tau)\\,d\\tau",
+ latex: String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(t-\tau)\,d\tau`,
isCorrect: true,
},
{
@@ -206,14 +206,13 @@ export function buildConvolutionItsData(
},
{
id: "correlation-integral",
- latex: "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(\\tau-t)\\,d\\tau",
+ latex: String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(\tau-t)\,d\tau`,
isCorrect: false,
- feedback:
- "The moving argument has the wrong orientation; reflection requires $t-\\tau$.",
+ feedback: String.raw`The moving argument has the wrong orientation; reflection requires $t-\tau$.`,
},
{
id: "outside-variable",
- latex: "y(t)=x(t)\\int_{-\\infty}^{\\infty}h(t-\\tau)\\,d\\tau",
+ latex: String.raw`y(t)=x(t)\int_{-\infty}^{\infty}h(t-\tau)\,d\tau`,
isCorrect: false,
feedback:
"Both signals must depend on the integration variable inside the convolution integral.",
@@ -245,8 +244,8 @@ export function buildConvolutionItsData(
options: shuffledDefinitionOptions,
hints: [
"Convolution combines reflection, translation, multiplication, and integration.",
- "Use $\\tau$ as the integration variable while $t$ remains a parameter.",
- "One signal is fixed in $\\tau$ and the other uses $t-\\tau$.",
+ String.raw`Use $\tau$ as the integration variable while $t$ remains a parameter.`,
+ String.raw`One signal is fixed in $\tau$ and the other uses $t-\tau$.`,
],
},
step3: {
@@ -266,7 +265,7 @@ export function buildConvolutionItsData(
},
choiceHints: [
"Both choices produce the same convolution because convolution is commutative.",
- "Keep one signal fixed in $\\tau$ and reflect and translate the other.",
+ String.raw`Keep one signal fixed in $\tau$ and reflect and translate the other.`,
"Choose the shape whose reflected edges are easiest for you to track.",
],
edgeHints: [
@@ -336,7 +335,7 @@ export function buildConvolutionItsData(
intervalBuilderHints: [
"Use the verified transition times from smallest to largest.",
"The first interval is left-unbounded and the final interval is right-unbounded.",
- `The ordered boundaries are $${intervalBoundaries.map(formatConvolutionScalar).join(",\\;")}$.`,
+ String.raw`The ordered boundaries are $${intervalBoundaries.map(formatConvolutionScalar).join(String.raw`,\;`)}$.`,
],
},
step5: {
diff --git a/src/lib/math-engine/convolution/its-scaffolding/intervals.ts b/src/lib/math-engine/convolution/its-scaffolding/intervals.ts
index 16c475d3..e9724354 100644
--- a/src/lib/math-engine/convolution/its-scaffolding/intervals.ts
+++ b/src/lib/math-engine/convolution/its-scaffolding/intervals.ts
@@ -120,7 +120,7 @@ function buildPathSetup(
.slice(0, -1)
.map(
(lower, index) =>
- `\\int_{${lower}}^{${boundaries[index + 1]}}${fixedName}(\\tau)${movingSignal}(t-\\tau)\\,d\\tau`,
+ String.raw`\int_{${lower}}^{${boundaries[index + 1]}}${fixedName}(\tau)${movingSignal}(t-\tau)\,d\tau`,
);
});
return {
@@ -167,10 +167,10 @@ export function buildSetupPart(
];
const lowerCandidates = setup.overlaps
.map(({ lowerCandidatesLatex }) => lowerCandidatesLatex.join(","))
- .join(";\\;");
+ .join(String.raw`;\;`);
const upperCandidates = setup.overlaps
.map(({ upperCandidatesLatex }) => upperCandidatesLatex.join(","))
- .join(";\\;");
+ .join(String.raw`;\;`);
const splitPoints = setup.overlaps.flatMap(
({ splitPointsLatex }) => splitPointsLatex,
);
@@ -178,7 +178,7 @@ export function buildSetupPart(
`Use the representative interior time $t=${formatConvolutionScalar(representativeTime(interval))}$ for $${interval.labelLatex}$.`,
`Compare lower candidates $${lowerCandidates}$ and upper candidates $${upperCandidates}$.`,
splitPoints.length > 0
- ? `Split at $${splitPoints.join(",\\;")}$.`
+ ? String.raw`Split at $${splitPoints.join(String.raw`,\;`)}$.`
: `The verified setup is $${setup.integralLatex}$.`,
];
};
@@ -245,7 +245,7 @@ export function buildEvaluationPart(
id: `interval-${String(index + 1).padStart(2, "0")}`,
title: `Evaluate Region ${index + 1}`,
intervalLatex: interval.labelLatex,
- resultLatex: `y(t)=${interval.exprLatex},\\quad ${interval.labelLatex}`,
+ resultLatex: String.raw`y(t)=${interval.exprLatex},\quad ${interval.labelLatex}`,
options: [],
carriedZero,
primitiveLatex: carriedZero ? "0" : primitiveBySignal.h,
diff --git a/src/lib/math-engine/convolution/its-scaffolding/presentation.ts b/src/lib/math-engine/convolution/its-scaffolding/presentation.ts
index b9cdfcfa..077f8627 100644
--- a/src/lib/math-engine/convolution/its-scaffolding/presentation.ts
+++ b/src/lib/math-engine/convolution/its-scaffolding/presentation.ts
@@ -18,8 +18,8 @@ import { createSeededPrng, shuffleWithRandom } from "$lib/math-engine/random";
/** Formats one finite or infinite scalar as exact LaTeX. */
export function formatConvolutionScalar(value: number): string {
- if (value === Number.POSITIVE_INFINITY) return "\\infty";
- if (value === Number.NEGATIVE_INFINITY) return "-\\infty";
+ if (value === Number.POSITIVE_INFINITY) return String.raw`\infty`;
+ if (value === Number.NEGATIVE_INFINITY) return String.raw`-\infty`;
return String(value);
}
@@ -33,7 +33,7 @@ export function formatConvolutionPiecewiseLatex(
`${expressions[index] ?? interval.exprLatex} & ${interval.labelLatex}`,
);
return sanitizeLatexMath(
- `y(t) = \\begin{cases} ${rows.join(" \\\\ ")} \\end{cases}`,
+ String.raw`y(t) = \begin{cases} ${rows.join(String.raw` \\ `)} \end{cases}`,
);
}
@@ -52,8 +52,8 @@ export function getFiniteConvolutionTransitionTimes(
/** Formats one transformed moving edge. */
export function formatTranslatedEdge(value: number): string {
- if (value === Number.POSITIVE_INFINITY) return "-\\infty";
- if (value === Number.NEGATIVE_INFINITY) return "\\infty";
+ if (value === Number.POSITIVE_INFINITY) return String.raw`-\infty`;
+ if (value === Number.NEGATIVE_INFINITY) return String.raw`\infty`;
return formatTranslatedArgument("t", value);
}
@@ -94,28 +94,27 @@ export function buildFormulaStep(
): ConvolutionItsChoiceStep {
const matching =
moving === "h"
- ? "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(t-\\tau)\\,d\\tau"
- : "y(t)=\\int_{-\\infty}^{\\infty}h(\\tau)x(t-\\tau)\\,d\\tau";
+ ? String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(t-\tau)\,d\tau`
+ : String.raw`y(t)=\int_{-\infty}^{\infty}h(\tau)x(t-\tau)\,d\tau`;
const selectedWithoutFlip =
moving === "h"
- ? "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(\\tau-t)\\,d\\tau"
- : "y(t)=\\int_{-\\infty}^{\\infty}h(\\tau)x(\\tau-t)\\,d\\tau";
+ ? String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(\tau-t)\,d\tau`
+ : String.raw`y(t)=\int_{-\infty}^{\infty}h(\tau)x(\tau-t)\,d\tau`;
const otherCorrect =
moving === "h"
- ? "y(t)=\\int_{-\\infty}^{\\infty}h(\\tau)x(t-\\tau)\\,d\\tau"
- : "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(t-\\tau)\\,d\\tau";
+ ? String.raw`y(t)=\int_{-\infty}^{\infty}h(\tau)x(t-\tau)\,d\tau`
+ : String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(t-\tau)\,d\tau`;
const otherWithoutFlip =
moving === "h"
- ? "y(t)=\\int_{-\\infty}^{\\infty}h(\\tau)x(\\tau-t)\\,d\\tau"
- : "y(t)=\\int_{-\\infty}^{\\infty}x(\\tau)h(\\tau-t)\\,d\\tau";
+ ? String.raw`y(t)=\int_{-\infty}^{\infty}h(\tau)x(\tau-t)\,d\tau`
+ : String.raw`y(t)=\int_{-\infty}^{\infty}x(\tau)h(\tau-t)\,d\tau`;
const options: ConvolutionItsOption[] = [
{ id: `formula-${moving}-correct`, latex: matching, isCorrect: true },
{
id: `formula-${moving}-no-flip`,
latex: selectedWithoutFlip,
isCorrect: false,
- feedback:
- "This shifts the selected signal without reflecting it. The moving argument must be $t-\\tau$.",
+ feedback: String.raw`This shifts the selected signal without reflecting it. The moving argument must be $t-\tau$.`,
},
{
id: `formula-${moving}-other-path`,
@@ -135,11 +134,11 @@ export function buildFormulaStep(
const optionSeed =
(seed ^ (moving === "x" ? 0x58_33_ba_11 : 0x48_33_ba_11)) >>> 0;
return {
- prompt: `Which integral keeps $${moving === "h" ? "x" : "h"}(\\tau)$ fixed and moves $${moving}(t)$?`,
+ prompt: String.raw`Which integral keeps $${moving === "h" ? "x" : "h"}(\tau)$ fixed and moves $${moving}(t)$?`,
options: shuffleWithRandom(options, createSeededPrng(optionSeed)),
hints: [
- "The fixed signal keeps the argument $\\tau$.",
- "The selected moving signal receives the argument $t-\\tau$.",
+ String.raw`The fixed signal keeps the argument $\tau$.`,
+ String.raw`The selected moving signal receives the argument $t-\tau$.`,
`The matching path is $${matching}$.`,
],
};
diff --git a/src/lib/math-engine/convolution/pulse-formatting.ts b/src/lib/math-engine/convolution/pulse-formatting.ts
index 75377e56..5a23fbff 100644
--- a/src/lib/math-engine/convolution/pulse-formatting.ts
+++ b/src/lib/math-engine/convolution/pulse-formatting.ts
@@ -36,7 +36,7 @@ export function formatRectPulseLatex(
const argument = formatTranslatedArgument("t", shift);
const body =
width === 1
- ? `\\operatorname{rect}(${argument})`
- : `\\operatorname{rect}\\left(\\frac{${argument}}{${width}}\\right)`;
+ ? String.raw`\operatorname{rect}(${argument})`
+ : String.raw`\operatorname{rect}\left(\frac{${argument}}{${width}}\right)`;
return sanitizeLatexMath(formatPulseScale(amplitude, body));
}
diff --git a/src/lib/math-engine/evaluator.ts b/src/lib/math-engine/evaluator.ts
index 1efeca87..cab4c0c3 100644
--- a/src/lib/math-engine/evaluator.ts
+++ b/src/lib/math-engine/evaluator.ts
@@ -94,7 +94,10 @@ export function parseStrictLatex(latex: string): unknown {
(token: string): string =>
token.startsWith("\\")
? token
- : token.replace(/u\s*$/, "\\operatorname{Heaviside}"),
+ : token.replace(
+ /u\s*$/,
+ String.raw`\operatorname{Heaviside}`,
+ ),
);
return parse(normalizeMathLatex(expression, false));
}
@@ -130,7 +133,7 @@ export function normalizeMathLatex(
// Convert bare functions without leading backslash (e.g. cos, sin, tan, exp, sqrt, ln, log)
.replace(
/(^|[^a-zA-Z\\])(cos|sin|tan|exp|sqrt|ln|log)(?=[^a-zA-Z]|$)/g,
- "$1\\$2",
+ String.raw`$1\$2`,
)
);
}
@@ -303,7 +306,7 @@ export function evaluatePiecewiseLatexAt(latex: string, t: number): number {
const body = match[1];
const rows = body
- .split("\\\\")
+ .split(String.raw`\\`)
.map((r) => r.trim())
.filter(Boolean);
@@ -315,8 +318,8 @@ export function evaluatePiecewiseLatexAt(latex: string, t: number): number {
const parts = row.split("&");
exprPart = (parts[0] ?? "").trim().replace(/[,;]$/, "").trim();
condPart = parts.slice(1).join("&").trim();
- } else if (row.includes("\\text{for}")) {
- const parts = row.split("\\text{for}");
+ } else if (row.includes(String.raw`\text{for}`)) {
+ const parts = row.split(String.raw`\text{for}`);
exprPart = (parts[0] ?? "")
.trim()
.replace(/\\quad$/, "")
diff --git a/src/lib/math-engine/formatting.ts b/src/lib/math-engine/formatting.ts
index 0cac827c..46c8657a 100644
--- a/src/lib/math-engine/formatting.ts
+++ b/src/lib/math-engine/formatting.ts
@@ -114,8 +114,8 @@ export function formatQuadraticPolynomial(
*/
export function formatOdeLhs(a2: number, a1: number, a0: number): string {
const terms: PolynomialTerm[] = [
- { coeff: a2, symbol: "\\frac{d^2 y}{dt^2}" },
- { coeff: a1, symbol: "\\frac{dy}{dt}" },
+ { coeff: a2, symbol: String.raw`\frac{d^2 y}{dt^2}` },
+ { coeff: a1, symbol: String.raw`\frac{dy}{dt}` },
{ coeff: a0, symbol: "y(t)" },
];
@@ -301,7 +301,7 @@ export function sanitizeUnitCoefficients(latex: string): string {
// Lookaround ensures we do NOT match multi-digit numbers like j10, j11, -j10, 10j, 31j, 151j, 0.1j
s = s.replace(/(? x, -1x -> -x, + 1t -> + t, - 1t -> - t, (1t -> (t, (-1t -> (-t
@@ -320,17 +320,17 @@ export function sanitizeUnitCoefficients(latex: string): string {
// Lookahead (?![0-9]) preserves \cos(10t), \cos(11t), \sin(151t)
s = s.replace(
/\\(cos|sin|tan|cot|sec|csc)\(\s*(-?)1([a-zA-Z])(?![0-9])\s*\)/g,
- "\\$1($2$3)",
+ String.raw`\$1($2$3)`,
);
s = s.replace(
/\\(cos|sin|tan|cot|sec|csc)\(\s*(-?)j1([a-zA-Z])(?![0-9])\s*\)/g,
- "\\$1($2j$3)",
+ String.raw`\$1($2j$3)`,
);
// Unit multiplier before functions: 1\cos -> \cos, -1\cos -> -\cos, 1e^{ -> e^{
s = s.replace(
/(?0$, use $c_n=2|F_n|=\\sqrt{a_n^2+b_n^2}$.",
- "Assign phase only to nonzero harmonics with $\\theta_n=\\operatorname{atan2}(-b_n,a_n)=\\angle F_n$.",
+ String.raw`For $n>0$, use $c_n=2|F_n|=\sqrt{a_n^2+b_n^2}$.`,
+ String.raw`Assign phase only to nonzero harmonics with $\theta_n=\operatorname{atan2}(-b_n,a_n)=\angle F_n$.`,
],
},
],
@@ -121,13 +121,13 @@ export function generateFourierSeriesProblem(
title: "Period and Fundamental Frequency",
description:
"Read one complete repetition from the waveform and convert its period to angular frequency.",
- latex: `T_0=${periodLatex}\\text{ s},\\qquad \\omega_0=\\frac{2\\pi}{T_0}=\\frac{2\\pi}{${periodLatex}}=${w0Latex}\\text{ rad/s}`,
+ latex: String.raw`T_0=${periodLatex}\text{ s},\qquad \omega_0=\frac{2\pi}{T_0}=\frac{2\pi}{${periodLatex}}=${w0Latex}\text{ rad/s}`,
},
{
title: "Symmetry and Vanishing Terms",
description:
"Test origin parity and half-wave symmetry independently, then remove coefficient families that must vanish.",
- latex: `\\begin{gathered}\\text{origin parity: }${coeffs.originParity},\\qquad \\text{half-wave symmetry: }${coeffs.hasHalfWaveSymmetry ? "\\text{yes}" : "\\text{no}"}\\\\${coeffs.originParity === "odd" ? "a_0=a_n=0" : coeffs.originParity === "even" ? "b_n=0" : "a_n\\text{ and }b_n\\text{ must both be evaluated}"}\\end{gathered}`,
+ latex: String.raw`\begin{gathered}\text{origin parity: }${coeffs.originParity},\qquad \text{half-wave symmetry: }${coeffs.hasHalfWaveSymmetry ? String.raw`\text{yes}` : String.raw`\text{no}`}\\${coeffs.originParity === "odd" ? String.raw`a_0=a_n=0` : coeffs.originParity === "even" ? String.raw`b_n=0` : String.raw`a_n\text{ and }b_n\text{ must both be evaluated`}\end{gathered}`,
},
{
title: "Representation Selection",
@@ -137,8 +137,8 @@ export function generateFourierSeriesProblem(
: "The assigned trigonometric path evaluates the real coefficient families remaining after symmetry shortcuts.",
latex:
itsData.step4.correctForm === "exp"
- ? "F_n=\\frac{1}{T_0}\\int_{T_0}x(t)e^{-jn\\omega_0t}\\,dt"
- : "x(t)=\\frac{a_0}{2}+\\sum_{n=1}^{\\infty}[a_n\\cos(n\\omega_0t)+b_n\\sin(n\\omega_0t)]",
+ ? String.raw`F_n=\frac{1}{T_0}\int_{T_0}x(t)e^{-jn\omega_0t}\,dt`
+ : String.raw`x(t)=\frac{a_0}{2}+\sum_{n=1}^{\infty}[a_n\cos(n\omega_0t)+b_n\sin(n\omega_0t)]`,
},
{
title: "Piecewise Integral Setup",
@@ -147,12 +147,11 @@ export function generateFourierSeriesProblem(
latex:
itsData.step4.correctForm === "exp"
? derivation.expIntegralLatex
- : `\\begin{gathered}${itsData.step5.parts.map(({ resultLatex }) => resultLatex).join("\\\\")}\\end{gathered}`,
+ : String.raw`\begin{gathered}${itsData.step5.parts.map(({ resultLatex }) => resultLatex).join(String.raw`\\`)}\end{gathered}`,
},
{
title: "Definite Integral Evaluation",
- description:
- "Apply the bounds and simplify parity factors such as $(-1)^n$ and $\\sin(n\\pi/2)$.",
+ description: String.raw`Apply the bounds and simplify parity factors such as $(-1)^n$ and $\sin(n\pi/2)$.`,
latex:
itsData.step4.correctForm === "exp"
? getExponentialEvaluationLatex(derivation)
@@ -162,7 +161,7 @@ export function generateFourierSeriesProblem(
title: "DC Offset Derivation",
description:
"Evaluate the average separately; the constant appearing in the trigonometric series is $a_0/2$.",
- latex: `a_0=\\frac{2}{T_0}\\int_{T_0}x(t)\\,dt=${derivation.a0Latex},\\qquad F_0=\\frac{a_0}{2}`,
+ latex: String.raw`a_0=\frac{2}{T_0}\int_{T_0}x(t)\,dt=${derivation.a0Latex},\qquad F_0=\frac{a_0}{2}`,
},
{
title: `${primaryName} Synthesis`,
@@ -182,8 +181,8 @@ export function generateFourierSeriesProblem(
seed,
waveformType,
title: "Practice Problem: Periodic Waveform",
- periodLatex: `T_0 = ${periodLatex}\\text{ s}`,
- omega0Latex: `\\omega_0 = \\frac{2\\pi}{${periodLatex}} = ${w0Latex}\\text{ rad/s}`,
+ periodLatex: String.raw`T_0 = ${periodLatex}\text{ s}`,
+ omega0Latex: String.raw`\omega_0 = \frac{2\pi}{${periodLatex}} = ${w0Latex}\text{ rad/s}`,
signalLatex,
a0Latex: derivation.a0Latex,
anLatex: derivation.anLatex,
diff --git a/src/lib/math-engine/fourier-series/its-scaffolding/step1-period-freq.ts b/src/lib/math-engine/fourier-series/its-scaffolding/step1-period-freq.ts
index ca1ba191..34e485d5 100644
--- a/src/lib/math-engine/fourier-series/its-scaffolding/step1-period-freq.ts
+++ b/src/lib/math-engine/fourier-series/its-scaffolding/step1-period-freq.ts
@@ -24,9 +24,16 @@ export function buildStep1Data(
const periodLatex = formatFourierNumber(T0);
const w0Aliases =
T0 === 2
- ? ["pi", "\\pi", "1pi", "3.14", "3.1415", "3.1416"]
+ ? ["pi", String.raw`\pi`, "1pi", "3.14", "3.1415", "3.1416"]
: T0 === 4
- ? ["pi/2", "\\pi/2", "0.5pi", "0.5\\pi", "1.57", "1.5708"]
+ ? [
+ "pi/2",
+ String.raw`\pi/2`,
+ "0.5pi",
+ String.raw`0.5\pi`,
+ "1.57",
+ "1.5708",
+ ]
: [w0Latex, formatFourierNumber(w0)];
return {
@@ -38,8 +45,8 @@ export function buildStep1Data(
w0Aliases,
hints: [
"Look at the bounds of the definition. Over what duration does the signal repeat itself entirely?",
- `The signal repeats every period $T_0 = ${periodLatex}\\text{ s}$. The fundamental frequency is $\\omega_0 = \\frac{2\\pi}{T_0}$.`,
- `Substitute $T_0 = ${periodLatex}$: $\\omega_0 = \\frac{2\\pi}{${periodLatex}} = ${w0Latex}\\text{ rad/s}$. Ensure units are $\\text{s}$ and $\\text{rad/s}$.`,
+ String.raw`The signal repeats every period $T_0 = ${periodLatex}\text{ s}$. The fundamental frequency is $\omega_0 = \frac{2\pi}{T_0}$.`,
+ String.raw`Substitute $T_0 = ${periodLatex}$: $\omega_0 = \frac{2\pi}{${periodLatex}} = ${w0Latex}\text{ rad/s}$. Ensure units are $\text{s}$ and $\text{rad/s}$.`,
],
};
}
diff --git a/src/lib/math-engine/fourier-series/its-scaffolding/step4-form.ts b/src/lib/math-engine/fourier-series/its-scaffolding/step4-form.ts
index 487197f9..a5dfa95c 100644
--- a/src/lib/math-engine/fourier-series/its-scaffolding/step4-form.ts
+++ b/src/lib/math-engine/fourier-series/its-scaffolding/step4-form.ts
@@ -30,7 +30,7 @@ export function buildStep4Data(
correctForm,
hints: [
`This guided problem uses the ${assignedName} form. Both Trigonometric and Exponential representations are mathematically valid.`,
- "Trigonometric form separates $a_n$ and $b_n$. Exponential form $F_n$ combines them using $e^{-j n \\omega_0 t}$.",
+ String.raw`Trigonometric form separates $a_n$ and $b_n$. Exponential form $F_n$ combines them using $e^{-j n \omega_0 t}$.`,
correctForm === "trig"
? "Follow the Trigonometric path by evaluating DC and the real coefficient families not already eliminated by symmetry."
: "Follow the Exponential path by evaluating $F_n$, including its DC case separately.",
@@ -38,8 +38,7 @@ export function buildStep4Data(
misconceptions: {
trig: `Trigonometric form is valid. Select the assigned ${assignedName} form for this guided derivation.`,
exp: `Exponential form is valid. Select the assigned ${assignedName} form for this guided derivation.`,
- compact:
- "Compact polar form ($C_n, \\theta_n$) is derived from Trigonometric or Exponential coefficients, not integrated directly.",
+ compact: String.raw`Compact polar form ($C_n, \theta_n$) is derived from Trigonometric or Exponential coefficients, not integrated directly.`,
},
};
}
diff --git a/src/lib/math-engine/fourier-series/its-scaffolding/step5-integrals.ts b/src/lib/math-engine/fourier-series/its-scaffolding/step5-integrals.ts
index b5dca302..0288bbdf 100644
--- a/src/lib/math-engine/fourier-series/its-scaffolding/step5-integrals.ts
+++ b/src/lib/math-engine/fourier-series/its-scaffolding/step5-integrals.ts
@@ -43,23 +43,47 @@ export function buildIntegralOptions(
}),
}));
}
- const scalingDistractor = correct.includes("\\frac{4}{T_0}")
- ? correct.replace("\\frac{4}{T_0}", "\\frac{2}{T_0}")
- : correct.includes("\\frac{2j}{T_0}")
- ? correct.replace("\\frac{2j}{T_0}", "\\frac{j}{T_0}")
- : correct.includes("\\frac{2}{T_0}")
- ? correct.replace("\\frac{2}{T_0}", "\\frac{1}{T_0}")
- : correct.replace("\\frac{1}{T_0}", "\\frac{2}{T_0}");
- const kernelDistractor = correct.includes("e^{-jn\\omega_0t}")
- ? correct.replace("e^{-jn\\omega_0t}", "e^{+jn\\omega_0t}")
- : correct.includes("\\cos(n\\omega_0t)")
- ? correct.replaceAll("\\cos(n\\omega_0t)", "\\sin(n\\omega_0t)")
- : correct.includes("\\sin(n\\omega_0t)")
- ? correct.replaceAll("\\sin(n\\omega_0t)", "\\cos(n\\omega_0t)")
- : correct.replace("\\,dt", "\\cos(n\\omega_0t)\\,dt");
- const fullIntervalDistractor = correct.includes("\\int_0^{T_0/2}")
- ? correct.replace("\\int_0^{T_0/2}", "\\int_0^{T_0}")
- : correct.replace("\\int_0^{T_0/4}", "\\int_0^{T_0/2}");
+ const scalingDistractor = correct.includes(String.raw`\frac{4}{T_0}`)
+ ? correct.replace(String.raw`\frac{4}{T_0}`, String.raw`\frac{2}{T_0}`)
+ : correct.includes(String.raw`\frac{2j}{T_0}`)
+ ? correct.replace(
+ String.raw`\frac{2j}{T_0}`,
+ String.raw`\frac{j}{T_0}`,
+ )
+ : correct.includes(String.raw`\frac{2}{T_0}`)
+ ? correct.replace(
+ String.raw`\frac{2}{T_0}`,
+ String.raw`\frac{1}{T_0}`,
+ )
+ : correct.replace(
+ String.raw`\frac{1}{T_0}`,
+ String.raw`\frac{2}{T_0}`,
+ );
+ const kernelDistractor = correct.includes(String.raw`e^{-jn\omega_0t}`)
+ ? correct.replace(
+ String.raw`e^{-jn\omega_0t}`,
+ String.raw`e^{+jn\omega_0t}`,
+ )
+ : correct.includes(String.raw`\cos(n\omega_0t)`)
+ ? correct.replaceAll(
+ String.raw`\cos(n\omega_0t)`,
+ String.raw`\sin(n\omega_0t)`,
+ )
+ : correct.includes(String.raw`\sin(n\omega_0t)`)
+ ? correct.replaceAll(
+ String.raw`\sin(n\omega_0t)`,
+ String.raw`\cos(n\omega_0t)`,
+ )
+ : correct.replace(
+ String.raw`\,dt`,
+ String.raw`\cos(n\omega_0t)\,dt`,
+ );
+ const fullIntervalDistractor = correct.includes(String.raw`\int_0^{T_0/2}`)
+ ? correct.replace(String.raw`\int_0^{T_0/2}`, String.raw`\int_0^{T_0}`)
+ : correct.replace(
+ String.raw`\int_0^{T_0/4}`,
+ String.raw`\int_0^{T_0/2}`,
+ );
return [
{ id: "c1", latex: correct, isCorrect: true },
@@ -74,8 +98,8 @@ export function buildIntegralOptions(
id: "d2",
latex: kernelDistractor,
isCorrect: false,
- feedback: correct.includes("e^{-jn\\omega_0t}")
- ? "Sign Error: Exponential Fourier coefficients require the kernel $e^{-j n \\omega_0 t}$."
+ feedback: correct.includes(String.raw`e^{-jn\omega_0t}`)
+ ? String.raw`Sign Error: Exponential Fourier coefficients require the kernel $e^{-j n \omega_0 t}$.`
: "Kernel Error: The selected sine or cosine kernel does not match the non-zero coefficient family.",
},
{
@@ -224,7 +248,7 @@ export function buildStep5Data(
carriedCoefficients,
hints: [
"Use symmetry to choose the non-zero coefficient family before writing an integral.",
- "Trigonometric coefficients use $2/T_0$; exponential coefficients use $1/T_0$ and $e^{-jn\\omega_0t}$.",
+ String.raw`Trigonometric coefficients use $2/T_0$; exponential coefficients use $1/T_0$ and $e^{-jn\omega_0t}$.`,
"Split the integral exactly where the waveform definition changes and omit intervals where the signal is zero.",
],
};
diff --git a/src/lib/math-engine/fourier-series/its-scaffolding/step6-evaluation.ts b/src/lib/math-engine/fourier-series/its-scaffolding/step6-evaluation.ts
index 02450011..d0ba995c 100644
--- a/src/lib/math-engine/fourier-series/its-scaffolding/step6-evaluation.ts
+++ b/src/lib/math-engine/fourier-series/its-scaffolding/step6-evaluation.ts
@@ -53,21 +53,21 @@ export function buildEvaluationOptions(
},
{
id: `${target}-scale`,
- latex: `${label}=\\frac{1}{2}\\left(${resultLatex}\\right)`,
+ latex: String.raw`${label}=\frac{1}{2}\left(${resultLatex}\right)`,
isCorrect: false,
feedback:
"Scale Factor Error: Recheck the Fourier normalization before applying the integration bounds.",
},
{
id: `${target}-sign`,
- latex: `${label}=-\\left(${resultLatex}\\right)`,
+ latex: String.raw`${label}=-\left(${resultLatex}\right)`,
isCorrect: false,
feedback:
"Sign Error: Re-evaluate the antiderivative at the upper and lower bounds in order.",
},
{
id: `${target}-support`,
- latex: `${label}=2\\left(${resultLatex}\\right)`,
+ latex: String.raw`${label}=2\left(${resultLatex}\right)`,
isCorrect: false,
feedback:
"Scale Factor Error: Do not apply the Fourier normalization a second time.",
@@ -136,7 +136,7 @@ export function buildStep6Data(
carriedCoefficients,
hints: [
"Apply the antiderivative to every non-zero interval before simplifying the harmonic index.",
- "Use $\\cos(n\\pi)=(-1)^n$ and $\\sin(n\\pi/2)$ to expose vanished or alternating harmonics.",
+ String.raw`Use $\cos(n\pi)=(-1)^n$ and $\sin(n\pi/2)$ to expose vanished or alternating harmonics.`,
form === "exp"
? `The exponential integral evaluates to $${getExponentialEvaluationLatex(derivation)}$.`
: `The evaluated result is $${derivation.evaluationLatex}$.`,
diff --git a/src/lib/math-engine/fourier-series/its-scaffolding/step7-series.ts b/src/lib/math-engine/fourier-series/its-scaffolding/step7-series.ts
index 9e3209fc..ae4a42b3 100644
--- a/src/lib/math-engine/fourier-series/its-scaffolding/step7-series.ts
+++ b/src/lib/math-engine/fourier-series/its-scaffolding/step7-series.ts
@@ -22,14 +22,14 @@ export function buildPrimarySeriesOptions(
form: FourierPrimaryForm,
): FourierItsOption[] {
// Coefficient definitions follow the synthesis expression and must stay intact.
- const definitionIndex = correct.indexOf(",\\qquad");
+ const definitionIndex = correct.indexOf(String.raw`,\qquad`);
const synthesis =
definitionIndex < 0 ? correct : correct.slice(0, definitionIndex);
const definitions =
definitionIndex < 0 ? "" : correct.slice(definitionIndex);
const rhs = synthesis.slice(synthesis.indexOf("=") + 1).trim();
- const signDistractor = `x(t)=-\\left(${rhs}\\right)${definitions}`;
- const scaleDistractor = `x(t)=\\frac{1}{2}\\left(${rhs}\\right)${definitions}`;
+ const signDistractor = String.raw`x(t)=-\left(${rhs}\right)${definitions}`;
+ const scaleDistractor = String.raw`x(t)=\frac{1}{2}\left(${rhs}\right)${definitions}`;
// Double only the independent time symbol; preserve phase and coefficient symbols.
const doubledTime = rhs.replace(/(?
- `x(t)=\\frac{c_0}{2}+\\sum_{n=1}^{\\infty}c_n\\cos(n ${w0Latex} t+\\theta_n),\\qquad ${body}`;
+ String.raw`x(t)=\frac{c_0}{2}+\sum_{n=1}^{\infty}c_n\cos(n ${w0Latex} t+\theta_n),\qquad ${body}`;
switch (waveformType) {
case "square":
case "square_odd":
return harmonic(
- `c_0=0,\\quad c_n=\\begin{cases}\\dfrac{4(${A})}{n\\pi},&n\\text{ odd}\\\\0,&n\\text{ even}\\end{cases},\\quad \\theta_n=-\\dfrac{\\pi}{2}\\ (n\\text{ odd})`,
+ String.raw`c_0=0,\quad c_n=\begin{cases}\dfrac{4(${A})}{n\pi},&n\text{ odd}\\0,&n\text{ even}\end{cases},\quad \theta_n=-\dfrac{\pi}{2}\ (n\text{ odd})`,
);
case "square_even":
return harmonic(
- `c_0=0,\\quad c_n=\\begin{cases}\\dfrac{4(${A})}{n\\pi},&n\\text{ odd}\\\\0,&n\\text{ even}\\end{cases},\\quad \\theta_n=\\begin{cases}0,&n\\equiv1\\pmod4\\\\\\pi,&n\\equiv3\\pmod4\\end{cases}`,
+ String.raw`c_0=0,\quad c_n=\begin{cases}\dfrac{4(${A})}{n\pi},&n\text{ odd}\\0,&n\text{ even}\end{cases},\quad \theta_n=\begin{cases}0,&n\equiv1\pmod4\\\pi,&n\equiv3\pmod4\end{cases}`,
);
case "triangle":
case "triangle_even":
return harmonic(
- `c_0=0,\\quad c_n=\\begin{cases}\\dfrac{8(${A})}{n^2\\pi^2},&n\\text{ odd}\\\\0,&n\\text{ even}\\end{cases},\\quad \\theta_n=0\\ (n\\text{ odd})`,
+ String.raw`c_0=0,\quad c_n=\begin{cases}\dfrac{8(${A})}{n^2\pi^2},&n\text{ odd}\\0,&n\text{ even}\end{cases},\quad \theta_n=0\ (n\text{ odd})`,
);
case "triangle_odd":
return harmonic(
- `c_0=0,\\quad c_n=\\begin{cases}\\dfrac{8(${A})}{n^2\\pi^2},&n\\text{ odd}\\\\0,&n\\text{ even}\\end{cases},\\quad \\theta_n=\\begin{cases}-\\dfrac{\\pi}{2},&n\\equiv1\\pmod4\\\\\\dfrac{\\pi}{2},&n\\equiv3\\pmod4\\end{cases}`,
+ String.raw`c_0=0,\quad c_n=\begin{cases}\dfrac{8(${A})}{n^2\pi^2},&n\text{ odd}\\0,&n\text{ even}\end{cases},\quad \theta_n=\begin{cases}-\dfrac{\pi}{2},&n\equiv1\pmod4\\\dfrac{\pi}{2},&n\equiv3\pmod4\end{cases}`,
);
case "sawtooth":
return harmonic(
- `c_0=0,\\quad c_n=\\dfrac{2(${A})}{n\\pi},\\quad \\theta_n=\\dfrac{(-1)^n\\pi}{2}`,
+ String.raw`c_0=0,\quad c_n=\dfrac{2(${A})}{n\pi},\quad \theta_n=\dfrac{(-1)^n\pi}{2}`,
);
case "half_wave_sine":
return harmonic(
- `c_0=\\dfrac{2(${A})}{\\pi},\\quad c_1=\\dfrac{${A}}{2},\\ \\theta_1=-\\dfrac{\\pi}{2},\\quad c_{2k}=\\dfrac{2(${A})}{\\pi(4k^2-1)},\\ \\theta_{2k}=\\pi,\\quad c_n=0\\ (n>1\\text{ odd})`,
+ String.raw`c_0=\dfrac{2(${A})}{\pi},\quad c_1=\dfrac{${A}}{2},\ \theta_1=-\dfrac{\pi}{2},\quad c_{2k}=\dfrac{2(${A})}{\pi(4k^2-1)},\ \theta_{2k}=\pi,\quad c_n=0\ (n>1\text{ odd})`,
);
case "full_wave_sine":
return harmonic(
- `c_0=\\dfrac{4(${A})}{\\pi},\\quad c_n=\\dfrac{4(${A})}{\\pi(4n^2-1)},\\quad \\theta_n=\\pi`,
+ String.raw`c_0=\dfrac{4(${A})}{\pi},\quad c_n=\dfrac{4(${A})}{\pi(4n^2-1)},\quad \theta_n=\pi`,
);
default: {
const _exhaustiveCheck: never = waveformType;
@@ -129,20 +129,20 @@ export function buildSignalLatex(
switch (waveformType) {
case "square":
case "square_odd":
- return `x(t)=\\begin{cases}-${A}&-${halfPeriod}1\\text{ odd}\\end{cases}`;
- a0IntegralLatex = `a_0=\\frac{2}{T_0}\\int_0^{T_0/2}${A}\\sin(\\omega_0t)\\,dt`;
- integralLatex = `F_n=\\frac{1}{T_0}\\int_0^{T_0/2}${A}\\sin(\\omega_0t)e^{-jn\\omega_0t}\\,dt`;
+ a0Latex = String.raw`\frac{2${amplitude}}{\pi}`;
+ anLatex = String.raw`\begin{cases}\dfrac{2${amplitude}}{\pi(1-n^2)},&n\text{ even}\\0,&n\text{ odd}\end{cases}`;
+ bnLatex = String.raw`\begin{cases}\dfrac{${A}}{2},&n=1\\0,&n\ne1\end{cases}`;
+ FnLatex = String.raw`\begin{cases}\dfrac{${A}}{\pi},&n=0\\-j\dfrac{${A}}{4},&n=1\\j\dfrac{${A}}{4},&n=-1\\\dfrac{${A}}{\pi(1-n^2)},&n\ne0\text{ even}\\0,&|n|>1\text{ odd}\end{cases}`;
+ a0IntegralLatex = String.raw`a_0=\frac{2}{T_0}\int_0^{T_0/2}${A}\sin(\omega_0t)\,dt`;
+ integralLatex = String.raw`F_n=\frac{1}{T_0}\int_0^{T_0/2}${A}\sin(\omega_0t)e^{-jn\omega_0t}\,dt`;
expIntegralLatex = integralLatex;
- evaluationLatex = `a_0=\\left[-\\frac{2${amplitude}\\cos(\\omega_0t)}{T_0\\omega_0}\\right]_0^{T_0/2}=\\frac{2${amplitude}}{\\pi},\\quad a_n=${anLatex},\\quad b_n=${bnLatex}`;
+ evaluationLatex = String.raw`a_0=\left[-\frac{2${amplitude}\cos(\omega_0t)}{T_0\omega_0}\right]_0^{T_0/2}=\frac{2${amplitude}}{\pi},\quad a_n=${anLatex},\quad b_n=${bnLatex}`;
break;
case "full_wave_sine":
- a0Latex = `\\frac{4${amplitude}}{\\pi}`;
- anLatex = `-\\frac{4${amplitude}}{\\pi(4n^2-1)}`;
+ a0Latex = String.raw`\frac{4${amplitude}}{\pi}`;
+ anLatex = String.raw`-\frac{4${amplitude}}{\pi(4n^2-1)}`;
bnLatex = "0";
- FnLatex = `\\begin{cases}\\dfrac{2${amplitude}}{\\pi},&n=0\\\\-\\dfrac{2${amplitude}}{\\pi(4n^2-1)},&n\\ne0\\end{cases}`;
- a0IntegralLatex = `a_0=\\frac{4}{T_0}\\int_0^{T_0/2}${A}\\sin\\left(\\frac{\\pi t}{T_0}\\right)\\,dt`;
- integralLatex = `a_n=\\frac{4}{T_0}\\int_0^{T_0/2}${A}\\sin\\left(\\frac{\\pi t}{T_0}\\right)\\cos(n\\omega_0t)\\,dt`;
- expIntegralLatex = `F_n=\\frac{2}{T_0}\\int_0^{T_0/2}${A}\\sin\\left(\\frac{\\pi t}{T_0}\\right)\\cos(n\\omega_0t)\\,dt`;
- evaluationLatex = `a_0=\\frac{4${amplitude}}{\\pi},\\qquad a_n=-\\frac{4${amplitude}}{\\pi(4n^2-1)},\\qquad b_n=0`;
+ FnLatex = String.raw`\begin{cases}\dfrac{2${amplitude}}{\pi},&n=0\\-\dfrac{2${amplitude}}{\pi(4n^2-1)},&n\ne0\end{cases}`;
+ a0IntegralLatex = String.raw`a_0=\frac{4}{T_0}\int_0^{T_0/2}${A}\sin\left(\frac{\pi t}{T_0}\right)\,dt`;
+ integralLatex = String.raw`a_n=\frac{4}{T_0}\int_0^{T_0/2}${A}\sin\left(\frac{\pi t}{T_0}\right)\cos(n\omega_0t)\,dt`;
+ expIntegralLatex = String.raw`F_n=\frac{2}{T_0}\int_0^{T_0/2}${A}\sin\left(\frac{\pi t}{T_0}\right)\cos(n\omega_0t)\,dt`;
+ evaluationLatex = String.raw`a_0=\frac{4${amplitude}}{\pi},\qquad a_n=-\frac{4${amplitude}}{\pi(4n^2-1)},\qquad b_n=0`;
break;
default: {
const _exhaustiveCheck: never = waveformType;
@@ -257,16 +257,16 @@ export function buildFourierSeriesSymbolicDerivation(
}
}
- const finalExpLatex = `x(t)=\\sum_{n=-\\infty}^{\\infty}F_ne^{j n ${w0Latex} t},\\qquad F_n=${FnLatex}`;
+ const finalExpLatex = String.raw`x(t)=\sum_{n=-\infty}^{\infty}F_ne^{j n ${w0Latex} t},\qquad F_n=${FnLatex}`;
const anIntegralLatex =
waveformType === "half_wave_sine"
- ? `a_n=\\frac{2}{T_0}\\int_0^{T_0/2}${A}\\sin(\\omega_0t)\\cos(n\\omega_0t)\\,dt`
+ ? String.raw`a_n=\frac{2}{T_0}\int_0^{T_0/2}${A}\sin(\omega_0t)\cos(n\omega_0t)\,dt`
: coeffs.originParity === "even"
? integralLatex
: buildFullPeriodIntegral(coeffs, "an");
const bnIntegralLatex =
waveformType === "half_wave_sine"
- ? `b_n=\\frac{2}{T_0}\\int_0^{T_0/2}${A}\\sin(\\omega_0t)\\sin(n\\omega_0t)\\,dt`
+ ? String.raw`b_n=\frac{2}{T_0}\int_0^{T_0/2}${A}\sin(\omega_0t)\sin(n\omega_0t)\,dt`
: coeffs.originParity === "odd"
? integralLatex
: buildFullPeriodIntegral(coeffs, "bn");
@@ -298,42 +298,42 @@ function buildExponentialEvaluation(
result: string,
): string {
const A = `(${formatFourierNumber(coeffs.A)})`;
- const k = "n\\omega_0";
- const sinePrimitive = `-\\frac{\\cos(n\\omega_0t)}{${k}}`;
- const cosinePrimitive = `\\frac{\\sin(n\\omega_0t)}{${k}}`;
+ const k = String.raw`n\omega_0`;
+ const sinePrimitive = String.raw`-\frac{\cos(n\omega_0t)}{${k}}`;
+ const cosinePrimitive = String.raw`\frac{\sin(n\omega_0t)}{${k}}`;
let evaluation: string;
let dc = "0";
- let dcEvaluation = `\\frac{1}{2}\\left(${buildFullPeriodIntegral(coeffs, "a0").split("=")[1]}\\right)`;
+ let dcEvaluation = String.raw`\frac{1}{2}\left(${buildFullPeriodIntegral(coeffs, "a0").split("=")[1]}\right)`;
switch (coeffs.waveformType) {
case "square":
case "square_odd":
- evaluation = `-\\frac{2j${A}}{T_0}\\left[${sinePrimitive}\\right]_0^{T_0/2}`;
+ evaluation = String.raw`-\frac{2j${A}}{T_0}\left[${sinePrimitive}\right]_0^{T_0/2}`;
break;
case "square_even":
- evaluation = `\\frac{2${A}}{T_0}\\left(\\left[${cosinePrimitive}\\right]_0^{T_0/4}-\\left[${cosinePrimitive}\\right]_{T_0/4}^{T_0/2}\\right)`;
+ evaluation = String.raw`\frac{2${A}}{T_0}\left(\left[${cosinePrimitive}\right]_0^{T_0/4}-\left[${cosinePrimitive}\right]_{T_0/4}^{T_0/2}\right)`;
break;
case "triangle":
case "triangle_even":
- evaluation = `\\frac{2${A}}{T_0}\\left[\\frac{(1-4t/T_0)\\sin(n\\omega_0t)}{${k}}-\\frac{4\\cos(n\\omega_0t)}{T_0n^2\\omega_0^2}\\right]_0^{T_0/2}`;
+ evaluation = String.raw`\frac{2${A}}{T_0}\left[\frac{(1-4t/T_0)\sin(n\omega_0t)}{${k}}-\frac{4\cos(n\omega_0t)}{T_0n^2\omega_0^2}\right]_0^{T_0/2}`;
break;
case "triangle_odd":
- evaluation = `-\\frac{2j${A}}{T_0}\\left(\\left[-\\frac{4t\\cos(n\\omega_0t)}{T_0${k}}+\\frac{4\\sin(n\\omega_0t)}{T_0n^2\\omega_0^2}\\right]_0^{T_0/4}+\\left[-\\frac{(2-4t/T_0)\\cos(n\\omega_0t)}{${k}}-\\frac{4\\sin(n\\omega_0t)}{T_0n^2\\omega_0^2}\\right]_{T_0/4}^{T_0/2}\\right)`;
+ evaluation = String.raw`-\frac{2j${A}}{T_0}\left(\left[-\frac{4t\cos(n\omega_0t)}{T_0${k}}+\frac{4\sin(n\omega_0t)}{T_0n^2\omega_0^2}\right]_0^{T_0/4}+\left[-\frac{(2-4t/T_0)\cos(n\omega_0t)}{${k}}-\frac{4\sin(n\omega_0t)}{T_0n^2\omega_0^2}\right]_{T_0/4}^{T_0/2}\right)`;
break;
case "sawtooth":
- evaluation = `-\\frac{4j${A}}{T_0^2}\\left[-\\frac{t\\cos(n\\omega_0t)}{${k}}+\\frac{\\sin(n\\omega_0t)}{n^2\\omega_0^2}\\right]_0^{T_0/2}`;
+ evaluation = String.raw`-\frac{4j${A}}{T_0^2}\left[-\frac{t\cos(n\omega_0t)}{${k}}+\frac{\sin(n\omega_0t)}{n^2\omega_0^2}\right]_0^{T_0/2}`;
break;
case "half_wave_sine":
- dc = `\\frac{${A}}{\\pi}`;
- dcEvaluation = `\\frac{${A}}{T_0}\\left[-\\frac{\\cos(\\omega_0t)}{\\omega_0}\\right]_0^{T_0/2}`;
- evaluation = `\\frac{${A}}{2jT_0}\\left[\\frac{e^{-j(n-1)\\omega_0t}}{-j(n-1)\\omega_0}-\\frac{e^{-j(n+1)\\omega_0t}}{-j(n+1)\\omega_0}\\right]_0^{T_0/2}`;
- return `\\begin{gathered}F_n=${evaluation}\\quad(n\\ne0,\\pm1)\\\\F_0=${dcEvaluation}=${dc}\\\\F_1=\\frac{${A}}{2jT_0}\\left[t-\\frac{e^{-2j\\omega_0t}}{-2j\\omega_0}\\right]_0^{T_0/2}=-j\\frac{${A}}{4}\\\\F_{-1}=\\frac{${A}}{2jT_0}\\left[\\frac{e^{2j\\omega_0t}}{2j\\omega_0}-t\\right]_0^{T_0/2}=j\\frac{${A}}{4}\\\\F_n=${result}\\end{gathered}`;
+ dc = String.raw`\frac{${A}}{\pi}`;
+ dcEvaluation = String.raw`\frac{${A}}{T_0}\left[-\frac{\cos(\omega_0t)}{\omega_0}\right]_0^{T_0/2}`;
+ evaluation = String.raw`\frac{${A}}{2jT_0}\left[\frac{e^{-j(n-1)\omega_0t}}{-j(n-1)\omega_0}-\frac{e^{-j(n+1)\omega_0t}}{-j(n+1)\omega_0}\right]_0^{T_0/2}`;
+ return String.raw`\begin{gathered}F_n=${evaluation}\quad(n\ne0,\pm1)\\F_0=${dcEvaluation}=${dc}\\F_1=\frac{${A}}{2jT_0}\left[t-\frac{e^{-2j\omega_0t}}{-2j\omega_0}\right]_0^{T_0/2}=-j\frac{${A}}{4}\\F_{-1}=\frac{${A}}{2jT_0}\left[\frac{e^{2j\omega_0t}}{2j\omega_0}-t\right]_0^{T_0/2}=j\frac{${A}}{4}\\F_n=${result}\end{gathered}`;
case "full_wave_sine":
- dc = `\\frac{2${A}}{\\pi}`;
- dcEvaluation = `\\frac{2${A}}{T_0}\\left[-\\frac{\\cos(\\pi t/T_0)}{\\pi/T_0}\\right]_0^{T_0/2}`;
- evaluation = `-\\frac{${A}}{T_0}\\left[\\frac{\\cos((1+2n)\\pi t/T_0)}{(1+2n)\\pi/T_0}+\\frac{\\cos((1-2n)\\pi t/T_0)}{(1-2n)\\pi/T_0}\\right]_0^{T_0/2}`;
+ dc = String.raw`\frac{2${A}}{\pi}`;
+ dcEvaluation = String.raw`\frac{2${A}}{T_0}\left[-\frac{\cos(\pi t/T_0)}{\pi/T_0}\right]_0^{T_0/2}`;
+ evaluation = String.raw`-\frac{${A}}{T_0}\left[\frac{\cos((1+2n)\pi t/T_0)}{(1+2n)\pi/T_0}+\frac{\cos((1-2n)\pi t/T_0)}{(1-2n)\pi/T_0}\right]_0^{T_0/2}`;
break;
}
- return `\\begin{gathered}F_n=${evaluation}\\quad(n\\ne0)\\\\F_0=${dcEvaluation}=${dc}\\\\F_n=${result}\\end{gathered}`;
+ return String.raw`\begin{gathered}F_n=${evaluation}\quad(n\ne0)\\F_0=${dcEvaluation}=${dc}\\F_n=${result}\end{gathered}`;
}
/**
@@ -351,8 +351,8 @@ function buildFullPeriodIntegral(
target === "a0"
? ""
: target === "an"
- ? "\\cos(n\\omega_0t)"
- : "\\sin(n\\omega_0t)";
+ ? String.raw`\cos(n\omega_0t)`
+ : String.raw`\sin(n\omega_0t)`;
const { label } = FOURIER_COEFFICIENT_METADATA[target];
let pieces: [string, string, string][];
switch (coeffs.waveformType) {
@@ -372,32 +372,32 @@ function buildFullPeriodIntegral(
break;
case "triangle_odd":
pieces = [
- ["-T_0/2", "-T_0/4", `-2${A}-\\frac{4${A}t}{T_0}`],
- ["-T_0/4", "T_0/4", `\\frac{4${A}t}{T_0}`],
- ["T_0/4", "T_0/2", `2${A}-\\frac{4${A}t}{T_0}`],
+ ["-T_0/2", "-T_0/4", String.raw`-2${A}-\frac{4${A}t}{T_0}`],
+ ["-T_0/4", "T_0/4", String.raw`\frac{4${A}t}{T_0}`],
+ ["T_0/4", "T_0/2", String.raw`2${A}-\frac{4${A}t}{T_0}`],
];
break;
case "sawtooth":
- pieces = [["-T_0/2", "T_0/2", `\\frac{2${A}t}{T_0}`]];
+ pieces = [["-T_0/2", "T_0/2", String.raw`\frac{2${A}t}{T_0}`]];
break;
case "half_wave_sine":
- pieces = [["0", "T_0/2", `${A}\\sin(\\omega_0t)`]];
+ pieces = [["0", "T_0/2", String.raw`${A}\sin(\omega_0t)`]];
break;
case "full_wave_sine":
- pieces = [["0", "T_0", `${A}\\sin(\\frac{\\pi t}{T_0})`]];
+ pieces = [["0", "T_0", String.raw`${A}\sin(\frac{\pi t}{T_0})`]];
break;
default:
pieces = [
- ["-T_0/2", "0", `${A}(1+\\frac{4t}{T_0})`],
- ["0", "T_0/2", `${A}(1-\\frac{4t}{T_0})`],
+ ["-T_0/2", "0", String.raw`${A}(1+\frac{4t}{T_0})`],
+ ["0", "T_0/2", String.raw`${A}(1-\frac{4t}{T_0})`],
];
}
const integrals = pieces.map(
/** @param piece - Interval bounds and waveform expression. @returns One integral. */
([lower, upper, signal]): string =>
- `\\int_{${lower}}^{${upper}}\\left(${signal}\\right)${kernel}\\,dt`,
+ String.raw`\int_{${lower}}^{${upper}}\left(${signal}\right)${kernel}\,dt`,
);
- return `${label}=\\frac{2}{T_0}\\left[${integrals.join("+")}\\right]`;
+ return String.raw`${label}=\frac{2}{T_0}\left[${integrals.join("+")}\right]`;
}
/**
diff --git a/src/lib/math-engine/fourier-transform/engine.ts b/src/lib/math-engine/fourier-transform/engine.ts
index 6ada5e95..6f5214bd 100644
--- a/src/lib/math-engine/fourier-transform/engine.ts
+++ b/src/lib/math-engine/fourier-transform/engine.ts
@@ -96,15 +96,15 @@ export function getCtftPairLatex(
case "rect": {
const T = params.T ?? 1;
return {
- timeLatex: `\\operatorname{rect}\\left(\\frac{t}{${T}}\\right)`,
- freqLatex: `${T} \\operatorname{sinc}\\left(\\frac{${T} \\omega}{2 \\pi}\\right)`,
+ timeLatex: String.raw`\operatorname{rect}\left(\frac{t}{${T}}\right)`,
+ freqLatex: String.raw`${T} \operatorname{sinc}\left(\frac{${T} \omega}{2 \pi}\right)`,
};
}
case "exponential": {
const a = params.a ?? 1;
return {
timeLatex: `e^{-${a} t} u(t)`,
- freqLatex: `\\frac{1}{${a} + j\\omega}`,
+ freqLatex: String.raw`\frac{1}{${a} + j\omega}`,
};
}
case "gaussian": {
@@ -116,15 +116,15 @@ export function getCtftPairLatex(
}
case "delta": {
return {
- timeLatex: "\\delta(t)",
+ timeLatex: String.raw`\delta(t)`,
freqLatex: "1",
};
}
case "cos": {
const w0 = params.w0 ?? 1;
return {
- timeLatex: `\\cos(${w0} t)`,
- freqLatex: `\\pi \\delta(\\omega - ${w0}) + \\pi \\delta(\\omega + ${w0})`,
+ timeLatex: String.raw`\cos(${w0} t)`,
+ freqLatex: String.raw`\pi \delta(\omega - ${w0}) + \pi \delta(\omega + ${w0})`,
};
}
default: {
@@ -292,15 +292,15 @@ export function createCtftProblem(
solutionSteps: [
{
title: "Step 1: Identify Base Transform Pair",
- latex: `x_0(t) \\iff X_0(\\omega) = ${pair.freqLatex}`,
+ latex: String.raw`x_0(t) \iff X_0(\omega) = ${pair.freqLatex}`,
},
{
title: "Step 2: Apply Time-Shift Property",
- latex: `x(t - t_0) \\iff X_0(\\omega) e^{-j \\omega t_0} \\quad \\text{with } t_0 = ${t0}`,
+ latex: String.raw`x(t - t_0) \iff X_0(\omega) e^{-j \omega t_0} \quad \text{with } t_0 = ${t0}`,
},
{
title: "Step 3: Combine Terms for Final CTFT",
- latex: `X(\\omega) = ${shiftedFreqLatex}`,
+ latex: String.raw`X(\omega) = ${shiftedFreqLatex}`,
},
],
};
@@ -316,11 +316,11 @@ export function createCtftProblem(
solutionSteps: [
{
title: "Step 1: Identify Base Signal Pair",
- latex: `\\text{Recall standard CTFT transform pair: } x(t) \\iff X(\\omega)`,
+ latex: String.raw`\text{Recall standard CTFT transform pair: } x(t) \iff X(\omega)`,
},
{
title: "Step 2: Substitute Parameter Values",
- latex: `X(\\omega) = \\int_{-\\infty}^{\\infty} x(t) e^{-j\\omega t} dt = ${pair.freqLatex}`,
+ latex: String.raw`X(\omega) = \int_{-\infty}^{\infty} x(t) e^{-j\omega t} dt = ${pair.freqLatex}`,
},
],
};
diff --git a/src/lib/math-engine/fourier-transform/its-scaffolding/derivation.ts b/src/lib/math-engine/fourier-transform/its-scaffolding/derivation.ts
index 334dcce9..b0d27898 100644
--- a/src/lib/math-engine/fourier-transform/its-scaffolding/derivation.ts
+++ b/src/lib/math-engine/fourier-transform/its-scaffolding/derivation.ts
@@ -60,7 +60,8 @@ export function buildCtftDerivation(
const { T, a, w0 } = problem.params;
const halfWidth = formatCtftHalfWidth(T);
/** Simplified half-width frequency used in endpoint and sine prompts. */
- const halfFrequency = T === 2 ? String.raw`\omega` : `${halfWidth}\\omega`;
+ const halfFrequency =
+ T === 2 ? String.raw`\omega` : String.raw`${halfWidth}\omega`;
switch (problem.signalType) {
case "rect":
return {
diff --git a/src/lib/math-engine/fourier-transform/its-scaffolding/guidance.ts b/src/lib/math-engine/fourier-transform/its-scaffolding/guidance.ts
index c31bb613..24645523 100644
--- a/src/lib/math-engine/fourier-transform/its-scaffolding/guidance.ts
+++ b/src/lib/math-engine/fourier-transform/its-scaffolding/guidance.ts
@@ -293,7 +293,7 @@ function inputMetadata(
const labels: Record = {
T: "$T =$",
a: "$a =$",
- w0: "$\\omega_0 =$",
+ w0: String.raw`$\omega_0 =$`,
t0: "$t_0 =$",
limit: "$X_0(0) =$",
};
@@ -308,7 +308,7 @@ function inputMetadata(
inputSize: compact ? "scalar" : "expression",
inputLabel:
labels[task.id] ??
- (task.kind === "location" ? "$\\omega =$" : "Value"),
+ (task.kind === "location" ? String.raw`$\omega =$` : "Value"),
answerForm,
};
}
diff --git a/src/lib/math-engine/fourier-transform/its-scaffolding/lesson.ts b/src/lib/math-engine/fourier-transform/its-scaffolding/lesson.ts
index c7095baa..58a22eab 100644
--- a/src/lib/math-engine/fourier-transform/its-scaffolding/lesson.ts
+++ b/src/lib/math-engine/fourier-transform/its-scaffolding/lesson.ts
@@ -275,7 +275,7 @@ export function buildCtftLesson(
setup.mathChoices = true;
const derivation =
mode === "derivation" ? buildCtftDerivation(baseProblem) : null;
- const phase = params.t0 === 0 ? "1" : `e^{${-params.t0}j\\omega}`;
+ const phase = params.t0 === 0 ? "1" : String.raw`e^{${-params.t0}j\omega}`;
const property = part(
"operation",
"Choose the operational property",
@@ -304,7 +304,7 @@ export function buildCtftLesson(
`weight-${row}`,
`Impulse ${row + 1} complex weight`,
"weight",
- "\\pi",
+ String.raw`\pi`,
shift === 0
? String.raw`Each base cosine impulse has weight $\pi$, not $1/2$ or $2\pi$.`
: String.raw`Evaluate $\pi e^{-j\omega t_0}$ at this row's verified impulse location.`,
diff --git a/src/lib/math-engine/fourier-transform/presentation.ts b/src/lib/math-engine/fourier-transform/presentation.ts
index 9dc1adc5..06eab8be 100644
--- a/src/lib/math-engine/fourier-transform/presentation.ts
+++ b/src/lib/math-engine/fourier-transform/presentation.ts
@@ -104,8 +104,8 @@ export function exactCtftSolution(
task.kind === "location"
? String(location)
: shift === 0
- ? "\\pi"
- : `\\pi e^{-j(${location})(${shift})}`;
+ ? String.raw`\pi`
+ : String.raw`\pi e^{-j(${location})(${shift})}`;
}
return summarizeCtftInput(task, target);
}
@@ -120,7 +120,7 @@ export function displayCtftInput(input: string): string {
return normalizeMathLatex(
normalizeTransformNotation(input, "omega"),
false,
- ).replace(/\\operatorname\{DiracDelta\}/g, "\\delta");
+ ).replace(/\\operatorname\{DiracDelta\}/g, String.raw`\delta`);
} catch {
return input;
}
diff --git a/src/lib/math-engine/fraction.ts b/src/lib/math-engine/fraction.ts
index a4c165e0..c3590493 100644
--- a/src/lib/math-engine/fraction.ts
+++ b/src/lib/math-engine/fraction.ts
@@ -84,7 +84,7 @@ export function toFractionLatex(
return isNegative ? `-${num}` : `${num}`;
}
- const fracStr = `\\frac{${num}}{${den}}`;
+ const fracStr = String.raw`\frac{${num}}{${den}}`;
return isNegative ? `-${fracStr}` : fracStr;
}
diff --git a/src/lib/math-engine/laplace/algebra.ts b/src/lib/math-engine/laplace/algebra.ts
index fdaff50b..4eefa2ea 100644
--- a/src/lib/math-engine/laplace/algebra.ts
+++ b/src/lib/math-engine/laplace/algebra.ts
@@ -157,7 +157,7 @@ export function rationalLatex(value: Rational): string {
)
return polynomialLatex(value.n);
const negative = value.n.at(-1)!.numerator < 0n;
- return `${negative ? "-" : ""}\\frac{${polynomialLatex(negative ? scale(value.n, fraction(-1)) : value.n)}}{${polynomialLatex(value.d)}}`;
+ return String.raw`${negative ? "-" : ""}\frac{${polynomialLatex(negative ? scale(value.n, fraction(-1)) : value.n)}}{${polynomialLatex(value.d)}}`;
}
/** @param rows - Square augmented matrix. @returns Exact unique solution. */
diff --git a/src/lib/math-engine/laplace/answer-entry.ts b/src/lib/math-engine/laplace/answer-entry.ts
index 7aff4023..7a8abadf 100644
--- a/src/lib/math-engine/laplace/answer-entry.ts
+++ b/src/lib/math-engine/laplace/answer-entry.ts
@@ -56,7 +56,7 @@ export function renderLaplaceFields(
): string {
return frame.replace(
/\{\{([a-z0-9-]+)\}\}/g,
- (_match, id: string) => values[id]?.trim() || "\\square",
+ (_match, id: string) => values[id]?.trim() || String.raw`\square`,
);
}
@@ -69,19 +69,21 @@ export function renderLaplaceFieldTask(
task.fields.map((field) => {
const value = values[field.id] ?? "";
if (field.entry?.kind === "degree" && value === ZERO_POLYNOMIAL)
- return [field.id, "\\mathrm{undefined}"];
+ return [field.id, String.raw`\mathrm{undefined}`];
if (field.entry?.kind === "boolean")
return [
field.id,
- value === "1" ? "\\text{Active}" : "\\text{Inactive}",
+ value === "1"
+ ? String.raw`\text{Active}`
+ : String.raw`\text{Inactive}`,
];
try {
if (entryIssue(value, field.entry ?? { kind: "exact" }))
- return [field.id, "\\square"];
+ return [field.id, String.raw`\square`];
parseStrictLatex(value);
return [field.id, value];
} catch {
- return [field.id, "\\square"];
+ return [field.id, String.raw`\square`];
}
}),
);
@@ -94,12 +96,12 @@ export function laplaceAnswerLabel(id: string, kind: "s" | "t"): string {
"forward-final": "X(s)",
"factor-numerator": "N(s)",
"factor-denominator": "D(s)",
- "ode-zi": "Y_{\\mathrm{ZI}}(s)",
- "ode-zs": "Y_{\\mathrm{ZS}}(s)",
+ "ode-zi": String.raw`Y_{\mathrm{ZI}}(s)`,
+ "ode-zs": String.raw`Y_{\mathrm{ZS}}(s)`,
"ode-total": "Y(s)",
"ode-response": "y(t)",
- "ode-check-zi": "y_{\\mathrm{ZI}}(t)",
- "ode-check-zs": "y_{\\mathrm{ZS}}(t)",
+ "ode-check-zi": String.raw`y_{\mathrm{ZI}}(t)`,
+ "ode-check-zs": String.raw`y_{\mathrm{ZS}}(t)`,
};
return labels[id] ?? (kind === "t" ? "x(t)" : "F(s)");
}
diff --git a/src/lib/math-engine/laplace/construction.ts b/src/lib/math-engine/laplace/construction.ts
index d03bcf97..1d699685 100644
--- a/src/lib/math-engine/laplace/construction.ts
+++ b/src/lib/math-engine/laplace/construction.ts
@@ -204,19 +204,19 @@ export function constructionPreview(
): string {
if (draft.mode !== "finite")
return draft.mode === "zero"
- ? "\\text{Identically zero}"
- : "\\text{No finite roots}";
+ ? String.raw`\text{Identically zero}`
+ : String.raw`\text{No finite roots}`;
/** @param value - Incomplete literal. @returns Safe exact preview or an empty slot. */
const slot = (value: string): string =>
entryIssue(value, { kind: "literal" })
- ? "\\square"
+ ? String.raw`\square`
: fraction(value).toLatex();
const rows = draft.rows.map((row, index) => {
const a = slot(row.first),
b = slot(row.second),
p = slot(row.power);
if (task.kind === "roots")
- return `${a}${row.kind === "quadratic" ? `\\pm j${b === "1" ? "" : b}` : ""}\\quad\\text{multiplicity }${p}`;
+ return String.raw`${a}${row.kind === "quadratic" ? String.raw`\pm j${b === "1" ? "" : b}` : ""}\quad\text{multiplicity }${p}`;
const complete =
!entryIssue(row.first, { kind: "literal" }) &&
(row.kind === "linear" ||
@@ -236,7 +236,7 @@ export function constructionPreview(
: `s^2+(${a})s+${b}`;
const power = p === "1" ? factor : `(${factor})^{${p}}`;
if (task.kind === "template")
- return `\\frac{${row.numerator === "linear" ? `A_{${index + 1}}s+B_{${index + 1}}` : `C_{${index + 1}}`}}{${power}}`;
+ return String.raw`\frac{${row.numerator === "linear" ? `A_{${index + 1}}s+B_{${index + 1}}` : `C_{${index + 1}}`}}{${power}}`;
return p === "1" && (draft.rows.length > 1 || draft.gain !== "1")
? `(${factor})`
: power;
@@ -246,10 +246,10 @@ export function constructionPreview(
? draft.gain
: slot(draft.gain);
return task.kind === "roots"
- ? rows.join(";\\quad ") || "\\square"
+ ? rows.join(String.raw`;\quad `) || String.raw`\square`
: task.kind === "template"
? sumLatex([gain, ...rows])
- : gain === "\\square"
- ? `\\square${rows.join("")}`
+ : gain === String.raw`\square`
+ ? String.raw`\square${rows.join("")}`
: scaledLatex(fraction(draft.gain), rows.join("") || "1");
}
diff --git a/src/lib/math-engine/laplace/its-scaffolding/elimination.ts b/src/lib/math-engine/laplace/its-scaffolding/elimination.ts
index 5931337f..2daa3a4f 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/elimination.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/elimination.ts
@@ -5,7 +5,7 @@ import { teaching } from "./teaching";
/** @param rows - Exact augmented rows. @param labels - Consistent unknown names. @returns Current equations for an elimination task. */
function systemLatex(rows: Poly[], labels: string[]): string {
- return `\\begin{aligned}${rows.map((row) => `${labels.map((label, index) => `(${row[index]!.toLatex()})${label}`).join("+")}&=${row.at(-1)!.toLatex()}`).join("\\\\")}\\end{aligned}`;
+ return String.raw`\begin{aligned}${rows.map((row) => `${labels.map((label, index) => `(${row[index]!.toLatex()})${label}`).join("+")}&=${row.at(-1)!.toLatex()}`).join(String.raw`\\`)}\end{aligned}`;
}
/** @param initial - Independently derived augmented system. @param labels - Canonical coefficient names. @returns Checked rows for every nonidentity Gauss-Jordan operation. */
@@ -55,7 +55,7 @@ export function eliminationTasks(
: `coefficient of $${labels[focus]}$`;
const calculation =
source === null
- ? `\\frac{${previous[focus]!.toLatex()}}{${factor.toLatex()}}`
+ ? String.raw`\frac{${previous[focus]!.toLatex()}{${factor.toLatex()}`
: `(${previous[focus]!.toLatex()})-(${factor.toLatex()})(${rows[source]![focus]!.toLatex()})`;
const fields = next.map((value, index) => ({
id: `entry-${index}`,
diff --git a/src/lib/math-engine/laplace/its-scaffolding/forward.ts b/src/lib/math-engine/laplace/its-scaffolding/forward.ts
index ea5db960..7f7b24b8 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/forward.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/forward.ts
@@ -76,7 +76,7 @@ export function blockAnalysis(blocks: TransformBlock[]): LaplaceStage {
`block-${index}-copies-values`,
"Count exact common copies",
"Compare this block's numerator and denominator factors and count matching copies only.",
- "\\text{Common copies}={{copies}}",
+ String.raw`\text{Common copies}={{copies}}`,
[
{
id: "copies",
@@ -190,7 +190,7 @@ function zeroTasks(
`block-${index}-zero-formula-values`,
"Construct the exact quadratic roots",
"Enter the signed linear coefficient, discriminant, and twice the leading coefficient from this reduced numerator.",
- "s=\\frac{-({{b}})\\pm\\sqrt{ {{disc}} }}{ {{twoa}} }",
+ String.raw`s=\frac{-({{b}})\pm\sqrt{ {{disc}} }}{ {{twoa}} }`,
[
{
id: "b",
diff --git a/src/lib/math-engine/laplace/its-scaffolding/inverse.ts b/src/lib/math-engine/laplace/its-scaffolding/inverse.ts
index 5efa8464..2b23e16e 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/inverse.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/inverse.ts
@@ -138,9 +138,9 @@ export function pairingStage(terms: LaplaceResponseTerm[]): LaplaceStage {
fields
.map(
(field) =>
- `\\text{${field.label}}={{${field.id}}}`,
+ String.raw`\text{${field.label}}={{${field.id}}}`,
)
- .join(",\\quad "),
+ .join(String.raw`,\quad `),
fields,
),
...teaching(
diff --git a/src/lib/math-engine/laplace/its-scaffolding/ode.ts b/src/lib/math-engine/laplace/its-scaffolding/ode.ts
index 4ebde0db..35d2e48e 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/ode.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/ode.ts
@@ -154,7 +154,7 @@ export function createOdeExercise(input: OdeExercise): LaplaceExercise {
"ode-derivative-values",
"Apply the first-derivative rule",
"Substitute the supplied initial output into the verified rule, retaining its sign, including zero.",
- "\\mathcal L_+\\{y'\\}=sY(s)-({{y0}})",
+ String.raw`\mathcal L_+\{y'\}=sY(s)-({{y0}})`,
[
{
id: "y0",
@@ -181,7 +181,7 @@ export function createOdeExercise(input: OdeExercise): LaplaceExercise {
"ode-second-values",
"Apply the second-derivative rule",
"Substitute the supplied initial output and derivative into their matching slots, retaining their signs, including zeros.",
- "\\mathcal L_+\\{y''\\}=s^2Y(s)-s({{y0}})-({{dy0}})",
+ String.raw`\mathcal L_+\{y''\}=s^2Y(s)-s({{y0}})-({{dy0}})`,
[
{
id: "y0",
@@ -309,7 +309,7 @@ export function createOdeExercise(input: OdeExercise): LaplaceExercise {
return {
spec,
prompt,
- conditions: `Unilateral IVP for $t\\ge0$: $y(0^-)=${y0.toLatex()}${order === 2 ? `,\\ y'(0^-)=${dy0.toLatex()}` : ""}$.`,
+ conditions: String.raw`Unilateral IVP for $t\ge0$: $y(0^-)=${y0.toLatex()}${order === 2 ? String.raw`,\ y'(0^-)=${dy0.toLatex()}` : ""}$.`,
transform: solution.transform,
response: solution.response,
terms,
diff --git a/src/lib/math-engine/laplace/its-scaffolding/roc.ts b/src/lib/math-engine/laplace/its-scaffolding/roc.ts
index 1dacaf8c..f0a13ceb 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/roc.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/roc.ts
@@ -108,7 +108,7 @@ export function createRocExercise(input: RationalExercise): LaplaceExercise {
task(
"axis",
"Check the imaginary axis",
- "The entire line $\\Re(s)=0$ must lie inside the ROC.",
+ String.raw`The entire line $\Re(s)=0$ must lie inside the ROC.`,
"choice",
problem.stable
? "Axis is inside the ROC"
diff --git a/src/lib/math-engine/laplace/its-scaffolding/shared.ts b/src/lib/math-engine/laplace/its-scaffolding/shared.ts
index bff3f985..b153fca9 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/shared.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/shared.ts
@@ -110,7 +110,7 @@ export function rootList(factors: LaplaceFactor[]): string {
? factors
.map(
(factor) =>
- `$${factor.real}${fraction(factor.frequency).numerator !== 0n ? `\\pm j(${factor.frequency})` : ""}$ (multiplicity ${factor.multiplicity})`,
+ String.raw`$${factor.real}${fraction(factor.frequency).numerator !== 0n ? String.raw`\pm j(${factor.frequency})` : ""}$ (multiplicity ${factor.multiplicity})`,
)
.join("; ")
: "No finite roots";
@@ -146,7 +146,7 @@ export function rootTask(
"A root is a value that makes a polynomial zero. Multiplicity counts factor copies. The imaginary unit satisfies $j^2=-1$; conjugate roots $a+jb$ and $a-jb$ share real part $a$ and opposite imaginary parts.",
setup,
first
- ? `For the factor $${polynomialLatex(factorPoly(first))}$, ${fraction(first.frequency).numerator ? `complete the square to obtain $(s-(${first.real}))^2+(${first.frequency})^2=0$, giving the pair $${first.real}\\pm j(${first.frequency})$` : `subtract its constant from both sides to obtain $s=${first.real}$`}. Count its copies separately from solving its location.`
+ ? String.raw`For the factor $${polynomialLatex(factorPoly(first))}$, ${fraction(first.frequency).numerator ? String.raw`complete the square to obtain $(s-(${first.real}))^2+(${first.frequency})^2=0$, giving the pair $${first.real}\pm j(${first.frequency})$` : `subtract its constant from both sides to obtain $s=${first.real}$`}. Count its copies separately from solving its location.`
: "A nonzero constant cannot equal zero, so it has no finite roots. This differs from the zero polynomial, which vanishes at every value.",
"Check Roots",
),
@@ -314,7 +314,7 @@ export function analysisStage(
"degrees-values",
"Compare the reduced polynomial degrees",
"Enter the highest nonzero power in each reduced polynomial. For a zero numerator, choose Zero polynomial—degree undefined.",
- "\\deg N={{numerator}},\\quad\\deg D={{denominator}}",
+ String.raw`\deg N={{numerator}},\quad\deg D={{denominator}}`,
[
{
id: "numerator",
@@ -382,7 +382,7 @@ function divisionTeaching(data: LaplaceDecomposition) {
`Compare $N(s)=${polynomialLatex(data.numerator)}$ and $D(s)=${polynomialLatex(data.denominator)}$ after cancellation.`,
zero(data.numerator)
? "The numerator is zero, so the complete expression is zero. No polynomial division is needed."
- : `Here $\\deg N=${n}$ and $\\deg D=${d}$. Since $${n}${n < d ? "<" : "\\ge"}${d}$, ${n < d ? "the fraction is proper and no division is needed" : `divide the leading coefficients first to obtain constant quotient $${data.quotient}$`}.`,
+ : String.raw`Here $\deg N=${n}$ and $\deg D=${d}$. Since $${n}${n < d ? "<" : String.raw`\ge`}${d}$, ${n < d ? "the fraction is proper and no division is needed" : `divide the leading coefficients first to obtain constant quotient $${data.quotient}$`}.`,
"Check Division Decision",
);
}
@@ -477,7 +477,7 @@ function coefficientTasks(data: LaplaceDecomposition): LaplaceTask[] {
slot.factor.real,
).toLatex(),
),
- formula: `N(s)=${polynomialLatex(data.numerator)},\\quad s=${slot.factor.real}`,
+ formula: String.raw`N(s)=${polynomialLatex(data.numerator)},\quad s=${slot.factor.real}`,
...teaching(
"For a simple pole, cover-up evaluates the numerator at the pole location after removing its factor.",
`In $N(s)=${polynomialLatex(data.numerator)}$, replace every $s$ by $${slot.factor.real}$, including inside powers.`,
@@ -496,7 +496,7 @@ function coefficientTasks(data: LaplaceDecomposition): LaplaceTask[] {
slot.factor.real,
).toLatex(),
),
- formula: `D_{\\mathrm{remaining}}(s)=${polynomialLatex(divide(data.denominator, slot.denominator)[0])},\\quad s=${slot.factor.real}`,
+ formula: String.raw`D_{\mathrm{remaining}}(s)=${polynomialLatex(divide(data.denominator, slot.denominator)[0])},\quad s=${slot.factor.real}`,
...teaching(
"The remaining denominator is the original reduced denominator divided by the selected simple-pole factor.",
`Remove $${polynomialLatex(slot.denominator)}$, then evaluate $${polynomialLatex(divide(data.denominator, slot.denominator)[0])}$ at $s=${slot.factor.real}$.`,
@@ -509,7 +509,7 @@ function coefficientTasks(data: LaplaceDecomposition): LaplaceTask[] {
...task(
`coefficient-${slot.label}`,
`Calculate $${slot.label}$`,
- `Solve the verified identity for the coefficient of $\\frac{${polynomialLatex(slot.basis)}}{${polynomialLatex(slot.denominator)}}$.`,
+ String.raw`Solve the verified identity for the coefficient of $\frac{${polynomialLatex(slot.basis)}}{${polynomialLatex(slot.denominator)}}$.`,
"scalar",
slot.value,
),
@@ -603,7 +603,7 @@ export function decompositionStages(
"factor-counts-values",
"Classify the denominator factors",
"Count linear and irreducible quadratic factor copies in the verified reduced denominator.",
- "\\text{Linear copies}={{linear}},\\quad\\text{Quadratic copies}={{quadratic}}",
+ String.raw`\text{Linear copies}={{linear}},\quad\text{Quadratic copies}={{quadratic}}`,
[
{
id: "linear",
@@ -762,7 +762,7 @@ function methodDegreeTasks(data: LaplaceDecomposition): LaplaceTask[] {
"method-degrees-values",
"Compare reduced degrees",
"Enter each reduced polynomial's highest nonzero power before choosing whether to divide.",
- "\\deg N={{numerator}},\\quad\\deg D={{denominator}}",
+ String.raw`\deg N={{numerator}},\quad\deg D={{denominator}}`,
[
{
id: "numerator",
@@ -852,7 +852,7 @@ function methodCoefficientTasks(
...teaching(
"A simple-pole residue is the evaluated numerator divided by the evaluated remaining denominator.",
`Use the numerator value $${numerator}$ and remaining-denominator value $${denominator}$ checked at $s=${slot.factor.real}$. The removed pole factor must not appear in the divisor.`,
- `$${slot.label}=\\frac{${numerator}}{${denominator}}=${slot.value}$. Dividing the signed values preserves the residue's sign.`,
+ String.raw`$${slot.label}=\frac{${numerator}}{${denominator}}=${slot.value}$. Dividing the signed values preserves the residue's sign.`,
"Check Coefficient",
),
},
diff --git a/src/lib/math-engine/laplace/its-scaffolding/support.ts b/src/lib/math-engine/laplace/its-scaffolding/support.ts
index 9edf6dd4..885fc041 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/support.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/support.ts
@@ -56,7 +56,7 @@ export function supportTasks(
min: min === null ? null : `${min.numerator}/${min.denominator}`,
max: max === null ? null : `${max.numerator}/${max.denominator}`,
};
- const range = `${min?.toLatex() ?? "-\\infty"} ({
@@ -105,7 +105,7 @@ export function supportTasks(
"Transform the original terms without checking a common ROC",
]),
prompt: "Your checked intervals assemble the ordinary signal below. The independently verified supported representation has a common ROC; carry it into the transform pairs.",
- formula: `x_{\\mathrm{regular}}(t)=\\begin{cases}${intervals.join("\\\\")}\\end{cases}`,
+ formula: String.raw`x_{\mathrm{regular}}(t)=\begin{cases}${intervals.join(String.raw`\\`)}\end{cases}`,
...teaching(
"Linearity permits adding individual Laplace transforms where those transforms have a common region of convergence. Combining canceled tails first can expose that region.",
`Use your checked interval sums, preserving these separate impulse terms: $${responseLatex(original.filter((term) => term.kind === "impulse"))}$.`,
diff --git a/src/lib/math-engine/laplace/its-scaffolding/teaching.ts b/src/lib/math-engine/laplace/its-scaffolding/teaching.ts
index dc63f9da..f0731e64 100644
--- a/src/lib/math-engine/laplace/its-scaffolding/teaching.ts
+++ b/src/lib/math-engine/laplace/its-scaffolding/teaching.ts
@@ -102,7 +102,7 @@ function initialStateTeaching(
"Differentiation in time becomes multiplication by $s$, with subtracted initial-state terms in the unilateral transform.",
id.includes("second")
? "Apply the first-derivative rule twice: the second application also subtracts $y'(0^-)$, while the initial output acquires a factor of $s$."
- : "Use $\\mathcal L_+\\{y'\\}=sY(s)-y(0^-)$. Substitute a signed initial value inside the subtraction; enter zero explicitly.",
+ : String.raw`Use $\mathcal L_+\{y'\}=sY(s)-y(0^-)$. Substitute a signed initial value inside the subtraction; enter zero explicitly.`,
"For example, if $y(0^-)=-2$, the first-derivative transform is $sY(s)-(-2)=sY(s)+2$. The rule subtracts the value, not its magnitude.",
"Check Initial-Condition Substitution",
);
@@ -256,14 +256,14 @@ function regionTeaching(id: string): Teaching | undefined {
return teaching(
"The ROC is the open set of complex values where the transform converges. Poles are excluded; zeros do not set its boundaries.",
"Sort the distinct real parts of surviving poles. Right-sided modes require a region to their right; left-sided modes require one to their left. Intersect these requirements.",
- "For poles at $-5$ and $-3$, candidate regions are $\\Re(s)<-5$, $-5<\\Re(s)<-3$, and $\\Re(s)>-3$. Finite-duration sums require checking cancellation of their infinite tails.",
+ String.raw`For poles at $-5$ and $-3$, candidate regions are $\Re(s)<-5$, $-5<\Re(s)<-3$, and $\Re(s)>-3$. Finite-duration sums require checking cancellation of their infinite tails.`,
"Check Region of Convergence",
);
if (["axis", "bibo", "stability"].includes(id))
return teaching(
"BIBO stability concerns bounded inputs producing bounded outputs. For this system-analysis family, check whether the entire imaginary axis lies in the ROC.",
"The imaginary axis has real part zero. Substitute zero into the strict ROC inequalities; a boundary at zero does not count as inside.",
- "For example, $\\Re(s)>-3$ contains the imaginary axis, but $\\Re(s)>0$ excludes it. This establishes input-output stability, not hidden internal stability.",
+ String.raw`For example, $\Re(s)>-3$ contains the imaginary axis, but $\Re(s)>0$ excludes it. This establishes input-output stability, not hidden internal stability.`,
"Check System Stability",
);
if (id === "side" || id === "causality")
@@ -341,18 +341,18 @@ export function signalFamilyChoices(
): NonNullable {
const support = side === "left" ? "u(d-t)" : "u(t-d)";
return {
- impulse: { label: "Impulse", math: "A\\delta(t-d)" },
+ impulse: { label: "Impulse", math: String.raw`A\delta(t-d)` },
exponential: {
label: "Step / polynomial exponential",
math: `A(t-d)^n e^{a(t-d)}${support}`,
},
cosine: {
label: "Damped cosine",
- math: `Ae^{a(t-d)}\\cos(\\omega(t-d))${support}`,
+ math: String.raw`Ae^{a(t-d)}\cos(\omega(t-d))${support}`,
},
sine: {
label: "Damped sine",
- math: `Ae^{a(t-d)}\\sin(\\omega(t-d))${support}`,
+ math: String.raw`Ae^{a(t-d)}\sin(\omega(t-d))${support}`,
},
};
}
@@ -381,7 +381,7 @@ export function teachRoc(
? poles
.map(
(pole) =>
- `$${pole.real}${fraction(pole.frequency).numerator ? `\\pm j(${pole.frequency})` : ""}$`,
+ String.raw`$${pole.real}${fraction(pole.frequency).numerator ? String.raw`\pm j(${pole.frequency})` : ""}$`,
)
.join(", ")
: "none";
@@ -404,7 +404,7 @@ export function teachRoc(
: support
? `Here the selected region has ${bounds[0] === -Infinity && bounds[1] === Infinity ? "no pole boundary, so ordinary left/right exponential classification alone is insufficient" : bounds[0] === -Infinity ? "an upper boundary, requiring left-sided ordinary modes" : bounds[1] === Infinity ? "a lower boundary, requiring right-sided ordinary modes" : "two boundaries, requiring a mixture of left- and right-sided modes"}. A causal response must additionally vanish at every negative time.`
: boundary
- ? `One boundary is $\\Re(s)=${boundary.real}$. The leftmost candidate region lies strictly to its left. Adjacent distinct real parts create interior strips; repeated poles or equal real parts do not create extra strips.`
+ ? String.raw`One boundary is $\Re(s)=${boundary.real}$. The leftmost candidate region lies strictly to its left. Adjacent distinct real parts create interior strips; repeated poles or equal real parts do not create extra strips.`
: "There are no surviving poles. For a zero or impulse-only response, the entire finite complex plane is available; do not introduce boundaries from canceled factors.",
],
explanation: `${stability ? "The imaginary-axis check establishes the input-output stability conclusion." : support ? "The supplied region and time support establish this classification." : "The selected region is open, excludes poles, and respects the supplied support."} ${task.answer}`,
diff --git a/src/lib/math-engine/laplace/legacy.ts b/src/lib/math-engine/laplace/legacy.ts
index c164039d..324ffc85 100644
--- a/src/lib/math-engine/laplace/legacy.ts
+++ b/src/lib/math-engine/laplace/legacy.ts
@@ -201,21 +201,21 @@ export function determineStability(
const isBiboStable = maxPole < 0;
return {
isBiboStable,
- rocLatex: `\\operatorname{Re}(s) > ${maxPole}`,
+ rocLatex: String.raw`\operatorname{Re}(s) > ${maxPole}`,
};
}
case "left-sided": {
const isBiboStable = minPole > 0;
return {
isBiboStable,
- rocLatex: `\\operatorname{Re}(s) < ${minPole}`,
+ rocLatex: String.raw`\operatorname{Re}(s) < ${minPole}`,
};
}
case "two-sided": {
const isBiboStable = minPole < 0 && maxPole > 0;
return {
isBiboStable,
- rocLatex: `${minPole} < \\operatorname{Re}(s) < ${maxPole}`,
+ rocLatex: String.raw`${minPole} < \operatorname{Re}(s) < ${maxPole}`,
};
}
default: {
@@ -241,12 +241,12 @@ export function getLaplacePairLatex(type: string): {
case "exp":
return {
timeLatex: "e^{-a t} u(t)",
- laplaceLatex: "\\frac{1}{s + a}",
+ laplaceLatex: String.raw`\frac{1}{s + a}`,
};
case "step":
- return { timeLatex: "u(t)", laplaceLatex: "\\frac{1}{s}" };
+ return { timeLatex: "u(t)", laplaceLatex: String.raw`\frac{1}{s}` };
case "delta":
- return { timeLatex: "\\delta(t)", laplaceLatex: "1" };
+ return { timeLatex: String.raw`\delta(t)`, laplaceLatex: "1" };
default:
throw new Error(`Unknown Laplace pair: ${type}`);
}
@@ -346,20 +346,20 @@ function createTrigonometricInverse(id: string): LaplaceProblem {
return {
id,
problemType: "inverse_direct",
- promptLatex: `\\text{Find } x(t) = \\mathcal{L}^{-1}\\left\\{\\frac{${A}s + ${bOmega}}{s^2 + ${wSq}}\\right\\}`,
- referenceAnswerLatex: `(${A} \\cos(${omega}t) + ${B} \\sin(${omega}t)) u(t)`,
+ promptLatex: String.raw`\text{Find } x(t) = \mathcal{L}^{-1}\left\{\frac{${A}s + ${bOmega}}{s^2 + ${wSq}}\right\}`,
+ referenceAnswerLatex: String.raw`(${A} \cos(${omega}t) + ${B} \sin(${omega}t)) u(t)`,
solutionSteps: [
{
title: "Step 1: Separate into Cosine and Sine Terms",
- latex: `X(s) = ${A} \\cdot \\frac{s}{s^2 + ${omega}^2} + ${B} \\cdot \\frac{${omega}}{s^2 + ${omega}^2}`,
+ latex: String.raw`X(s) = ${A} \cdot \frac{s}{s^2 + ${omega}^2} + ${B} \cdot \frac{${omega}}{s^2 + ${omega}^2}`,
},
{
title: "Step 2: Recall Standard Trigonometric Pairs",
- latex: `\\mathcal{L}^{-1}\\left\\{\\frac{s}{s^2 + ${omega}^2}\\right\\} = \\cos(${omega}t) u(t), \\quad \\mathcal{L}^{-1}\\left\\{\\frac{${omega}}{s^2 + ${omega}^2}\\right\\} = \\sin(${omega}t) u(t)`,
+ latex: String.raw`\mathcal{L}^{-1}\left\{\frac{s}{s^2 + ${omega}^2\right\} = \cos(${omega}t) u(t), \quad \mathcal{L}^{-1}\left\{\frac{${omega}}{s^2 + ${omega}^2\right\} = \sin(${omega}t) u(t)`,
},
{
title: "Step 3: Combine Terms by Linearity",
- latex: `x(t) = (${A} \\cos(${omega}t) + ${B} \\sin(${omega}t)) u(t)`,
+ latex: String.raw`x(t) = (${A} \cos(${omega}t) + ${B} \sin(${omega}t)) u(t)`,
},
],
};
@@ -378,20 +378,20 @@ function createDelayedInverse(id: string): LaplaceProblem {
return {
id,
problemType: "inverse_direct",
- promptLatex: `\\text{Find } x(t) = \\mathcal{L}^{-1}\\left\\{\\frac{${A} e^{-${t0}s}}{s + ${a}}\\right\\}`,
+ promptLatex: String.raw`\text{Find } x(t) = \mathcal{L}^{-1}\left\{\frac{${A} e^{-${t0}s}}{s + ${a}}\right\}`,
referenceAnswerLatex: `${A} e^{-${a}(t-${t0})} u(t-${t0})`,
solutionSteps: [
{
title: "Step 1: Identify Time-Shift Property",
- latex: `\\mathcal{L}^{-1}\\{e^{-${t0}s} F(s)\\} = f(t - ${t0}) u(t - ${t0})`,
+ latex: String.raw`\mathcal{L}^{-1}\{e^{-${t0}s} F(s)\} = f(t - ${t0}) u(t - ${t0})`,
},
{
title: "Step 2: Inverse Transform of Unshifted Term",
- latex: `\\mathcal{L}^{-1}\\left\\{\\frac{${A}}{s + ${a}}\\right\\} = ${A} e^{-${a}t} u(t)`,
+ latex: String.raw`\mathcal{L}^{-1}\left\{\frac{${A}}{s + ${a}}\right\} = ${A} e^{-${a}t} u(t)`,
},
{
title: "Step 3: Apply Time Shift",
- latex: `x(t) = ${A} e^{-${a}(t-${t0})} u(t-${t0})`,
+ latex: String.raw`x(t) = ${A} e^{-${a}(t-${t0})} u(t-${t0})`,
},
],
};
@@ -410,16 +410,16 @@ function createImpulseInverse(id: string): LaplaceProblem {
return {
id,
problemType: "inverse_direct",
- promptLatex: `\\text{Find } x(t) = \\mathcal{L}^{-1}\\left\\{${A} + \\frac{${B}}{s + ${a}}\\right\\}`,
- referenceAnswerLatex: `${A} \\delta(t) + ${B} e^{-${a}t} u(t)`,
+ promptLatex: String.raw`\text{Find } x(t) = \mathcal{L}^{-1}\left\{${A} + \frac{${B}}{s + ${a}}\right\}`,
+ referenceAnswerLatex: String.raw`${A} \delta(t) + ${B} e^{-${a}t} u(t)`,
solutionSteps: [
{
title: "Step 1: Identify Impulse & Exponential Pairs",
- latex: `\\mathcal{L}^{-1}\\{1\\} = \\delta(t), \\quad \\mathcal{L}^{-1}\\left\\{\\frac{1}{s + ${a}}\\right\\} = e^{-${a}t} u(t)`,
+ latex: String.raw`\mathcal{L}^{-1}\{1\} = \delta(t), \quad \mathcal{L}^{-1}\left\{\frac{1}{s + ${a}}\right\} = e^{-${a}t} u(t)`,
},
{
title: "Step 2: Combine Terms",
- latex: `x(t) = ${A} \\delta(t) + ${B} e^{-${a}t} u(t)`,
+ latex: String.raw`x(t) = ${A} \delta(t) + ${B} e^{-${a}t} u(t)`,
},
],
};
@@ -445,16 +445,16 @@ function generateForwardTransform(id: string): LaplaceProblem {
return {
id,
problemType: "forward",
- promptLatex: `\\text{Find } X(s) = \\mathcal{L}\\{x(t)\\} \\text{ for } x(t) = (${c1} e^{-${a1}t} + ${c2} e^{-${a2}t}) u(t)`,
- referenceAnswerLatex: `\\frac{${b1}s + ${b0}}{s^2 + ${d1}s + ${d0}}`,
+ promptLatex: String.raw`\text{Find } X(s) = \mathcal{L}\{x(t)\} \text{ for } x(t) = (${c1} e^{-${a1}t} + ${c2} e^{-${a2}t}) u(t)`,
+ referenceAnswerLatex: String.raw`\frac{${b1}s + ${b0}}{s^2 + ${d1}s + ${d0}}`,
solutionSteps: [
{
title: "Step 1: Apply Exponential Transform Pair",
- latex: `\\mathcal{L}\\{e^{-at} u(t)\\} = \\frac{1}{s + a} \\implies X(s) = \\frac{${c1}}{s+${a1}} + \\frac{${c2}}{s+${a2}}`,
+ latex: String.raw`\mathcal{L}\{e^{-at} u(t)\} = \frac{1}{s + a} \implies X(s) = \frac{${c1}}{s+${a1}} + \frac{${c2}}{s+${a2}}`,
},
{
title: "Step 2: Combine Terms Over Common Denominator",
- latex: `X(s) = \\frac{${c1}(s+${a2}) + ${c2}(s+${a1})}{(s+${a1})(s+${a2})} = \\frac{${b1}s + ${b0}}{s^2 + ${d1}s + ${d0}}`,
+ latex: String.raw`X(s) = \frac{${c1}(s+${a2}) + ${c2}(s+${a1})}{(s+${a1})(s+${a2})} = \frac{${b1}s + ${b0}}{s^2 + ${d1}s + ${d0}}`,
},
],
};
@@ -486,20 +486,20 @@ function generateRocProblem(id: string): LaplaceProblem {
return {
id,
problemType: "roc_stability",
- promptLatex: `\\text{Determine ROC and BIBO stability for } ${direction} \\text{ system } X(s) = \\frac{1}{(s - (${p1}))(s - (${p2}))}`,
- referenceAnswerLatex: `${stability.rocLatex}, \\quad \\text{${stability.isBiboStable ? "BIBO Stable" : "Unstable"}}`,
+ promptLatex: String.raw`\text{Determine ROC and BIBO stability for } ${direction} \text{ system } X(s) = \frac{1}{(s - (${p1}))(s - (${p2}))}`,
+ referenceAnswerLatex: String.raw`${stability.rocLatex}, \quad \text{${stability.isBiboStable ? "BIBO Stable" : "Unstable"}}`,
solutionSteps: [
{
title: "Step 1: Identify System Poles",
- latex: `D(s) = 0 \\implies p_1 = ${p1}, \\quad p_2 = ${p2}`,
+ latex: String.raw`D(s) = 0 \implies p_1 = ${p1}, \quad p_2 = ${p2}`,
},
{
title: "Step 2: Determine ROC Region",
- latex: `\\text{ROC for } ${direction} \\text{ system is } ${stability.rocLatex}`,
+ latex: String.raw`\text{ROC for } ${direction} \text{ system is } ${stability.rocLatex}`,
},
{
title: "Step 3: Check Stability Criteria",
- latex: `\\operatorname{Re}(s) = 0 \\text{ ${stability.isBiboStable ? "is contained in" : "is NOT contained in"} ROC } \\implies \\text{${stability.isBiboStable ? "BIBO Stable" : "Unstable"}}`,
+ latex: String.raw`\operatorname{Re}(s) = 0 \text{ ${stability.isBiboStable ? "is contained in" : "is NOT contained in"} ROC } \implies \text{${stability.isBiboStable ? "BIBO Stable" : "Unstable"}}`,
},
],
};
diff --git a/src/lib/math-engine/laplace/pfd.ts b/src/lib/math-engine/laplace/pfd.ts
index bb6587ae..f9b52100 100644
--- a/src/lib/math-engine/laplace/pfd.ts
+++ b/src/lib/math-engine/laplace/pfd.ts
@@ -226,7 +226,7 @@ export function decompose(
n: scale(slot.basis, fractionLatex(slot.value)),
d: slot.denominator,
})
- : `\\frac{${slot.label}${slot.basis.length === 1 && slot.basis[0]!.numerator === slot.basis[0]!.denominator ? "" : `(${polynomialLatex(slot.basis)})`}}{${polynomialLatex(slot.denominator)}}`,
+ : String.raw`\frac{${slot.label}${slot.basis.length === 1 && slot.basis[0]!.numerator === slot.basis[0]!.denominator ? "" : `(${polynomialLatex(slot.basis)})`}}{${polynomialLatex(slot.denominator)}}`,
),
]);
return {
@@ -284,11 +284,11 @@ export function formatRoc(
};
return lower === -Infinity
? upper === Infinity
- ? "s\\in\\mathbb C"
- : `\\operatorname{Re}(s)<${label(upper)}`
+ ? String.raw`s\in\mathbb C`
+ : String.raw`\operatorname{Re}(s)<${label(upper)}`
: upper === Infinity
- ? `\\operatorname{Re}(s)>${label(lower)}`
- : `${label(lower)}<\\operatorname{Re}(s)<${label(upper)}`;
+ ? String.raw`\operatorname{Re}(s)>${label(lower)}`
+ : String.raw`${label(lower)}<\operatorname{Re}(s)<${label(upper)}`;
}
/** @param value - Nonnegative integer. @returns Exact small factorial. */
diff --git a/src/lib/math-engine/laplace/signals.ts b/src/lib/math-engine/laplace/signals.ts
index 8e85e408..cd30f17d 100644
--- a/src/lib/math-engine/laplace/signals.ts
+++ b/src/lib/math-engine/laplace/signals.ts
@@ -101,7 +101,7 @@ function formatSignal(term: LaplaceSignalTerm, supported: boolean): string {
amplitude = fractionLatex(term.amplitude);
const time = shiftedTime(term.delay);
if (term.kind === "impulse")
- return scaledLatex(amplitude, `\\delta(${time})`);
+ return scaledLatex(amplitude, String.raw`\delta(${time})`);
const rate = fraction(term.rate),
frequency = fraction(term.frequency);
const polynomial =
@@ -113,7 +113,9 @@ function formatSignal(term: LaplaceSignalTerm, supported: boolean): string {
: "";
const trig =
term.kind === "cosine" || term.kind === "sine"
- ? `\\${term.kind === "cosine" ? "cos" : "sin"}(${scaledLatex(frequency, time, !!delay.numerator)})`
+ ? term.kind === "cosine"
+ ? String.raw`\cos(${scaledLatex(frequency, time, !!delay.numerator)})`
+ : String.raw`\sin(${scaledLatex(frequency, time, !!delay.numerator)})`
: "";
const support =
term.side === "left"
diff --git a/src/lib/math-engine/laplace/transform.ts b/src/lib/math-engine/laplace/transform.ts
index e766563b..6ceee16c 100644
--- a/src/lib/math-engine/laplace/transform.ts
+++ b/src/lib/math-engine/laplace/transform.ts
@@ -138,7 +138,7 @@ export function zeroDescription(numerator: Poly): string {
const discriminant = b!
.multiply(b!)
.add(a!.multiply(c!).multiply(fraction(-4)));
- return `$s=\\frac{-(${b!.toLatex()})\\pm\\sqrt{${discriminant.toLatex()}}}{${a!.multiply(fraction(2)).toLatex()}}$`;
+ return String.raw`$s=\frac{-(${b!.toLatex()})\pm\sqrt{${discriminant.toLatex()}}}{${a!.multiply(fraction(2)).toLatex()}}$`;
}
return `The finite solutions of $${polynomialLatex(numerator)}=0$`;
}
diff --git a/src/lib/math-engine/odes/formatting.ts b/src/lib/math-engine/odes/formatting.ts
index 2fcf0a3a..4c319f1e 100644
--- a/src/lib/math-engine/odes/formatting.ts
+++ b/src/lib/math-engine/odes/formatting.ts
@@ -24,7 +24,7 @@ export function formatHarmonicScalar(value: number): string {
if (!Number.isFinite(value) || value === 0) return ordinary;
if (ordinary !== "0" && !/[eE][+-]?\d/.test(ordinary)) return ordinary;
const [mantissa, exponent] = value.toExponential().split("e");
- return `${mantissa} \\times 10^{${Number(exponent)}}`;
+ return String.raw`${mantissa} \times 10^{${Number(exponent)}}`;
}
/**
@@ -76,12 +76,12 @@ export function formatHomogeneousResponse(
case "complex_conjugate": {
const term1 = formatSignedLinearTerm(
c1,
- `\\cos(${roots.im ?? 0}t)`,
+ String.raw`\cos(${roots.im ?? 0}t)`,
true,
);
const term2 = formatSignedLinearTerm(
c2,
- `\\sin(${roots.im ?? 0}t)`,
+ String.raw`\sin(${roots.im ?? 0}t)`,
false,
);
const expTerm = roots.r1 !== 0 ? formatExpTerm(roots.r1) : "";
diff --git a/src/lib/math-engine/odes/its-scaffolding/step5-coefficients.ts b/src/lib/math-engine/odes/its-scaffolding/step5-coefficients.ts
index effa4f3e..66b2fd2b 100644
--- a/src/lib/math-engine/odes/its-scaffolding/step5-coefficients.ts
+++ b/src/lib/math-engine/odes/its-scaffolding/step5-coefficients.ts
@@ -258,7 +258,7 @@ function formatCoefficientSystem(equation: TrialTerm[]): string {
}
return equations.length === 1
? equations.join("")
- : `\\begin{cases} ${equations.join(" \\\\ ")} \\end{cases}`;
+ : String.raw`\begin{cases} ${equations.join(String.raw` \\ `)} \end{cases}`;
}
/**
@@ -361,7 +361,7 @@ export function buildStep5Data(params: BuildStep5Params): OdeItsStep5 {
} = context;
const systemLatex = formatCoefficientSystem(equation);
const firstDerivLatex = `y_p'(t) = ${formatTrial(first, rate, frequency)}`;
- const substitutionLatex = `${resolvedOrder === 2 ? `${toFractionLatex(a2)}\\left(${formatTrial(second, rate, frequency)}\\right) + ` : ""}${toFractionLatex(a1)}\\left(${formatTrial(first, rate, frequency)}\\right) + ${toFractionLatex(a0)}\\left(${formatTrial(trial, rate, frequency)}\\right) = ${forcing.latex}`;
+ const substitutionLatex = String.raw`${resolvedOrder === 2 ? String.raw`${toFractionLatex(a2)}\left(${formatTrial(second, rate, frequency)}\right) + ` : ""}${toFractionLatex(a1)}\left(${formatTrial(first, rate, frequency)}\right) + ${toFractionLatex(a0)}\left(${formatTrial(trial, rate, frequency)}\right) = ${forcing.latex}`;
const secondDerivLatex = `y_p''(t) = ${formatTrial(second, rate, frequency)}`;
const firstDerivativeOptions = shuffleWithRandom(
derivativeChoices(first, rate, frequency, 1, trial),
@@ -374,7 +374,7 @@ export function buildStep5Data(params: BuildStep5Params): OdeItsStep5 {
const systemOptions = buildSystemChoices(context);
const solved =
forcing.type === "sinusoid"
- ? `$A = ${toFractionLatex(particular.coeffs.A ?? 0)}, \\quad B = ${toFractionLatex(particular.coeffs.B ?? 0)}$.`
+ ? String.raw`$A = ${toFractionLatex(particular.coeffs.A ?? 0)}, \quad B = ${toFractionLatex(particular.coeffs.B ?? 0)}$.`
: `$K_p = ${toFractionLatex(particular.coeffs.Kp ?? 0)}$.`;
const derivativeHint =
power > 0
@@ -393,7 +393,7 @@ export function buildStep5Data(params: BuildStep5Params): OdeItsStep5 {
derivativesLatex:
resolvedOrder === 1
? firstDerivLatex
- : `${firstDerivLatex}, \\quad ${secondDerivLatex}`,
+ : String.raw`${firstDerivLatex}, \quad ${secondDerivLatex}`,
systemLatex,
substitutionLatex,
hints: [
diff --git a/src/lib/math-engine/odes/its-scaffolding/step7-decomposition.ts b/src/lib/math-engine/odes/its-scaffolding/step7-decomposition.ts
index 9b29bd62..67cf8880 100644
--- a/src/lib/math-engine/odes/its-scaffolding/step7-decomposition.ts
+++ b/src/lib/math-engine/odes/its-scaffolding/step7-decomposition.ts
@@ -84,7 +84,7 @@ export const CONCEPT_QUESTIONS_POOL: OdeItsConceptQuestion[] = [
"By definition, the Zero-Input response $y_{ZI}(t)$ depends linearly on the initial state. When $y(0^-)=0$ and $y'(0^-)=0$, $y_{ZI}(t) = 0$, so $y(t) = y_{ZI}(t) + y_{ZS}(t) = y_{ZS}(t)$.",
},
{
- prompt: "For a stable system with characteristic roots $\\operatorname{Re}(r_i) < 0$, what happens to the transient response $y_{tr}(t)$ as $t \\to \\infty$?",
+ prompt: String.raw`For a stable system with characteristic roots $\operatorname{Re}(r_i) < 0$, what happens to the transient response $y_{tr}(t)$ as $t \to \infty$?`,
options: [
{
id: "cq3_opt1",
@@ -272,7 +272,7 @@ function buildResponseChoices(params: BuildStep7Params) {
A: particularScale * (particular.coeffs.A ?? 0),
B: particularScale * (particular.coeffs.B ?? 0),
});
- const firstBasis = `${formatExpTerm(roots.r1)}${resolvedOrder === 2 && resolvedRootType === "complex_conjugate" ? ` \\cos(${roots.im ?? 1}t)` : ""}`;
+ const firstBasis = `${formatExpTerm(roots.r1)}${resolvedOrder === 2 && resolvedRootType === "complex_conjugate" ? String.raw` \cos(${roots.im ?? 1}t)` : ""}`;
// The legacy array names retain compatibility; the mode defines their meaning.
const transientOptions: OdeItsOption[] = [
{
diff --git a/src/lib/math-engine/odes/its-scaffolding/trial-algebra.ts b/src/lib/math-engine/odes/its-scaffolding/trial-algebra.ts
index cd32c81d..ccb01b17 100644
--- a/src/lib/math-engine/odes/its-scaffolding/trial-algebra.ts
+++ b/src/lib/math-engine/odes/its-scaffolding/trial-algebra.ts
@@ -118,7 +118,9 @@ export function formatTrial(
? rate === 0
? ""
: formatExpTerm(rate)
- : `\\${term.harmonic}(${toFractionLatex(frequency)}t)`;
+ : term.harmonic === "cos"
+ ? String.raw`\cos(${toFractionLatex(frequency)}t)`
+ : String.raw`\sin(${toFractionLatex(frequency)}t)`;
const symbol = term.symbol === "input" ? "" : term.symbol;
fragments.push(
formatSignedLinearTerm(
diff --git a/src/lib/math-engine/odes/solver.ts b/src/lib/math-engine/odes/solver.ts
index 2f8a3c1e..5e576226 100644
--- a/src/lib/math-engine/odes/solver.ts
+++ b/src/lib/math-engine/odes/solver.ts
@@ -393,13 +393,12 @@ function computeSinusoidalParticular(
);
if (multiplicity === 1) {
return {
- formDescription:
- "y_p(t) = t[A \\cos(\\omega t) + B \\sin(\\omega t)]",
+ formDescription: String.raw`y_p(t) = t[A \cos(\omega t) + B \sin(\omega t)]`,
latex:
sanitizeLatexMath(
formatSignedLinearTerm(
formatHarmonicScalar(B),
- `t \\sin(${frequencyLatex}t)`,
+ String.raw`t \sin(${frequencyLatex}t)`,
true,
),
) || "0",
@@ -416,15 +415,15 @@ function computeSinusoidalParticular(
const latexB = formatHarmonicScalar(B);
let latexStr = "";
- if (A !== 0) latexStr += `${latexA} \\cos(${frequencyLatex}t)`;
+ if (A !== 0) latexStr += String.raw`${latexA} \cos(${frequencyLatex}t)`;
if (B > 0)
- latexStr += `${latexStr ? " + " : ""}${latexB} \\sin(${frequencyLatex}t)`;
+ latexStr += String.raw`${latexStr ? " + " : ""}${latexB} \sin(${frequencyLatex}t)`;
else if (B < 0)
- latexStr += `${latexStr ? " - " : "-"}${formatHarmonicScalar(Math.abs(B))} \\sin(${frequencyLatex}t)`;
+ latexStr += String.raw`${latexStr ? " - " : "-"}${formatHarmonicScalar(Math.abs(B))} \sin(${frequencyLatex}t)`;
if (!latexStr) latexStr = "0";
return {
- formDescription: "y_p(t) = A \\cos(\\omega t) + B \\sin(\\omega t)",
+ formDescription: String.raw`y_p(t) = A \cos(\omega t) + B \sin(\omega t)`,
latex: latexStr,
/** @param t - Evaluation time. @returns Harmonic particular response. */
eval: (t: number) => evaluateHarmonic(A, B, w, t),
@@ -544,12 +543,12 @@ export function solveHomogeneousConstants(
const cosTerm = formatSignedLinearTerm(
c1Str,
- `\\cos(${toFractionLatex(omega_d)}t)`,
+ String.raw`\cos(${toFractionLatex(omega_d)}t)`,
true,
);
const sinTerm = formatSignedLinearTerm(
c2Str,
- `\\sin(${toFractionLatex(omega_d)}t)`,
+ String.raw`\sin(${toFractionLatex(omega_d)}t)`,
false,
);
const inner = `${cosTerm} ${sinTerm}`.trim();
diff --git a/src/lib/math-engine/real-evaluation.ts b/src/lib/math-engine/real-evaluation.ts
index 48ee07c2..47b7b43b 100644
--- a/src/lib/math-engine/real-evaluation.ts
+++ b/src/lib/math-engine/real-evaluation.ts
@@ -13,7 +13,7 @@ type Operation = (args: unknown[], vars: Bindings) => number | null;
* @returns Assigned value, known constant, or null.
*/
function resolveSymbol(symbol: string, vars: Bindings): number | null {
- if (["Pi", "pi", "\\pi"].includes(symbol)) return Math.PI;
+ if (["Pi", "pi", String.raw`\pi`].includes(symbol)) return Math.PI;
if (["ExponentialE", "e"].includes(symbol)) return Math.E;
return symbol in vars ? (vars[symbol] ?? null) : null;
}
diff --git a/src/lib/math-engine/transform-notation.ts b/src/lib/math-engine/transform-notation.ts
index 3a393b26..294400d8 100644
--- a/src/lib/math-engine/transform-notation.ts
+++ b/src/lib/math-engine/transform-notation.ts
@@ -77,12 +77,12 @@ function normalizeGroups(source: string): string {
let previous = "";
for (let index = 0; index < tokens.length; index++) {
const token = tokens[index]!;
- if (token === "\\left" || token === "\\right") {
+ if (token === String.raw`\left` || token === String.raw`\right`) {
index = sizedDelimiter(tokens, index + 1);
output.push(
groupToken(
tokens[index]!,
- token === "\\right",
+ token === String.raw`\right`,
true,
false,
stack,
@@ -94,7 +94,7 @@ function normalizeGroups(source: string): string {
token,
")]}".includes(token),
false,
- token === "[" && previous === "\\sqrt",
+ token === "[" && previous === String.raw`\sqrt`,
stack,
),
);
@@ -163,11 +163,14 @@ export function normalizeTransformNotation(
"Enter one expression or use the problem's supported equation prefix.",
);
return expression
- .replace(/Ï€/g, "\\pi ")
- .replace(/\\delta\b/g, "\\operatorname{DiracDelta}")
- .replace(/(^|[^a-zA-Z\\])sinc(?=\s*\()/g, "$1\\operatorname{sinc}")
- .replace(/(^|[^a-zA-Z\\])([ij])(?:omega|w)\b/g, "$1$2\\omega")
- .replace(/(^|[^a-zA-Z\\])omega\b/g, "$1\\omega")
- .replace(/(^|[^a-zA-Z\\])w\b/g, "$1\\omega")
+ .replace(/Ï€/g, String.raw`\pi `)
+ .replace(/\\delta\b/g, String.raw`\operatorname{DiracDelta}`)
+ .replace(
+ /(^|[^a-zA-Z\\])sinc(?=\s*\()/g,
+ String.raw`$1\operatorname{sinc}`,
+ )
+ .replace(/(^|[^a-zA-Z\\])([ij])(?:omega|w)\b/g, String.raw`$1$2\omega`)
+ .replace(/(^|[^a-zA-Z\\])omega\b/g, String.raw`$1\omega`)
+ .replace(/(^|[^a-zA-Z\\])w\b/g, String.raw`$1\omega`)
.trim();
}
diff --git a/src/lib/problems/bank/circuits-bank.ts b/src/lib/problems/bank/circuits-bank.ts
index 182cceff..1bbc7a35 100644
--- a/src/lib/problems/bank/circuits-bank.ts
+++ b/src/lib/problems/bank/circuits-bank.ts
@@ -12,17 +12,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-1",
components: { R: 20, L: 2, C: 0.05 },
topology: "series-rlc",
- promptLatex:
- "\\text{Derive } H(s) = \\frac{V_R(s)}{V_{in}(s)} \\text{ for Series RLC with } R = 20\\Omega, L = 2\\text{H}, C = 0.05\\text{F}",
- referenceAnswerLatex: "\\frac{10 s}{s^2 + 10 s + 10}",
+ promptLatex: String.raw`\text{Derive } H(s) = \frac{V_R(s)}{V_{in}(s)} \text{ for Series RLC with } R = 20\Omega, L = 2\text{H}, C = 0.05\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{10 s}{s^2 + 10 s + 10}`,
solutionSteps: [
{
title: "Step 1: Impedance Voltage Divider",
- latex: "H(s) = \\frac{R}{sL + R + \\frac{1}{sC}} = \\frac{\\frac{R}{L} s}{s^2 + \\frac{R}{L} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{R}{sL + R + \frac{1}{sC}} = \frac{\frac{R}{L} s}{s^2 + \frac{R}{L} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Plug in Values",
- latex: "\\frac{R}{L} = 10, \\quad \\omega_0^2 = \\frac{1}{2 \\times 0.05} = 10 \\implies H(s) = \\frac{10s}{s^2 + 10s + 10}",
+ latex: String.raw`\frac{R}{L} = 10, \quad \omega_0^2 = \frac{1}{2 \times 0.05} = 10 \implies H(s) = \frac{10s}{s^2 + 10s + 10}`,
},
],
},
@@ -30,17 +29,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-2",
components: { R: 4, L: 1, C: 0.25 },
topology: "series-rlc",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Series RLC Bandpass filter with } R = 4\\Omega, L = 1\\text{H}, C = 0.25\\text{F}",
- referenceAnswerLatex: "\\frac{4 s}{s^2 + 4 s + 4}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Series RLC Bandpass filter with } R = 4\Omega, L = 1\text{H}, C = 0.25\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{4 s}{s^2 + 4 s + 4}`,
solutionSteps: [
{
title: "Step 1: Apply Transfer Function Formula",
- latex: "H(s) = \\frac{\\frac{R}{L} s}{s^2 + \\frac{R}{L} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{\frac{R}{L} s}{s^2 + \frac{R}{L} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Calculate Parameters",
- latex: "\\frac{R}{L} = 4, \\quad \\frac{1}{LC} = 4 \\implies H(s) = \\frac{4s}{s^2 + 4s + 4}",
+ latex: String.raw`\frac{R}{L} = 4, \quad \frac{1}{LC} = 4 \implies H(s) = \frac{4s}{s^2 + 4s + 4}`,
},
],
},
@@ -50,17 +48,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-3",
components: { R: 5, L: 2, C: 0.1 },
topology: "parallel-rlc",
- promptLatex:
- "\\text{Derive } H(s) = \\frac{I_R(s)}{I_{in}(s)} \\text{ for Parallel RLC with } R = 5\\Omega, L = 2\\text{H}, C = 0.1\\text{F}",
- referenceAnswerLatex: "\\frac{2 s}{s^2 + 2 s + 5}",
+ promptLatex: String.raw`\text{Derive } H(s) = \frac{I_R(s)}{I_{in}(s)} \text{ for Parallel RLC with } R = 5\Omega, L = 2\text{H}, C = 0.1\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{2 s}{s^2 + 2 s + 5}`,
solutionSteps: [
{
title: "Step 1: Admittance Division",
- latex: "H(s) = \\frac{\\frac{1}{R}}{\\frac{1}{R} + \\frac{1}{sL} + sC} = \\frac{\\frac{1}{RC} s}{s^2 + \\frac{1}{RC} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{\frac{1}{R}}{\frac{1}{R} + \frac{1}{sL} + sC} = \frac{\frac{1}{RC} s}{s^2 + \frac{1}{RC} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Plug in Values",
- latex: "\\frac{1}{RC} = \\frac{1}{0.5} = 2, \\quad \\frac{1}{LC} = 5 \\implies H(s) = \\frac{2s}{s^2 + 2s + 5}",
+ latex: String.raw`\frac{1}{RC} = \frac{1}{0.5} = 2, \quad \frac{1}{LC} = 5 \implies H(s) = \frac{2s}{s^2 + 2s + 5}`,
},
],
},
@@ -68,17 +65,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-4",
components: { R: 10, L: 1, C: 0.05 },
topology: "parallel-rlc",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Parallel RLC filter with } R = 10\\Omega, L = 1\\text{H}, C = 0.05\\text{F}",
- referenceAnswerLatex: "\\frac{2 s}{s^2 + 2 s + 20}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Parallel RLC filter with } R = 10\Omega, L = 1\text{H}, C = 0.05\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{2 s}{s^2 + 2 s + 20}`,
solutionSteps: [
{
title: "Step 1: Apply Parallel RLC Formula",
- latex: "H(s) = \\frac{\\frac{1}{RC} s}{s^2 + \\frac{1}{RC} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{\frac{1}{RC} s}{s^2 + \frac{1}{RC} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Calculate Coefficients",
- latex: "\\frac{1}{RC} = 2, \\quad \\frac{1}{LC} = 20 \\implies H(s) = \\frac{2s}{s^2 + 2s + 20}",
+ latex: String.raw`\frac{1}{RC} = 2, \quad \frac{1}{LC} = 20 \implies H(s) = \frac{2s}{s^2 + 2s + 20}`,
},
],
},
@@ -88,17 +84,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-5",
components: { R: 10, L: 1, C: 0.01 },
topology: "parallel-lc-series-r",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Notch Filter with } R = 10\\Omega, L = 1\\text{H}, C = 0.01\\text{F}",
- referenceAnswerLatex: "\\frac{s^2 + 100}{s^2 + 10 s + 100}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Notch Filter with } R = 10\Omega, L = 1\text{H}, C = 0.01\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{s^2 + 100}{s^2 + 10 s + 100}`,
solutionSteps: [
{
title: "Step 1: Derive Notch Transfer Function",
- latex: "H(s) = \\frac{s^2 + \\omega_0^2}{s^2 + \\frac{1}{RC} s + \\omega_0^2}",
+ latex: String.raw`H(s) = \frac{s^2 + \omega_0^2}{s^2 + \frac{1}{RC} s + \omega_0^2}`,
},
{
title: "Step 2: Calculate Corner Frequencies",
- latex: "\\omega_0^2 = \\frac{1}{LC} = 100, \\quad \\frac{1}{RC} = 10 \\implies H(s) = \\frac{s^2 + 100}{s^2 + 10s + 100}",
+ latex: String.raw`\omega_0^2 = \frac{1}{LC} = 100, \quad \frac{1}{RC} = 10 \implies H(s) = \frac{s^2 + 100}{s^2 + 10s + 100}`,
},
],
},
@@ -106,17 +101,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-6",
components: { R: 5, L: 2, C: 0.02 },
topology: "parallel-lc-series-r",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Notch Filter with } R = 5\\Omega, L = 2\\text{H}, C = 0.02\\text{F}",
- referenceAnswerLatex: "\\frac{s^2 + 25}{s^2 + 10 s + 25}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Notch Filter with } R = 5\Omega, L = 2\text{H}, C = 0.02\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{s^2 + 25}{s^2 + 10 s + 25}`,
solutionSteps: [
{
title: "Step 1: Apply Notch Transfer Function",
- latex: "H(s) = \\frac{s^2 + \\frac{1}{LC}}{s^2 + \\frac{1}{RC} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{s^2 + \frac{1}{LC}}{s^2 + \frac{1}{RC} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Substitute Values",
- latex: "\\frac{1}{LC} = 25, \\quad \\frac{1}{RC} = 10 \\implies H(s) = \\frac{s^2 + 25}{s^2 + 10s + 25}",
+ latex: String.raw`\frac{1}{LC} = 25, \quad \frac{1}{RC} = 10 \implies H(s) = \frac{s^2 + 25}{s^2 + 10s + 25}`,
},
],
},
@@ -126,17 +120,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-7",
components: { R: 10, L: 1, C: 0.01 },
topology: "parallel-rc-series-l",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Parallel RC in Series with L with } R = 10\\Omega, L = 1\\text{H}, C = 0.01\\text{F}",
- referenceAnswerLatex: "\\frac{s^2 + 10 s}{s^2 + 10 s + 100}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Parallel RC in Series with L with } R = 10\Omega, L = 1\text{H}, C = 0.01\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{s^2 + 10 s}{s^2 + 10 s + 100}`,
solutionSteps: [
{
title: "Step 1: Impedance Derivation",
- latex: "H(s) = \\frac{s^2 + \\frac{1}{RC} s}{s^2 + \\frac{1}{RC} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{s^2 + \frac{1}{RC} s}{s^2 + \frac{1}{RC} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Substitute Parameters",
- latex: "\\frac{1}{RC} = 10, \\quad \\frac{1}{LC} = 100 \\implies H(s) = \\frac{s^2 + 10s}{s^2 + 10s + 100}",
+ latex: String.raw`\frac{1}{RC} = 10, \quad \frac{1}{LC} = 100 \implies H(s) = \frac{s^2 + 10s}{s^2 + 10s + 100}`,
},
],
},
@@ -144,17 +137,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-8",
components: { R: 20, L: 2, C: 0.025 },
topology: "parallel-rc-series-l",
- promptLatex:
- "\\text{Find } H(s) \\text{ for Parallel RC in Series with L with } R = 20\\Omega, L = 2\\text{H}, C = 0.025\\text{F}",
- referenceAnswerLatex: "\\frac{s^2 + 2 s}{s^2 + 2 s + 20}",
+ promptLatex: String.raw`\text{Find } H(s) \text{ for Parallel RC in Series with L with } R = 20\Omega, L = 2\text{H}, C = 0.025\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{s^2 + 2 s}{s^2 + 2 s + 20}`,
solutionSteps: [
{
title: "Step 1: Impedance Derivation",
- latex: "H(s) = \\frac{s^2 + \\frac{1}{RC} s}{s^2 + \\frac{1}{RC} s + \\frac{1}{LC}}",
+ latex: String.raw`H(s) = \frac{s^2 + \frac{1}{RC} s}{s^2 + \frac{1}{RC} s + \frac{1}{LC}}`,
},
{
title: "Step 2: Substitute Parameters",
- latex: "\\frac{1}{RC} = 2, \\quad \\frac{1}{LC} = 20 \\implies H(s) = \\frac{s^2 + 2s}{s^2 + 2s + 20}",
+ latex: String.raw`\frac{1}{RC} = 2, \quad \frac{1}{LC} = 20 \implies H(s) = \frac{s^2 + 2s}{s^2 + 2s + 20}`,
},
],
},
@@ -164,17 +156,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-9",
components: { R: 1000, L: 1, C: 0.000001 },
topology: "rc-lpf",
- promptLatex:
- "\\text{Derive 1st-order RC LPF transfer function with } R = 1\\text{k}\\Omega, C = 1\\mu\\text{F}",
- referenceAnswerLatex: "\\frac{1000}{s + 1000}",
+ promptLatex: String.raw`\text{Derive 1st-order RC LPF transfer function with } R = 1\text{k}\Omega, C = 1\mu\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{1000}{s + 1000}`,
solutionSteps: [
{
title: "Step 1: Voltage Divider Formula",
- latex: "H(s) = \\frac{\\frac{1}{sC}}{R + \\frac{1}{sC}} = \\frac{1}{1 + s R C} = \\frac{\\frac{1}{RC}}{s + \\frac{1}{RC}}",
+ latex: String.raw`H(s) = \frac{\frac{1}{sC}}{R + \frac{1}{sC}} = \frac{1}{1 + s R C} = \frac{\frac{1}{RC}}{s + \frac{1}{RC}}`,
},
{
title: "Step 2: Calculate Corner Frequency w_c",
- latex: "\\omega_c = \\frac{1}{RC} = \\frac{1}{1000 \\times 10^{-6}} = 1000 \\text{ rad/s} \\implies H(s) = \\frac{1000}{s + 1000}",
+ latex: String.raw`\omega_c = \frac{1}{RC} = \frac{1}{1000 \times 10^{-6}} = 1000 \text{ rad/s} \implies H(s) = \frac{1000}{s + 1000}`,
},
],
},
@@ -182,17 +173,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-10",
components: { R: 500, L: 1, C: 0.000002 },
topology: "rc-lpf",
- promptLatex:
- "\\text{Find 3dB corner frequency } \\omega_c \\text{ for RC LPF with } R = 500\\Omega, C = 2\\mu\\text{F}",
- referenceAnswerLatex: "\\omega_c = 1000 \\text{ rad/s}",
+ promptLatex: String.raw`\text{Find 3dB corner frequency } \omega_c \text{ for RC LPF with } R = 500\Omega, C = 2\mu\text{F}`,
+ referenceAnswerLatex: String.raw`\omega_c = 1000 \text{ rad/s}`,
solutionSteps: [
{
title: "Step 1: Corner Frequency Formula",
- latex: "\\omega_c = \\frac{1}{R C}",
+ latex: String.raw`\omega_c = \frac{1}{R C}`,
},
{
title: "Step 2: Plug in Values",
- latex: "\\omega_c = \\frac{1}{500 \\times 2 \\times 10^{-6}} = 1000 \\text{ rad/s}",
+ latex: String.raw`\omega_c = \frac{1}{500 \times 2 \times 10^{-6}} = 1000 \text{ rad/s}`,
},
],
},
@@ -202,17 +192,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-11",
components: { R: 100, L: 1, C: 0.0001 },
topology: "active-sallen-key",
- promptLatex:
- "\\text{Derive 2nd-Order Sallen-Key LPF transfer function with } R = 100\\Omega, C = 100\\mu\\text{F}",
- referenceAnswerLatex: "\\frac{10000}{s^2 + 200 s + 10000}",
+ promptLatex: String.raw`\text{Derive 2nd-Order Sallen-Key LPF transfer function with } R = 100\Omega, C = 100\mu\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{10000}{s^2 + 200 s + 10000}`,
solutionSteps: [
{
title: "Step 1: Sallen-Key Transfer Function Formula",
- latex: "H(s) = \\frac{\\omega_c^2}{s^2 + 2 \\omega_c s + \\omega_c^2}",
+ latex: String.raw`H(s) = \frac{\omega_c^2}{s^2 + 2 \omega_c s + \omega_c^2}`,
},
{
title: "Step 2: Calculate Corner Frequency w_c",
- latex: "\\omega_c = \\frac{1}{RC} = 100 \\text{ rad/s} \\implies \\omega_c^2 = 10000 \\implies H(s) = \\frac{10000}{s^2 + 200s + 10000}",
+ latex: String.raw`\omega_c = \frac{1}{RC} = 100 \text{ rad/s} \implies \omega_c^2 = 10000 \implies H(s) = \frac{10000}{s^2 + 200s + 10000}`,
},
],
},
@@ -220,17 +209,16 @@ export const CIRCUITS_EXAM_BANK: CircuitProblem[] = [
id: "circuits-bank-12",
components: { R: 50, L: 1, C: 0.0004 },
topology: "active-sallen-key",
- promptLatex:
- "\\text{Derive 2nd-Order Sallen-Key LPF with } R = 50\\Omega, C = 400\\mu\\text{F}",
- referenceAnswerLatex: "\\frac{2500}{s^2 + 100 s + 2500}",
+ promptLatex: String.raw`\text{Derive 2nd-Order Sallen-Key LPF with } R = 50\Omega, C = 400\mu\text{F}`,
+ referenceAnswerLatex: String.raw`\frac{2500}{s^2 + 100 s + 2500}`,
solutionSteps: [
{
title: "Step 1: Calculate Corner Frequency w_c",
- latex: "\\omega_c = \\frac{1}{50 \\times 400 \\times 10^{-6}} = 50 \\text{ rad/s}",
+ latex: String.raw`\omega_c = \frac{1}{50 \times 400 \times 10^{-6}} = 50 \text{ rad/s}`,
},
{
title: "Step 2: Form Transfer Function",
- latex: "\\omega_c^2 = 2500, \\quad 2\\omega_c = 100 \\implies H(s) = \\frac{2500}{s^2 + 100s + 2500}",
+ latex: String.raw`\omega_c^2 = 2500, \quad 2\omega_c = 100 \implies H(s) = \frac{2500}{s^2 + 100s + 2500}`,
},
],
},
diff --git a/src/lib/problems/bank/fourier-transform-bank.ts b/src/lib/problems/bank/fourier-transform-bank.ts
index f1366991..bab0fe87 100644
--- a/src/lib/problems/bank/fourier-transform-bank.ts
+++ b/src/lib/problems/bank/fourier-transform-bank.ts
@@ -10,58 +10,54 @@ import type { CtftProblem } from "$lib/math-engine/fourier-transform/index";
export const CTFT_EXAM_BANK: CtftProblem[] = [
{
id: "ctft-bank-1",
- promptLatex:
- "\\text{Calculate the CTFT } X(\\omega) \\text{ of } x(t) = \\operatorname{rect}\\left(\\frac{t - 3}{4}\\right)",
- referenceAnswerLatex:
- "4 \\operatorname{sinc}\\left(\\frac{2 \\omega}{\\pi}\\right) e^{-j 3 \\omega}",
+ promptLatex: String.raw`\text{Calculate the CTFT } X(\omega) \text{ of } x(t) = \operatorname{rect}\left(\frac{t - 3}{4}\right)`,
+ referenceAnswerLatex: String.raw`4 \operatorname{sinc}\left(\frac{2 \omega}{\pi}\right) e^{-j 3 \omega}`,
solutionSteps: [
{
title: "Step 1: Identify Base Rectangular Transform Pair",
- latex: "\\operatorname{rect}\\left(\\frac{t}{T}\\right) \\iff T \\operatorname{sinc}\\left(\\frac{T \\omega}{2 \\pi}\\right)",
+ latex: String.raw`\operatorname{rect}\left(\frac{t}{T}\right) \iff T \operatorname{sinc}\left(\frac{T \omega}{2 \pi}\right)`,
},
{
title: "Step 2: Substitute Parameter T = 4",
- latex: "\\operatorname{rect}\\left(\\frac{t}{4}\\right) \\iff 4 \\operatorname{sinc}\\left(\\frac{4 \\omega}{2 \\pi}\\right) = 4 \\operatorname{sinc}\\left(\\frac{2 \\omega}{\\pi}\\right)",
+ latex: String.raw`\operatorname{rect}\left(\frac{t}{4}\right) \iff 4 \operatorname{sinc}\left(\frac{4 \omega}{2 \pi}\right) = 4 \operatorname{sinc}\left(\frac{2 \omega}{\pi}\right)`,
},
{
title: "Step 3: Apply Time Shift Property",
- latex: "x(t - t_0) \\iff X(\\omega) e^{-j \\omega t_0} \\implies 4 \\operatorname{sinc}\\left(\\frac{2 \\omega}{\\pi}\\right) e^{-j 3 \\omega}",
+ latex: String.raw`x(t - t_0) \iff X(\omega) e^{-j \omega t_0} \implies 4 \operatorname{sinc}\left(\frac{2 \omega}{\pi}\right) e^{-j 3 \omega}`,
},
],
},
{
id: "ctft-bank-2",
- promptLatex:
- "\\text{Find the inverse CTFT } x(t) \\text{ of } X(\\omega) = \\frac{1}{4 + j\\omega} e^{-j 2 \\omega}",
+ promptLatex: String.raw`\text{Find the inverse CTFT } x(t) \text{ of } X(\omega) = \frac{1}{4 + j\omega} e^{-j 2 \omega}`,
referenceAnswerLatex: "e^{-4 (t - 2)} u(t - 2)",
solutionSteps: [
{
title: "Step 1: Recall One-Sided Exponential Pair",
- latex: "e^{-a t} u(t) \\iff \\frac{1}{a + j\\omega} \\implies a = 4",
+ latex: String.raw`e^{-a t} u(t) \iff \frac{1}{a + j\omega} \implies a = 4`,
},
{
title: "Step 2: Apply Time Shift Property in Reverse",
- latex: "X(\\omega) e^{-j \\omega t_0} \\iff x(t - t_0) \\implies e^{-4 (t - 2)} u(t - 2)",
+ latex: String.raw`X(\omega) e^{-j \omega t_0} \iff x(t - t_0) \implies e^{-4 (t - 2)} u(t - 2)`,
},
],
},
{
id: "ctft-bank-3",
- promptLatex:
- "\\text{Compute the 3dB Energy Bandwidth } \\omega_{3dB} \\text{ for } x(t) = e^{-3 t} u(t)",
- referenceAnswerLatex: "\\omega_{3dB} = 3 \\text{ rad/s}",
+ promptLatex: String.raw`\text{Compute the 3dB Energy Bandwidth } \omega_{3dB} \text{ for } x(t) = e^{-3 t} u(t)`,
+ referenceAnswerLatex: String.raw`\omega_{3dB} = 3 \text{ rad/s}`,
solutionSteps: [
{
title: "Step 1: Form Energy Spectrum |X(w)|^2",
- latex: "|X(\\omega)|^2 = \\left| \\frac{1}{3 + j\\omega} \\right|^2 = \\frac{1}{9 + \\omega^2}",
+ latex: String.raw`|X(\omega)|^2 = \left| \frac{1}{3 + j\omega} \right|^2 = \frac{1}{9 + \omega^2}`,
},
{
title: "Step 2: Set Spectrum Equal to Half Peak Energy",
- latex: "|X(0)|^2 = \\frac{1}{9} \\implies \\frac{1}{9 + \\omega_{3dB}^2} = \\frac{1}{2} \\cdot \\frac{1}{9} = \\frac{1}{18}",
+ latex: String.raw`|X(0)|^2 = \frac{1}{9} \implies \frac{1}{9 + \omega_{3dB}^2} = \frac{1}{2} \cdot \frac{1}{9} = \frac{1}{18}`,
},
{
title: "Step 3: Solve for Corner Frequency",
- latex: "9 + \\omega_{3dB}^2 = 18 \\implies \\omega_{3dB}^2 = 9 \\implies \\omega_{3dB} = 3 \\text{ rad/s}",
+ latex: String.raw`9 + \omega_{3dB}^2 = 18 \implies \omega_{3dB}^2 = 9 \implies \omega_{3dB} = 3 \text{ rad/s}`,
},
],
},
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
index f2671ad1..29c15f20 100644
--- a/src/routes/+error.svelte
+++ b/src/routes/+error.svelte
@@ -70,15 +70,15 @@
*/
function getMathFormula(pathname: string): string {
if (pathname.includes("fourier-transform")) {
- return "X(\\omega) = \\int_{-\\infty}^{\\infty} x(t) e^{-j\\omega t} dt";
+ return String.raw`X(\omega) = \int_{-\infty}^{\infty} x(t) e^{-j\omega t} dt`;
}
if (pathname.includes("laplace")) {
- return "X(s) = \\int_{0^{-}}^{\\infty} x(t) e^{-st} dt";
+ return String.raw`X(s) = \int_{0^{-}}^{\infty} x(t) e^{-st} dt`;
}
if (pathname.includes("circuits")) {
- return "H(s) = \\frac{V_{\\text{out}}(s)}{V_{\\text{in}}(s)}";
+ return String.raw`H(s) = \frac{V_{\text{out}}(s)}{V_{\text{in}}(s)}`;
}
- return "H(s) \\to 0 \\quad \\text{for } t \\to \\infty";
+ return String.raw`H(s) \to 0 \quad \text{for } t \to \infty`;
}
From ae8d0112011b4386edd73f74ef60949b1c036ee5 Mon Sep 17 00:00:00 2001
From: rapjul <46605047+rapjul@users.noreply.github.com>
Date: Mon, 2 Nov 2026 13:20:46 -0600
Subject: [PATCH 2/6] feat(lint): block escaped LaTeX strings
- Add the AST-based checker for JavaScript, TypeScript, and Svelte strings and templates.
- Run the rule on staged source changes and in the full-source CI check.
- Cover escapes, String.raw, interpolation, Svelte expressions, comments, regexes, and path selection.
- Convert existing escaped LaTeX fixtures and evaluator replacement strings to String.raw.
---
.github/workflows/practice-verification.yml | 2 +
package.json | 6 +-
scripts/lint-escaped-latex.mjs | 545 ++++++++++++++++++
src/lib/math-engine/evaluator.ts | 7 +-
tests/e2e/ctft-browser.ts | 8 +-
tests/e2e/ctft-module.spec.ts | 4 +-
tests/e2e/practice-correctness.spec.ts | 6 +-
tests/unit/canonical-transform.test.ts | 10 +-
tests/unit/circuits.test.ts | 2 +-
.../components/ConvolutionStepSolver.test.ts | 2 +-
tests/unit/components/CtftStepSolver.test.ts | 6 +-
.../components/FourierCoefficientCard.test.ts | 12 +-
.../components/FourierSeriesCanvas.test.ts | 4 +-
.../components/FourierSeriesInput.test.ts | 44 +-
.../FourierSeriesReviewRegressions.test.ts | 2 +-
tests/unit/components/MathBlock.test.ts | 13 +-
tests/unit/components/MathInline.test.ts | 6 +-
tests/unit/components/MathInputBar.test.ts | 8 +-
tests/unit/components/MathText.test.ts | 11 +-
.../unit/components/OdeResponseInput.test.ts | 4 +-
tests/unit/configured-convolution.test.ts | 2 +-
tests/unit/constant-proofs.test.ts | 12 +-
.../convolution-beginner-workflow.test.ts | 4 +-
.../convolution-expression-validation.test.ts | 13 +-
.../unit/convolution-pulse-formatting.test.ts | 12 +-
.../convolution-step-solver-lifecycle.test.ts | 4 +-
.../unit/convolution-symbolic-grading.test.ts | 6 +-
tests/unit/ctft-answer-validation.test.ts | 2 +-
tests/unit/ctft-presentation.test.ts | 8 +-
tests/unit/ctft-tutor.test.ts | 22 +-
tests/unit/evaluator.test.ts | 17 +-
tests/unit/formatting.test.ts | 76 ++-
tests/unit/fourier-expression-oracle.ts | 10 +-
...rier-series-distractor-regressions.test.ts | 5 +-
.../unit/fourier-series-its-generator.test.ts | 16 +-
.../fourier-series-math-contracts.test.ts | 20 +-
.../fourier-series-review-regressions.test.ts | 6 +-
tests/unit/fourier-series-step-solver.test.ts | 16 +-
...ourier-series-symbolic-derivations.test.ts | 31 +-
.../fourier-series-tutor-contracts.test.ts | 2 +-
tests/unit/fourier-transform-bank.test.ts | 23 +-
tests/unit/fourier-transform.test.ts | 21 +-
tests/unit/fraction.test.ts | 38 +-
tests/unit/input-builders.test.ts | 9 +-
tests/unit/laplace-algebra.test.ts | 17 +-
tests/unit/laplace-answer-entry.test.ts | 4 +-
.../unit/laplace-choice-presentation.test.ts | 2 +-
tests/unit/laplace-constant-preview.test.ts | 4 +-
tests/unit/laplace-construction.test.ts | 2 +-
tests/unit/laplace-elimination.test.ts | 10 +-
tests/unit/laplace-fixtures.ts | 14 +-
tests/unit/laplace-formatting.test.ts | 6 +-
tests/unit/laplace-input-entry.test.ts | 9 +-
tests/unit/laplace-ode-tutor.test.ts | 2 +-
tests/unit/laplace-support.test.ts | 8 +-
tests/unit/laplace.test.ts | 4 +-
tests/unit/lint-escaped-latex.test.ts | 169 ++++++
tests/unit/mathblock.test.ts | 56 +-
tests/unit/mathtext.test.ts | 27 +-
tests/unit/ode-choice-regressions.test.ts | 2 +-
tests/unit/ode-formatting-helpers.test.ts | 4 +-
tests/unit/ode-its-generator.test.ts | 12 +-
tests/unit/ode-solver-state.test.ts | 12 +-
tests/unit/ode-step-solver-validation.test.ts | 4 +-
tests/unit/odes-solver.test.ts | 20 +-
tests/unit/transform-notation.test.ts | 10 +-
tests/unit/ui-components.test.ts | 2 +-
67 files changed, 1183 insertions(+), 294 deletions(-)
create mode 100644 scripts/lint-escaped-latex.mjs
create mode 100644 tests/unit/lint-escaped-latex.test.ts
diff --git a/.github/workflows/practice-verification.yml b/.github/workflows/practice-verification.yml
index ae2449d8..758d16d8 100644
--- a/.github/workflows/practice-verification.yml
+++ b/.github/workflows/practice-verification.yml
@@ -79,6 +79,8 @@ jobs:
run: npm run check
- name: Check imports
run: npm run lint:imports
+ - name: Check escaped LaTeX strings
+ run: npm run lint:escaped-latex
- name: Check formatting
run: npm run format:check
- name: Check verification documentation
diff --git a/package.json b/package.json
index 47d8b740..7811c815 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint:imports": "biome check --only=organizeImports .",
+ "lint:escaped-latex": "node scripts/lint-escaped-latex.mjs",
"lint:verification-docs": "node scripts/lint-verification-docs.mjs",
"format:imports": "biome check --write --only=organizeImports .",
"format": "prettier --write .",
@@ -79,9 +80,10 @@
}
},
"lint-staged": {
- "*.{js,ts,svelte}": [
+ "*.{js,mjs,cjs,mts,cts,jsx,ts,tsx,svelte}": [
"biome check --write --no-errors-on-unmatched",
- "prettier --write"
+ "prettier --write",
+ "node scripts/lint-escaped-latex.mjs"
],
"*.{json,json5,jsonc,css,md,yaml,yml,html,svg}": [
"prettier --write"
diff --git a/scripts/lint-escaped-latex.mjs b/scripts/lint-escaped-latex.mjs
new file mode 100644
index 00000000..de916bd4
--- /dev/null
+++ b/scripts/lint-escaped-latex.mjs
@@ -0,0 +1,545 @@
+#!/usr/bin/env node
+import { readdir, readFile, stat } from "node:fs/promises";
+import path from "node:path";
+import process from "node:process";
+import { pathToFileURL } from "node:url";
+import { parse as parseSvelte } from "svelte/compiler";
+import * as ts from "typescript";
+
+/**
+ * @typedef {object} EscapedLatexViolation
+ * @property {number} line Source line containing the escaped LaTeX command.
+ * @property {string} command LaTeX command that uses JavaScript escaping.
+ * @property {number} offset Source offset of the command.
+ */
+
+/**
+ * @typedef {object} FileViolation
+ * @property {string} file Path relative to the project root.
+ * @property {number} line Source line containing the escaped LaTeX command.
+ * @property {string} command LaTeX command that uses JavaScript escaping.
+ */
+
+const DEFAULT_TARGETS = ["src", "tests", "scripts"];
+const SUPPORTED_EXTENSIONS = new Set([
+ ".cjs",
+ ".cts",
+ ".js",
+ ".jsx",
+ ".mjs",
+ ".mts",
+ ".svelte",
+ ".ts",
+ ".tsx",
+]);
+const LATEX_COMMANDS = new Set([
+ "alpha",
+ "angle",
+ "approx",
+ "arg",
+ "begin",
+ "cdot",
+ "circ",
+ "cos",
+ "deg",
+ "delta",
+ "Delta",
+ "dfrac",
+ "displaystyle",
+ "dots",
+ "end",
+ "equiv",
+ "eta",
+ "exp",
+ "F",
+ "frac",
+ "ge",
+ "iff",
+ "implies",
+ "in",
+ "infty",
+ "int",
+ "j",
+ "le",
+ "left",
+ "leftrightarrow",
+ "lim",
+ "ln",
+ "log",
+ "longleftrightarrow",
+ "Longrightarrow",
+ "mathbb",
+ "mathcal",
+ "mathrm",
+ "max",
+ "min",
+ "mp",
+ "mu",
+ "ne",
+ "neq",
+ "omega",
+ "Omega",
+ "operatorname",
+ "phi",
+ "pi",
+ "pm",
+ "pmod",
+ "qquad",
+ "quad",
+ "Re",
+ "right",
+ "rm",
+ "sigma",
+ "sin",
+ "sqrt",
+ "square",
+ "sum",
+ "tan",
+ "tau",
+ "text",
+ "textasciicircum",
+ "texttt",
+ "tfrac",
+ "theta",
+ "tilde",
+ "times",
+ "to",
+ "X",
+]);
+const ESCAPED_CONTROL_SEQUENCE = /(?:\\\\)+([A-Za-z]+)/g;
+
+/**
+ * Finds escaped LaTeX commands in JavaScript, TypeScript, or Svelte source.
+ *
+ * @param {string} source Source contents to inspect.
+ * @param {string} filePath File path used to select the parser.
+ * @returns {EscapedLatexViolation[]} Escaped LaTeX commands found in the source.
+ */
+export function findEscapedLatexViolations(source, filePath) {
+ /** @type {EscapedLatexViolation[]} */
+ const violations = [];
+
+ if (path.extname(filePath) === ".svelte") {
+ scanSvelteSource(source, filePath, violations);
+ } else {
+ scanTypeScriptSource(source, filePath, violations);
+ }
+
+ return violations;
+}
+
+/**
+ * Scans JavaScript or TypeScript AST string and template nodes.
+ *
+ * @param {string} source Source contents to inspect.
+ * @param {string} filePath File path supplied to the TypeScript parser.
+ * @param {EscapedLatexViolation[]} violations Mutable output collection.
+ * @returns {void}
+ */
+function scanTypeScriptSource(source, filePath, violations) {
+ const extension = path.extname(filePath);
+ const scriptKind =
+ extension === ".tsx"
+ ? ts.ScriptKind.TSX
+ : extension === ".jsx"
+ ? ts.ScriptKind.JSX
+ : extension === ".js" ||
+ extension === ".mjs" ||
+ extension === ".cjs"
+ ? ts.ScriptKind.JS
+ : ts.ScriptKind.TS;
+ const sourceFile = ts.createSourceFile(
+ filePath,
+ source,
+ ts.ScriptTarget.Latest,
+ true,
+ scriptKind,
+ );
+
+ /**
+ * Visits a TypeScript AST node and checks its string-bearing children.
+ *
+ * @param {ts.Node} node AST node to inspect.
+ * @returns {void}
+ */
+ function visit(node) {
+ if (ts.isStringLiteral(node)) {
+ scanRawText(
+ node.getText(sourceFile),
+ node.getStart(sourceFile),
+ source,
+ violations,
+ );
+ return;
+ }
+
+ if (ts.isRegularExpressionLiteral(node)) return;
+
+ if (ts.isNoSubstitutionTemplateLiteral(node)) {
+ if (!isRawTaggedTemplate(node.parent, node)) {
+ scanRawText(
+ node.getText(sourceFile),
+ node.getStart(sourceFile),
+ source,
+ violations,
+ );
+ }
+ return;
+ }
+
+ if (ts.isTemplateExpression(node)) {
+ if (!isRawTaggedTemplate(node.parent, node)) {
+ scanRawText(
+ node.head.getText(sourceFile),
+ node.head.getStart(sourceFile),
+ source,
+ violations,
+ );
+ for (const span of node.templateSpans) {
+ scanRawText(
+ span.literal.getText(sourceFile),
+ span.literal.getStart(sourceFile),
+ source,
+ violations,
+ );
+ visit(span.expression);
+ }
+ } else {
+ for (const span of node.templateSpans) visit(span.expression);
+ }
+ return;
+ }
+
+ if (
+ ts.isTaggedTemplateExpression(node) &&
+ isTypeScriptStringRawTag(node.tag)
+ ) {
+ if (ts.isTemplateExpression(node.template)) {
+ for (const span of node.template.templateSpans) {
+ visit(span.expression);
+ }
+ }
+ return;
+ }
+
+ ts.forEachChild(node, visit);
+ }
+
+ visit(sourceFile);
+}
+
+/**
+ * Scans Svelte script and markup-expression AST nodes.
+ *
+ * @param {string} source Svelte component contents.
+ * @param {string} filePath File path supplied to the Svelte parser.
+ * @param {EscapedLatexViolation[]} violations Mutable output collection.
+ * @returns {void}
+ */
+function scanSvelteSource(source, filePath, violations) {
+ const root = parseSvelte(source, { filename: filePath, modern: true });
+ /** @type {WeakSet