2017-10-05 207 views
0

我面临的问题是如何在ckeditor中显示匹配公式的正确格式,我试图用很多方法搜索,但它似乎不能..如何在ckeditor中显示数学公式的正确格式

这是我的来源:

<html> 
<head> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> 
<script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['\\(','\\)']]}});</script>  

<script type="text/javascript"> 
    $(function(){ 
    init(); 
    }); 
</script> 

<script language="javascript"> 
    function init() 
    { 
     var strArea = "";    
     strArea += "<table border='0' cellpadding='0' cellspacing='0' align='left' valign='top' width='100%' id='contents2'>"; 

     strArea += "<tr><td>"; 
     strArea += "<table border='0' cellpadding='0' cellspacing='0' align='left' valign='top' width='100%'>"; 
     strArea += "<tr><td height='20'></td></tr><tr><td>"; 
     strArea += "<table border='3' cellpadding='0' cellspacing='0' align='left' valign='top'>"; 
     strArea += "<tr>"; 
     strArea += "<td width='20' valign='top' style='line-height:2.1'><div id='quizno'>\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</div></td>"; 
     strArea += "<td width='5'></td>"; 
     strArea += "<td style='line-height:2.1'><H1><div id='quiz'>aaaa</div></H1></td>"; 
     strArea += "</tr>"; 
     strArea += "</table></td></tr>"; 
     strArea += "<tr><td height='7'>bbb</td></tr><tr><td>"; 
     strArea += "<table border='1' cellpadding='0' cellspacing='0' align='left' valign='top'>"; 
     strArea += "</table></td></tr></table></td></tr>";   
     strArea += "</table></td></tr></table>"; 
     document.all.quizdiv.innerHTML = strArea; 
     // CKEDITOR.instances.ir4.getData() 
     // CKEDITOR.instances.quizdiv.getData(document.getElementById('quizdiv').innerHTML) = strArea;   
    }  
    </script>  
    </head> 
    <body> 
    <div style="overflow: auto; height: 700; width: 100%" id="centerdiv"> 
    <div id="quizdiv" style="width: 100%;"></div>          
</div> 
</body> 
</html> 

我尝试用数学公式的默认要显示的文本是:(X = {-b \时\ SQRT {b^2-4ac} \ 2A超}),但并不正确显示

enter image description here

如何显示正确的数学公式格式?感谢..

+0

就是你能正确的显示意思? –

+0

嗨@Mahbubul,这是数学公式ckeditor .. – luongkhanh

回答

1

我发现不同的问题...

  1. CKEditor的已被应用到一个文本...

    <textarea id="quizdiv" style="width: 100%;"></textarea> 
    
  2. 您必须使用标准的所有版本的CKEditor而不是标准版本,因为标准不包括额外的插件...

    <script src="https://cdn.ckeditor.com/4.7.3/standard-all/ckeditor.js"></script> 
    
  3. 您必须配置CKEDITOR.config.extraPluginsCKEDITOR.config.mathJaxLib ...

    CKEDITOR.config.extraPlugins = 'mathjax'; 
    CKEDITOR.config.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML'; 
    
  4. 你必须把公式一个<span class='math-tex'>内...

    <span class="math-tex">\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</span> 
    
  5. 你正在创建的内部公式字符串,所以你必须转义'\'字符,使它们出现在字符串中,以便插件可以读取它们...

    strArea += "<td width='50%' valign='top' style='line-height:2.1'><span class='math-tex'>\\(x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}\\)</span></td>"; 
    

这里有一个工作文件...

https://fiddle.jshell.net/rigobauer/3qgeL5ae/

我希望它能帮助

+0

嗨@A。 lglesias:感谢你的高级,我正在修改你的建议。 – luongkhanh