[英]Displaying Math functions using Mathquill
我正在使用下面的代碼在輸入字段中顯示數學函數。 然而,與其讓函數合並以創建一個像 cos(√) 這樣的方程。 每個方程都添加到已顯示方程的右側。 例子:cos() √
import React, {useState} from 'react'
import { addStyles, EditableMathField } from 'react-mathquill'
addStyles();
function App(props) {
const [latex, setLatex] = useState("");
const injectMathFunction = (latexString) => {
setLatex((latex) => latex + latexString);
};
return (
<div>
<EditableMathField
latex={latex} // latex value for the input field
onChange={(mathField) => {
setLatex(mathField.latex());
}}
/>
<button onClick={() => injectMathFunction("{\\sqrt{}}")}>√</button>
<button onClick={() => injectMathFunction("\\frac{}{}")}>/</button>
</div>
);
}
我假設問題出在這部分代碼中
const injectMathFunction = (latexString) => {
setLatex((latex) => latex + latexString);
};
您正在連接兩個字符串。 您要么需要解析您的 \\cos{} 字符串並插入新字符串。 您可以使用子字符串完成此操作。
或者,您可以插入 "\\cos{" 和 "\\sqrt{" 然后構建另一個為您關閉它們的函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.