2017-10-05 208 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