2013-11-21 29 views
3

我正在嘗試使ractive.js動態更新MathJaxRactive JS和用LaTeX輸入更新MathJax?

現在我知道你可以觸發一個MathJax重新裝入:

MathJax.Hub.Queue.Push(["Typeset",MathJax.Hub]); 

所以我束縛,這對觀察回調:

ractive.observe('input', function (input) { 
    ractive.set('output', input * 2); 
    MathJax.Hub.Queue(["Typeset",MathJax.Hub]); 
    }); 

但是當我嘗試呈現MathJax與\begin{equation} {{output}} \end{equation} 它仍然處於初始值。

testcase

奇怪的是,確實獲得初始值,只是沒有更新。

有什麼想法?

編輯:似乎增加了一大堆嵌套的MathJax_MathContainer元素,每個調用它出現一個。


JsFiddle demo with Peter Krautzberger's suggestion - 似乎仍然沒有工作

回答

3

的事情是,MathJax刪除從DOM元素,因此Ractive不再對其進行更新。這可以通過代替使用包裝LaTeX的MathJax搜索(例如$$)來解決,而不是使用<script type="math/tex; mode=display" id="foo">元素。這將阻止替換,因爲MathJax可以在內部處理腳本元素。

現在你可以觀察的變量和與MathJax.Hub.Queue(["Typeset",MathJax.Hub, "foo"]);

非常感謝Peter Krautzberger您的建議/解決方案觸發重繪。

+0

在Ractive模板的腳本標記中是否遇到嵌套MathJax腳本標記的麻煩? – wrongusername

+0

我得到了Ractive來代替使用'template'標籤,但它仍然不起作用,您是否願意爲您的示例發佈工作代碼?這是我的非工作代碼:https://jsfiddle.net/qpk70h1t/ – wrongusername

+0

@wrongusername請參閱下面的答案。 :) – Kishor

1

@wrongusername我對Ractive沒有任何經驗,我大約3年前只和MathJax一起工作過,但我試過Reprocess而不是Typeset,它工作正常。我認爲你應該使用Reprocess,因爲你的輸入改變了。從documentation,它說

從文檔中移除或DOM元素的任何排版數學(或 元件,如果它是元件的陣列),然後再次處理 數學,重新排版一切。

查看最新的JSFiddle這裏。

你只需要

MathJax.Hub.Queue(["Reprocess", MathJax.Hub, "foo"]); 

希望它可以幫助更換

MathJax.Hub.Queue(["Typeset", MathJax.Hub, "foo"]); 

+1

嗚呼,謝謝! – wrongusername