2013-03-05 236 views
2

我已經配置額外的處理MathJax與此代碼如下MathJax自動換行

<script type="text/x-mathjax-config"> 

    MathJax.Hub.Config({ 
    tex2jax: { inlineMath: [["$","$"],["\\(","\\)"]] }, 
    "HTML-CSS": { 
     linebreaks: { width: "container" }   
    }    
    }); 

</script> 

正如我認爲它與自動換行的容器,我在我的HTML代碼工作。

我有這個CSS與設置自動換行

.col { 
     background: #f0f0f0; 
     width: 230px; 
     padding: 10px; 
     font-size: 1.5em; 
     word-wrap: break-word; 
    }  

這是我的身體:

<body> 

     <div class = 'col'> 

     $$ 
      Pr [(G \bigcup B \bigcup S)^e ] = 1 - Pr (G \bigcup B \bigcup S)     
      = 1 - [Pr(G)+Pr(B)Pr(S)-Pr(G \bigcap B) - Pr(G \bigcap S) - Pr(B \bigcap S)] 
      Pr [(G \bigcup B \bigcup S)^e ] = 1 - Pr (G \bigcup B \bigcup S) 
      = 1 - [Pr(G)+Pr(B)Pr(S)-Pr(G \bigcap B) - Pr(G \bigcap S) - Pr(B \bigcap S)] 
      = 1 - (0.28 + 0.29 + 0.19 - 0.14 - 0.10 -0.12 + 0.08) = 1 - 0.48 = 0.52 
     $$ 

     </div> 

</body> 

但換行不會在我的情況下工作。

我們已經附上截圖中的樣子Safri iPad上

enter image description here

的話,必須換到第二行,但他們不這樣做的廣告就可以看到。

回答

4

編輯 如果你在iOS6上,那麼你可能會遇到this MathJax bug

MathJax使用自己的換行算法(implementing the MathML specs)。設置word-wrap: break-word;不會改變其行爲。

除非缺少一些信息,否則您的代碼可以按照我的預期工作,即MathJax會實現其斷行。

下面是一個完整的例子。

<!doctype HTML> 
<head> 
<title>Break!</title> 
<script type="text/x-mathjax-config"> 

MathJax.Hub.Config({ 
tex2jax: { inlineMath: [["$","$"],["\\(","\\)"]] }, 
"HTML-CSS": { 
    linebreaks: { automatic: true, width: "container" }   
}    
}); 

</script> 
<script type="text/javascript" 
    src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> 
</script> 
<style> 
.col { 
    background: #f0f0f0; 
    width: 230px; 
    padding: 10px; 
    font-size: 1.5em; 
    word-wrap: break-word; 
} 
</style> 

</head> 
<body> 

    <div class = 'col'> 

    $$ 
     Pr [(G \bigcup B \bigcup S)^e ] = 1 - Pr (G \bigcup B \bigcup S)     
     = 1 - [Pr(G)+Pr(B)Pr(S)-Pr(G \bigcap B) - Pr(G \bigcap S) - Pr(B \bigcap S)] 
     Pr [(G \bigcup B \bigcup S)^e ] = 1 - Pr (G \bigcup B \bigcup S) 
     = 1 - [Pr(G)+Pr(B)Pr(S)-Pr(G \bigcap B) - Pr(G \bigcap S) - Pr(B \bigcap S)] 
     = 1 - (0.28 + 0.29 + 0.19 - 0.14 - 0.10 -0.12 + 0.08) = 1 - 0.48 = 0.52 
    $$ 

    </div> 

</body> 
+0

感謝您的回覆,但不幸的是我不明白我必須設置哪些選項。你能解釋它是如何工作的嗎?我如何設置將顯示數學表達式的容器的寬度。 – 2013-03-06 13:10:32

+0

您的示例也適用於我。你確定你沒有選擇MathML作爲MathJax上下文菜單中的渲染器嗎? – 2013-03-06 17:43:00

+0

HTML-CSS輸出的[documentation](http://docs.mathjax.org/en/latest/options/HTML-CSS.html#configure-html-css)(請參閱換行符部分)顯示您可以明確地設置換行符的寬度,或者根據包含元素的值來設置寬度。後者是默認設置,這似乎對我們有用。也許如果你給一個完整的HTML文件,並指出你正在使用的瀏覽器和操作系統,這將有所幫助。 – 2013-03-06 17:45:57