【问题标题】:Mathjax not rendering TEX formulas dynamically from PHP/AjaxMathjax 不能从 PHP/Ajax 动态渲染 TEX 公式
【发布时间】:2017-11-04 21:11:15
【问题描述】:

var questions = {"ques_id":"1","question":"<p><span class=\\\"math-tex\\\">\\\\(x = {-b \\\\pm \\\\sqrt{b^2-4ac} \\\\over 2a}\\\\)<\/span>&nbsp; &nbsp;Test Question new with mathjax<\/p>","ques_type":"text_based_questions","correctAnswer":3,"choices":[{"option_id":"1","value":"Option A"},{"option_id":"2","value":"Option B"},{"option_id":"3","value":"Option C"},{"option_id":"4","value":"OPtion D"}]};

$('#test-question').html(questions.question);
MathJax.Hub.Queue(["Typeset",MathJax.Hub, 'test-question']);
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        showProcessingMessages: false,
        tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
      });
    </script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML">
    </script>
    </head>
	<body>
    <h5 class="border-bottom">Instructions: Read the question, work out your answer and select the best option.</h5>
    <p><span class="math-tex">\( \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \)</span></p>
		<div class="question" id="test-question"></div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  </body>
</html>

我从 Ajax 请求中收到以下问题

MathJax 配置正确,但来自 JSON 的问题未由 MathJax 呈现。问题保存在 MySQL 数据库中,由 ajax 请求获取。

我尝试了所有方法,但仍然无法正常工作。请帮忙

【问题讨论】:

  • 您可能希望使用 sn-ps 功能创建一个实时示例。这很可能是一个简单的同步问题,但没有足够的信息。
  • @PeterKrautzberger 我添加了一个代码 sn-p,其中未呈现来自 JSON 的 MathJax。

标签: php jquery ajax dynamic mathjax


【解决方案1】:

从 Json 中添加了双斜杠。请删除它会解决您的问题。

【讨论】:

  • question = question.replace(/\\\\/g, '\\'); question = question.replace('&lt;span class=\\\"math-tex\\\"&gt;', '&lt;span class=\"math-tex\"&gt;');
猜你喜欢
  • 1970-01-01
  • 2014-10-08
  • 2017-02-17
  • 2021-10-12
  • 2018-07-05
  • 2019-04-21
  • 2014-11-28
  • 2013-02-11
  • 2020-09-26
相关资源
最近更新 更多