简体   繁体   English

尝试修改文件内容时,MathJax 无法正常工作<p>标签</p>

[英]MathJax is not working properly when trying to modify the contents of the <p> tag

I have been trying to make a MathJax interpreter using JavaScript, HTML and MathJax.我一直在尝试使用 JavaScript、HTML 和 MathJax 制作 MathJax 解释器。 I have done all of the default inclusions of the MathJax libraries etc. and one feature of the web application is to be able to type in some LaTeX code and look at the output when a button is pressed.我已经完成了 MathJax 库等的所有默认包含,并且 web 应用程序的一个功能是能够输入一些 LaTeX 代码并在按下 a 按钮时查看 Z78E6221F6393D1356681DB398F14CEZ6。 However, when I run the program nothing changes, and all that happens is that the text box which contains the output just has the raw output outputted into it.但是,当我运行程序时,没有任何变化,所发生的只是包含output的文本框只有原始 output 输出到其中。 For Example:例如:

// My LaTeX code:
\[x=5\]
// the expected output when the button is clicked:
x = 5
// what I do get:
\[x=5\]

I have tried numerous things, but I cant seem to get it to work.我已经尝试了很多东西,但我似乎无法让它发挥作用。 Here is my code:这是我的代码:

var input_text = document.getElementById("mathjax_input_area");
var output_p   = document.getElementById("mathjax_output_area");

output_p.innerHTML = input_text.value;
MathJax.Hub.Queue(["Typeset", MathJax.Hub, 'output_p']);

Could someone please help?有人可以帮忙吗?

When you use MathJax.Hub.Queue(["Typeset", MathJax.Hub, string]) , the string is supposed to be the ID of an element in the page, not the name of a variable in your code.当您使用MathJax.Hub.Queue(["Typeset", MathJax.Hub, string])时,字符串应该是页面中元素的 ID,而不是代码中变量的名称。 You could either use你可以使用

MathJax.Hub.Queue(["Typeset", MathJax.Hub, output_p]);

to use the actual DOM element itself (stored in the variable) or使用实际的 DOM 元素本身(存储在变量中)或

MathJax.Hub.Queue(["Typeset", MathJax.Hub, 'mathjax_output_area']);

so that you have passed the actual ID of the element to be processed.这样您就传递了要处理的元素的实际 ID。 Either should work.要么应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM