Skip to content

Adding support for maths latex #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions components/QuizQuestionItem.js
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not necesary, it doesn't change anything. What error did you got and why you did this as a solution? how is this a solution?

Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,23 @@ export default function QuizQuestionItem({ children, ...props }) {
// remove the flag we added to recognize quiz options (avoiding false identification of nested child list items...)
// @see <api.js>.parseQuiz
//
if (children[0].indexOf("%OPTION%") == 0) {
children[0] = children[0].replace("%OPTION%", "");


let childElements = {}

if (typeof children === 'string') {


// Case when 'children' is a string
if (children.indexOf("%OPTION%") === 0) {
childElements = children.replace("%OPTION%", "");
}
} else if (Array.isArray(children) && children.length > 0) {
// Case when 'children' is an array of strings
childElements = [ ...children ]
if (childElements[0].indexOf("%OPTION%") === 0) {
childElements[0] = childElements[0].replace("%OPTION%", "");
}
}

return (
Expand All @@ -90,7 +105,7 @@ export default function QuizQuestionItem({ children, ...props }) {
>
<OptionIndexContext.Provider value={true}>
{" "}
{children}{" "}
{childElements}{" "}
</OptionIndexContext.Provider>
</li>
);
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
"dependencies": {
"glob": "^8.0.3",
"iso-language-codes": "^1.1.0",
"next": "latest",
"react": "latest",
"react-dom": "latest",
"react-markdown": "^8.0.3",



"react-syntax-highlighter": "^15.5.0",
"yaml": "^2.1.1"

"yaml": "^2.1.1",

"katex": "^0.16.9",
"next": "14.0.4",
"react": "^18",
"react-dom": "^18",
"react-markdown": "^9.0.1",
"rehype-katex": "^7.0.0",

"remark-math": "6.0.0"

},
"devDependencies": {
"@babel/core": "^7.18.10",
Expand Down
2 changes: 2 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { LanguageContext } from "../components/LanguageProvider";
import "../styles/global.css";
import 'katex/dist/katex.min.css'; // Import the CSS for KaTeX


export default function MainApp({ Component, pageProps }) {

Expand Down
6 changes: 6 additions & 0 deletions pages/quiz/[...slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { useQuizSolvedState } from "../../lib/QuizSolvedState";
import { getDictionary } from '../../lib/l18n';
import { useLanguage } from '../../components/LanguageProvider';
import Head from "next/head"
import remarkMath from 'remark-math'
import rehypeKatex from 'rehype-katex'
import 'katex/dist/katex.min.css'


const questionQueryName = 'question';
Expand Down Expand Up @@ -132,9 +135,12 @@ const Quiz = ({ quiz, availableLanguages }) => {
code: QuizCodeSnipped,
img: QuizImageRef,
}}
remarkPlugins={[remarkMath]}
rehypePlugins={[rehypeKatex]}
>
{quiz.questions[question - 1].text}
</ReactMarkdown>

</QuizContext.Provider>

<div className="mt-10 text-center ">
Expand Down