MathJax Typeset -- 如何呈現特定區域的數學式

JavaScript

簡介

歷史

開發工具

基本語法

運算式

分枝

迴圈

函數

陣列

物件導向

原型

封裝

繼承

多型

this

控制流程

進階功能

Eval 函數

Closure

JSONP

小書籤

字串

正規表達式

除錯方法

伺服端

播 midi

cookie

套件

ccc函式庫

2D 繪圖

3D 繪圖

影像處理

訊號處理

語音處理

數學計算

tex 數學式

格式轉換

桌面應用

自然語言

地理資訊

平台

Node.js

jQuery

Google

numeric.js

Titanium

引擎

語法

作品

翻譯精靈

繪圖精靈

DotWiki

流程

前端工程師

後端工程師

css

訊息

相關網站

參考文獻

最新修改

簡體版

English

Manipulating Individual Math Elements

<div id="MathDiv">
  The answer you provided is: ${}$.
</div>
var math = MathJax.Hub.getAllJax("MathDiv")[0];
MathJax.Hub.Queue(["Text",math,"x+1"]);
var studentDisplay = null;
MathJax.Hub.Queue(function () {
  studentDisplay = MathJax.Hub.getAllJax("MathDiv");
});
MathJax.Hub.Queue(["Text",studentDisplay,studentAnswer])

The actions you can perform on an element jax include:

Text(newmath)
to set the math text of the element to newmath and typeset.

Reprocess()
to remove the output and reproduce it again (for example, if CSS has changed that would alter the spacing of the mathematics).

Remove()
to remove the output for this math element (but not the original <script> tag).

SourceElement()
to obtain a reference to the original <script> object that is assocaited with this element jax.

完整範例

<html>
<head>
<title>MathJax Dynamic Math Test Page</title>

<script src="/MathJax/MathJax.js">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
    tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
  });
</script>

</head>
<body>

<script>
  //
  //  Use a closure to hide the local variables from the
  //  global namespace
  //
  (function () {
    var QUEUE = MathJax.Hub.queue;  // shorthand for the queue
    var math = null;                // the element jax for the math output.

    //
    //  Get the element jax when MathJax has produced it.
    //
    QUEUE.Push(function () {
      math = MathJax.Hub.getAllJax("MathOutput")[0];
    });

    //
    //  The onchange event handler that typesets the
    //  math entered by the user
    //
    window.UpdateMath = function (TeX) {
      QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
    }
  })();
</script>

Type some TeX code:
<input id="MathInput" size="50" onchange="UpdateMath(this.value)" />
<p>

<div id="MathOutput">
You typed: ${}$
</div>

</body>
</html>

參考文獻

  1. http://www.mathjax.org/docs/typeset.html

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License