1

私は次のdivを持っています:

<div id="math-display">``</div>

MathJax.Hub.Queue(['Typeset', MathJax.Hub, 'math-display'])ページが読み込まれると、ページが実行されます。`AsciiMath 入力の区切り文字です。

ラテックスを使用して方程式を入力し、更新したい場合はmath-display、次のコードを実行できます。

MathJax.Hub.Queue(['Text', MathJax.Hub.getAllJax('math-display')[0], 'new latex here'])

ただし、ラテックスの代わりに AsciiMath 入力を配置した場合、結果は引き続きラテックスでレンダリングされます ('new latex here'文字列で AsciiMath 区切り文字が使用されている場合でも)。表示された MathJax をラテックスではなく AsciiMath 入力で更新するにはどうすればよいですか?

可能であれば、Typeset更新のために電話をかけないことをお勧めします。

4

1 に答える 1

1

Text()メソッドはオブジェクト インスタンスのテキストのみを更新し、このオブジェクトは既に入力の型をプロパティとして持っています。このタイプの入力はdelimiters、オブジェクトの作成時に定義されます。

使うときtext()は の間にあった文字列を変更するdelimitersので は不要ですがdelimiters、入力の型は変更できません。

typesetただし、単一の要素を使用できます。区切り記号で定義された入力で新しいオブジェクトを作成します。たとえば、スニペットを参照してください。

document.querySelector('#switch').onclick = function() {
  //inputJax property defines type of input  
  alert('input type of math-display is: ' + MathJax.Hub.getAllJax('math-display')[0].inputJax);
  
  //To change type of input, you can modifiy content of math-display, not of the math object that was generated 
  document.querySelector('#math-display').textContent = "$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$";
  
  //You typeset only element that has id math-display. 
  MathJax.Hub.Queue(['Typeset', MathJax.Hub, 'math-display']);

}
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
<div id="math-display">`sum_(i=1)^n i^3=((n(n+1))/2)^2`</div>
<button id="switch">Change content</button>

于 2015-07-18T15:16:52.203 に答える