MathJax自动换行

时间:2013-03-05 22:06:25

标签: html ios css mathjax

我已使用以下代码为MathJax配置了额外的处理

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

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

</script>

我认为它必须使用我的HTML代码中的自动换行容器。

我有这个用word-wrap

设置的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>

但在我的案例中,自动换行不起作用。

我已经在iPad上附上了Safri在Safri上的样子

enter image description here

这些单词必须包含在第二行,但它们不是你能看到的广告。

2 个答案:

答案 0 :(得分:5)

EDIT 如果您使用的是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>

答案 1 :(得分:0)

我也遇到过类似的问题,但是我无法解决使用自动换行的问题。
这个问题是由MathJax的默认类引起的,因此我们需要重写它们,以便它根据父级的宽度工作:

.mjx-chtml {
   font-size: ${IS_MOBILE ? '100%' : '120%'} !important;
}
.mjx-table {
   white-space: pre-line !important;
}
.mjx-table .mjx-char {
   white-space: ${IS_MOBILE ? 'pre-line' : 'inherit'} !important;
}
.mjx-full-width {
   width: 0em !important;
}
相关问题