Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: render latex in quiz options

Zhouac0c348b9ea6
diff --git a/web/components/quiz/QuizViewer.tsx b/web/components/quiz/QuizViewer.tsx
index 08d1544ad..831ac716e 100644
--- a/web/components/quiz/QuizViewer.tsx
+++ b/web/components/quiz/QuizViewer.tsx
@@ -1038,7 +1038,13 @@ export default function QuizViewer({
key
)}
</span>
- <span className="leading-relaxed">{text}</span>
+ <span className="min-w-0 leading-relaxed">
+ <MarkdownRenderer
+ content={text}
+ variant="compact"
+ enableMath
+ />
+ </span>
</button>
);
})}
diff --git a/web/tests/quiz-option-latex.test.ts b/web/tests/quiz-option-latex.test.ts
new file mode 100644
index 000000000..49a3e7c86
--- /dev/null
+++ b/web/tests/quiz-option-latex.test.ts
@@ -0,0 +1,28 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import path from "node:path";
+
+test("QuizViewer renders multiple-choice options through MarkdownRenderer", () => {
+ const source = readFileSync(
+ path.join(process.cwd(), "components/quiz/QuizViewer.tsx"),
+ "utf8",
+ );
+ const optionsStart = source.indexOf(
+ "{Object.entries(q.options!).map(([key, text]) => {",
+ );
+ assert.notEqual(optionsStart, -1, "choice option renderer not found");
+
+ const optionsEnd = source.indexOf(") : isConcept ?", optionsStart);
+ assert.notEqual(optionsEnd, -1, "choice option branch end not found");
+
+ const optionsBranch = source.slice(optionsStart, optionsEnd);
+ assert.match(
+ optionsBranch,
+ /<MarkdownRenderer[\s\S]*content=\{text\}[\s\S]*variant="compact"[\s\S]*enableMath/,
+ );
+ assert.doesNotMatch(
+ optionsBranch,
+ /<span className="leading-relaxed">\{text\}<\/span>/,
+ );
+});