# If you use the jsMath control panel, it will add parameters to the URL, which interfere with TiddlyWiki's save function. The jsMath options are stored in a cookie, so after setting them it is safe to reload your tiddlywiki file.\n# The font browser font size and alignment does not always match the math. (anyone have an idea to fix this?)\n# jsMath uses document.write() which prevents it from being loaded in a tiddler.\n# jsMath loads external browser-specific code (and this code is fairly large) which also prevents jsMath from being placed entirely in a tiddler.
[[Outdated Notice]]\nLaTeX\n[[Scientific Notation]]
LaTeX is the world standard for specifying, typesetting, and communicating mathematics among scientists, engineers, and mathematicians. For more information about LaTeX itself, visit the [[LaTeX Project|http://www.latex-project.org/]]. On this page math is typeset using [[jsMath|http://www.math.union.edu/~dpvc/jsMath/]], which is an implementation of the TeX math rules and typesetting in javascript, for your browser. Notice the small button in the lower right corner which opens its control panel.\n\n[[Plugin: jsMath]] contains the formatting code for the {{{$ $}}} and {{{\s( \s)}}} in-line operators, which generate math like $e^x$. It also contains code for the block display operators {{{$$ $$}}}, {{{\s[ \s]}}}, {{{\sbegin{equation} \send{equation} }}}, and {{{\sbegin{eqnarray} \send{eqnarray} }}}. Block equations look like\n\sbegin{equation}\n\sint_a^b x\s, dx = \sfrac{1}{2}(b^2-a^2),\n\send{equation}\nwhile {{{eqnarray}}} environment is used to make multi-line equations such as \n\sbegin{eqnarray}\ne^x &=& 1+x+{\sfrac {1}{2}}{x}^{2}+{\sfrac {1}{6}}{x}^{3}+{\sfrac {1}{24}}{x}^{4}+{\sfrac {1}{120}}{x}^{5}+{\sfrac {1}{720}}{x}^{6} \s\s\n&& +{\sfrac {1}{5040}}{x}^{7}+{\sfrac {1}{40320}}{x}^{8}+{\sfrac {1}{362880}}{x}^{9}+{\sfrac {1}{3628800}}{x}^{10}+O \sleft( {x}^{11} \sright).\n\send{eqnarray}\n\nTo use this plugin you must add the following to your tiddlywiki html file: \n{{{\n <script src="path-to-jsMath/jsMath.js"></script>\n}}}\nBecause jsMath itself is not included in the tiddly html file, it must be placed on some web server somewhere, or on your filesystem so that your tiddlywiki can access it. This file will work if you place the jsMath directory in the same directory as the tiddlywiki html file.\n\nFor the best appearance, use a serif font for your tiddlers, and adjust the line-height as in my StyleSheet. Finally, the font size must be somewhat large if you want small math such as exponents to be legible.\n\nPlease mail comments or improvements to bob at (domain of this web page). Especially if you have fixed one of the [[Bugs]]!
<<newTiddler>>\n----\n[[Plugin: jsMath]]\nLaTeX\n[[Bugs]]\nStyleSheet
This version of [[Plugin: jsMath]] is now outdated. (But those still using TiddlyWiki 1.2 may want it)\n\nA version of this plugin for [[is available for TiddlyWiki 2.0|tiddlyjsmath-2.0.3.html]].
window.createTiddlerViewer_orig_mptw_autopre = window.createTiddlerViewer;\n\nwindow.createTiddlerViewer = function(title,highlightText,highlightCaseSensitive) {\n \n var theBody = document.getElementById("body" + title);\n if(theBody) {\n \n var tiddler = store.tiddlers[title];\n if (typeof tiddler != "undefined" &&\n (title=="StyleSheet" || title == "StyleSheetColors" || title == "StyleSheetLayout"\n || tiddler.getTags().indexOf("systemConfig") != -1\n || tiddler.getTags().indexOf("stylesheet") != -1\n // TODO: should be configurable in config instead of hard coded here...\n )\n )\n {\n var realText = store.getTiddlerText(title);\n var tweakedText = "{{{\sn" + realText + "\sn}}}";\n tiddler.text = tweakedText;\n createTiddlerViewer_orig_mptw_autopre(title,highlightText,highlightCaseSensitive);\n tiddler.text = realText;\n }\n else {\n createTiddlerViewer_orig_mptw_autopre(title,highlightText,highlightCaseSensitive);\n }\n }\n}
config.formatterHelpers.mathFormatHelper = function(w) {\n var e = document.createElement(this.element);\n e.className = this.className;\n var endRegExp = new RegExp(this.terminator, "mg");\n endRegExp.lastIndex = w.matchStart+w.matchLength;\n var matched = endRegExp.exec(w.source);\n if(matched) {\n var txt = w.source.substr(w.matchStart+w.matchLength, \n matched.index-w.matchStart-w.matchLength);\n if(this.keepdelim) {\n txt = w.source.substr(w.matchStart, matched.index+matched[0].length-w.matchStart);\n }\n e.appendChild(document.createTextNode(txt));\n w.output.appendChild(e);\n w.nextMatch = endRegExp.lastIndex;\n }\n}\n\nconfig.formatters.push({\n name: "displayMath1",\n match: "\s\s\s$\s\s\s$",\n terminator: "\s\s\s$\s\s\s$\s\sn?",\n element: "div",\n className: "math",\n handler: config.formatterHelpers.mathFormatHelper\n});\n\nconfig.formatters.push({\n name: "inlineMath1",\n match: "\s\s\s$", \n terminator: "\s\s\s$",\n element: "span",\n className: "math",\n handler: config.formatterHelpers.mathFormatHelper\n});\n\nconfig.formatters.push({\n name: "scientificNotation",\n match: "\s\sb[0-9]+\s\s.[0-9]+[eE][+-]?[0-9]+\s\sb",\n element: "span",\n className: "math",\n normalize: true, // set to 'true' to convert numbers to X.XXX \stimes 10^{y}\n sigfigs: 3, // with this many digits in the mantissa\n handler: function(w) {\n var snRegExp = new RegExp("\s\sb([0-9]+(?:\s\s.[0-9]+)?)[eE]([-0-9+]+)\s\sb");\n var mymatch = snRegExp.exec(w.matchText);\n var mantissa = mymatch[1];\n var exponent = parseInt(mymatch[2]);\n // normalize the number.\n if(this.normalize) {\n mantissa = parseFloat(mantissa);\n while(mantissa > 10.0) {\n mantissa = mantissa / 10.0;\n exponent++; \n }\n while(mantissa < 1.0) {\n mantissa = mantissa * 10.0;\n exponent--;\n }\n var sigfigsleft = this.sigfigs;\n mantissa = parseInt(mantissa) + "." + (Math.round(Math.pow(10,this.sigfigs-1)*mantissa)+"").substr(1,this.sigfigs-1);\n }\n var e = document.createElement(this.element);\n e.className = this.className;\n e.appendChild(document.createTextNode(mantissa + "\s\stimes 10^{" + exponent + "}"));\n w.output.appendChild(e);\n }\n});\n\nvar backslashformatters = new Array(0);\n\nbackslashformatters.push({\n name: "inlineMath2",\n match: "\s\s\s\s\s\s\s(",\n terminator: "\s\s\s\s\s\s\s)",\n element: "span",\n className: "math",\n handler: config.formatterHelpers.mathFormatHelper\n});\n\nbackslashformatters.push({\n name: "displayMath2",\n match: "\s\s\s\s\s\s\s[",\n terminator: "\s\s\s\s\s\s\s]\s\sn?",\n element: "div",\n className: "math",\n handler: config.formatterHelpers.mathFormatHelper\n});\n\nbackslashformatters.push({\n name: "displayMath3",\n match: "\s\s\s\sbegin\s\s{equation\s\s}",\n terminator: "\s\s\s\send\s\s{equation\s\s}\s\sn?",\n element: "div",\n className: "math",\n handler: config.formatterHelpers.mathFormatHelper\n});\n\n// These can be nested. e.g. \sbegin{equation} \sbegin{array}{ccc} \sbegin{array}{ccc} ...\nbackslashformatters.push({\n name: "displayMath4",\n match: "\s\s\s\sbegin\s\s{eqnarray\s\s}",\n terminator: "\s\s\s\send\s\s{eqnarray\s\s}\s\sn?",\n element: "div",\n className: "math",\n keepdelim: true,\n handler: config.formatterHelpers.mathFormatHelper\n});\n\n// The escape must come between backslash formatters and regular ones.\n// So any latex-like \scommands must be added to the beginning of\n// backslashformatters here.\nbackslashformatters.push({\n name: "escape",\n match: "\s\s\s\s.",\n handler: function(w) {\n w.output.appendChild(document.createTextNode(w.source.substr(w.matchStart+1,1)));\n w.nextMatch = w.matchStart+2;\n }\n});\n\nconfig.formatters=backslashformatters.concat(config.formatters);\n\nfunction wikify(source,output,highlightText,highlightCaseSensitive)\n{\n var w = new Wikifier(source,output,config.formatters,highlightText,highlightCaseSensitive);\n jsMath.ProcessBeforeShowing();\n}
This plugin now supports entering scientific notation in the format {{{2.48e-3}}} and will format it as 2.48e-3 using jsMath. You can also specify whether to normalize the number e.g. if you enter {{{0.032e-4}}} it will convert it to 0.032e-4. You can also specify the number of significant figures to print.
a reusable non-linear personal web notebook with LaTeX via [[jsMath|http://www.math.union.edu/~dpvc/jsMath/]]
$L_AT^EX$ TiddlyWiki
http://bob.mcelrath.org/tiddlyjsmath-1.2.37.html
.viewer {\n line-height: 125%;\n font-family: serif;\n font-size: 12pt;\n}