我使用下面的代码在输入字段中显示数学函数。然而,不是让函数合并来创建一个方程,而是像这样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);
};发布于 2020-10-05 12:29:57
您正在连接这两个字符串。您需要解析\cos{}字符串并插入新字符串。你可以用子字符串来实现这一点。
或者,您可以插入"\cos{“和"\sqrt{”,然后构建另一个函数来为您关闭它们。
https://stackoverflow.com/questions/63692746
复制相似问题