Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用MathJax获取MathML代码_Javascript_Mathjax - Fatal编程技术网

Javascript 使用MathJax获取MathML代码

Javascript 使用MathJax获取MathML代码,javascript,mathjax,Javascript,Mathjax,我已经构建了一个表单来编写LaTeX表达式并用MathJax呈现它们。为了加速MathML代码的复制,我编写了一个脚本,在另一个文本区域中显示MathML代码,如您所示 这是我的代码: <!doctype html> <html> <head> <title>LaTeX para Word</title> <script type="text/x-mathjax-config"> MathJax.Hub.Config({

我已经构建了一个表单来编写LaTeX表达式并用MathJax呈现它们。为了加速MathML代码的复制,我编写了一个脚本,在另一个文本区域中显示MathML代码,如您所示

这是我的代码:

<!doctype html>
<html>
<head>
<title>LaTeX para Word</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  showProcessingMessages: false,
  tex2jax: {
    inlineMath: [
      ['$','$'],
      [ '\\(', '\\)' ]
    ]
  },
  extensions: ['toMathML.js']
});

var math = null;
MathJax.Hub.queue.Push(function () {
  math = MathJax.Hub.getAllJax('MathOutput') [0];
});

window.UpdateMath = function (TeX) {
  MathJax.Hub.queue.Push(['Text', math, '\\displaystyle{' + TeX + '}']);
  document.getElementById('output').value = '<?xml version="1.0"?>' + math.root.toMathML("");
};

function selectTextarea(element) {
  var text = document.getElementById(element).select();
}
</script>
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&locale=pt-br"></script>
</head>
<body>

<textarea id="MathInput" cols="60" rows="10" onkeyup="UpdateMath(this.value)"></textarea>

<div id="MathOutput">
$${}$$
</div>
<hr>
<br>
<textarea id="output" cols="60" rows="10" readonly="readonly"></textarea>
<br>
<button onclick="selectTextarea('output')">Selecionar código</button>
<script src="main.js"></script>
</body>
</html>

乳胶对位词
MathJax.Hub.Config({
showProcessingMessages:false,
tex2jax:{
inlineMath:[
['$','$'],
[ '\\(', '\\)' ]
]
},
扩展:['toMathML.js']
});
var-math=null;
MathJax.Hub.queue.Push(函数(){
math=MathJax.Hub.getAllJax('MathOutput')[0];
});
window.UpdateMath=函数(TeX){
Push(['Text',math',\\displaystyle{'+TeX+'}');
document.getElementById('output')。value=''+math.root.toMathML(“”);
};
函数selectTextarea(元素){
var text=document.getElementById(element.select();
}
$${}$$



塞莱西奥纳·科迪戈

问题是,当我更快地键入公式时,MathML代码上不会显示最后一个字符。有时,为了得到正确的MathML代码,我必须在公式的末尾添加一个空格。任何人都可以给我一些提示来解决这个问题吗?

问题是您将
异步
调用与
同步
调用混合在一起。
队列
异步工作,因此在调用此队列时:

MathJax.Hub.queue.Push(['Text', math, '\\displaystyle{' + TeX + '}']);
它不会等到实际渲染完成后才转到下一行。因此,此调用在完成之前执行:

document.getElementById('output').value = '<?xml version="1.0"?>' + math.root.toMathML("");
document.getElementById('output')。value=''+math.root.toMathML(“”);
解决此问题的一种方法是将输出更新排队,您可以通过创建另一个处理输出的函数并在渲染后将其排队来完成此操作,以便仅在渲染完成时执行此操作。例如:

window.updateMathMl = function (math) {
    document.getElementById('output').value = '<?xml version="1.0"?>' + math.root.toMathML("");
};

window.UpdateMath = function (TeX) {
    MathJax.Hub.queue.Push(['Text', math, '\\displaystyle{' + TeX + '}'], [updateMathMl, math]);
};
window.updateMathl=函数(数学){
document.getElementById('output')。value=''+math.root.toMathML(“”);
};
window.UpdateMath=函数(TeX){
Push(['Text',math',\\displaystyle{'+TeX+'}'],[updateMathMl,math]);
};

未来的注意:cdn.mathjax.org即将结束,请查看mathjax.org/cdn-shutdown以了解迁移技巧。