diff --git a/src/Pages/Home/Dummy.tsx b/src/Pages/Home/Dummy.tsx index f7afbc3..f1761f5 100644 --- a/src/Pages/Home/Dummy.tsx +++ b/src/Pages/Home/Dummy.tsx @@ -1,23 +1,14 @@ import React, { useState } from "react"; import { useTranslation } from "react-i18next"; -import MathMLPreview from "./MathMLPreview"; -import { Field, Form, Formik } from "formik"; -import Test from "./Test"; -import MarkdownPreview from '@uiw/react-markdown-preview'; -import { BlockMath } from "react-katex"; - +import { MathConverter } from "./MathConverter"; const Dummy = () => { const [t] = useTranslation(); - const [markdown, setMarkdown] = useState(' \nV_{sphere} = \\frac{4}{3}\\pi r^3\n'); return (
- underlined text."} /> - - {markdown} - +
); }; diff --git a/src/Pages/Home/MathConverter.tsx b/src/Pages/Home/MathConverter.tsx new file mode 100644 index 0000000..2c8dcc7 --- /dev/null +++ b/src/Pages/Home/MathConverter.tsx @@ -0,0 +1,56 @@ +import React, { useState } from 'react'; +import { MathJax, MathJaxContext } from 'better-react-mathjax'; + +const convertToLatex = (input: string): string => { + // Replace fractions + let latex = input.replace(/(\d+)\/(\d+)/g, '\\frac{$1}{$2}'); + latex = latex.replace(/\(([^()]+)\)\/\(([^()]+)\)/g, '\\frac{($1)}{($2)}'); + latex = latex.replace(/([^\s()]+)\s*\/\s*([^\s()]+)/g, '\\frac{$1}{$2}'); + + // Handle exponentiation + latex = latex.replace(/(\w+)\^(\(.+?\)|\w+)/g, '$1^{ $2 }'); + latex = latex.replace(/(\w+)\s*\^(\w+)/g, '$1^{ $2 }'); + + // Handle square roots + latex = latex.replace(/sqrt\(([^()]+)\)/g, '\\sqrt{$1}'); + + // Replace subscripts + latex = latex.replace(/_(\w+)/g, '_{ $1 }'); + latex = latex.replace(/_([\w+]+)/g, '_{ $1 }'); + + // Add spacing for equations + latex = latex.replace(/=/g, ' = '); + + return latex; +}; + +export const MathConverter: React.FC = () => { + const config = { + loader: { load: ["input/asciimath"] } + }; + + const [inputText, setInputText] = useState('u_(n+1)=e.sqrt(u_n)'); + const [convertedLatex, setConvertedLatex] = useState(''); + +const handleClick = () => { + const latex = convertToLatex(inputText); + setConvertedLatex(latex); + }; + + return ( + +
+

LaTeX Preview

+