The Lorenz Equations\n<<dmath \sbegin{aligned}\n\sdot{x} & = \ssigma(y-x) \s\s\n\sdot{y} & = \srho x - y - xz \s\s\n\sdot{z} & = -\sbeta z + xy\n\send{aligned} >>\n\nThe Cauchy-Schwarz Inequality\n<<dmath \sleft( \ssum_{k=1}^n a_k b_k \sright)^2 \sleq \sleft( \ssum_{k=1}^n a_k^2 \sright) \sleft( \ssum_{k=1}^n b_k^2 \sright) >>\n\nA Cross Product Formula\n<<dmath \smathbf{V}_1 \stimes \smathbf{V}_2 = \sbegin{vmatrix}\n\smathbf{i} & \smathbf{j} & \smathbf{k} \s\s\n\sfrac{\spartial X}{\spartial u} & \sfrac{\spartial Y}{\spartial u} & 0 \s\s\n\sfrac{\spartial X}{\spartial v} & \sfrac{\spartial Y}{\spartial v} & 0\n\send{vmatrix} >>\n\nThe probability of getting <<math k>> heads when flipping <<math n>> coins is\n<<dmath P(E) = {n \schoose k} p^k (1-p)^{ n-k} >>\n\nAn Identity of Ramanujan\n<<dmath \sfrac{1}{\sBigl(\ssqrt{\sphi \ssqrt{5}}-\sphi\sBigr) e^{\sfrac25 \spi}} =\n1+\sfrac{e^{-2\spi}} {1+\sfrac{e^{-4\spi}} {1+\sfrac{e^{-6\spi}}\n{1+\sfrac{e^{-8\spi}} {1+\sldots} } } } >>\n\nA Rogers-Ramanujan Identity\n<<dmath 1 + \sfrac{q^2}{(1-q)}+\sfrac{q^6}{(1-q)(1-q^2)}+\scdots =\n\sprod_{j=0}^{\sinfty}\sfrac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n\squad\squad \stext{for $|q|<1$}. >>\n\nMaxwell's Equations\n<<dmath \sbegin{aligned}\n\snabla \stimes \svec{\smathbf{B}} -\s, \sfrac1c\s, \sfrac{\spartial\svec{\smathbf{E}}}{\spartial t} & = \sfrac{4\spi}{c}\svec{\smathbf{j}} \s\s \snabla \scdot \svec{\smathbf{E}} & = 4 \spi \srho \s\s\n\snabla \stimes \svec{\smathbf{E}}\s, +\s, \sfrac1c\s, \sfrac{\spartial\svec{\smathbf{B}}}{\spartial t} & = \svec{\smathbf{0}} \s\s\n\snabla \scdot \svec{\smathbf{B}} & = 0 \send{aligned} >>\n\nFinally, while display equations look good for a page of samples, the ability to mix math and text in a paragraph is also important. This expression <<math \ssqrt{3x-1} + (1+x)^2 >> is an example of an inline equation. As you see, MathJax equations can be used this way as well, without unduly disturbing the spacing between lines.
function loadMathJax() {\n\t/* insert the MathJax script dynamically into the document */\n\tfunction insertScript(doc) {\n\t\tvar script = doc.createElement('script'), config;\n\n\t\t/* see */\n\t\tscript.src = '';\n\t\tscript.type = 'text/javascript';\n\n\t\t/* see */\n\t\tconfig = 'MathJax.Hub.Config({tex2jax:{inlineMath:[],displayMath:[]}});MathJax.Hub.Startup.onload();';\n\n\t\tif (window.opera) script.innerHTML = config; else script.text = config;\n\n\t\tdoc.getElementsByTagName('head')[0].appendChild(script);\n\t}\n\n\t/* execute MathJax for given window */\n\tfunction executeMathJax(win) {\n\t\tif (win.MathJax === undefined) {\n\t\t\t/* insert the script into document if MathJax global doesn't exist for given window */\n\t\t\tinsertScript(win.document);\n\t\t} else {\n\t\t\t/* using win.Array instead of [] to get 'instanceof Array' check working inside iframe */\n\t\t\t/* see */\n\t\t\twin.MathJax.Hub.Queue(new win.Array('Typeset', win.MathJax.Hub));\n\t\t}\n\t}\n\n\tvar frames = document.getElementsByTagName('iframe'), index, win;\n\n\t/* execute MathJax on the window object */\n\texecuteMathJax(window);\n\n\t/* try to execute MathJax on every iframe */\n\tfor (index = 0; index < frames.length; index++) {\n\t\t/* find the iframe's window object */\n\t\twin = frames[index].contentWindow || frames[index].contentDocument;\n\t\tif (!win.document) win = win.parentNode;\n\n\t\texecuteMathJax(win);\n\t}\n};\n\nfunction mathsMacro(mode) {\n\treturn {\n\t\thandler: function(place, macroName, params, parser) {\n\t\t\tvar elem = document.createElement('script');\n\t\t\telem.textContent = params.join(' ');\n\t\t\telem.setAttribute('type','math/tex; mode='+mode);\n\t\t\tplace.appendChild(elem);\n\t\t\tif(window.MathJax)\n\t\t\t\tMathJax.Hub.Queue(['Typeset',MathJax.Hub,place]);\n\t\t},\n\t\tinit: function() {\n\t\t\tif(!window.MathJax) {\n\t\t\t\tloadMathJax();\n\t\t\t}\n\t\t}\n\t}\n}\n\nmacros['math'] = mathsMacro('inline');\nmacros['dmath'] = mathsMacro('display');
This is a simple Twine story to show off the MathJax macro.\n\nYou can get the code for this at [[GitHub|]].\n\nUse <code>math</code> to get inline maths: <<math e^{i \spi} + 1 = 0>>\nUse <code>dmath</code> to get display mode maths: <<dmath e^{i \spi} + 1 = 0>>\nYou can spread your TeX across several lines, with no problems\n<<dmath \sbegin{align}x &= 1, & y &= 2, \s\sz &= 3, & w &= 4. \send{align}>>\nTwine puts content in the page dynamically, so the macro needs to tell MathJax there's new stuff to typeset when you [[move to another passage|end]].
MathJax Twine demo
Christian Perfect
body {\n\tbackground: white;\n\tcolor: black;\n\tfont-size: 18px;\n}
.MathJax_Display ~ br {\n\tdisplay: none;\n}