SHARE
TWEET

Untitled

a guest May 3rd, 2012 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***
  2. |''Name:''|MathJaxPlugin|
  3. |''Description:''|Enable LaTeX formulas for TiddlyWiki|
  4. |''Version:''|1.0.1|
  5. |''Date:''|Feb 11, 2012|
  6. |''Source:''|http://www.guyrutenberg.com/2011/06/25/latex-for-tiddlywiki-a-mathjax-plugin|
  7. |''Author:''|Guy Rutenberg|
  8. |''License:''|[[BSD open source license]]|
  9. |''~CoreVersion:''|2.5.0|
  10.  
  11. !! Changelog
  12. !!! 1.0.1 Feb 11, 2012
  13. * Fixed interoperability with TiddlerBarPlugin
  14. !! How to Use
  15. Currently the plugin supports the following delemiters:
  16. * """\(""".."""\)""" - Inline equations
  17. * """$$""".."""$$""" - Displayed equations
  18. * """\[""".."""\]""" - Displayed equations
  19. !! Demo
  20. This is an inline equation \(P(E)   = {n \choose k} p^k (1-p)^{ n-k}\) and this is a displayed equation:
  21. \[J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha}\]
  22. This is another displayed equation $$e=mc^2$$
  23. !! Code
  24. ***/
  25. //{{{
  26. config.extensions.MathJax = {
  27.    mathJaxScript : "mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
  28.   // uncomment the following line if you want to access MathJax using SSL
  29.   // mathJaxScript : "https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
  30.   displayTiddler: function(TiddlerName) {
  31.     config.extensions.MathJax.displayTiddler_old = story.displayTiddler
  32.     config.extensions.MathJax.displayTiddler_old.apply(this, arguments);
  33.     MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
  34.   }
  35. };
  36.  
  37.  
  38. var mathjax_script = document.createElement('script');
  39. mathjax_script.setAttribute('type', 'text/javascript');
  40. mathjax_script.setAttribute('src', config.extensions.MathJax.mathJaxScript);
  41. mathjax_script.onload = function() {
  42.     MathJax.Hub.Config({
  43.       extensions: ["tex2jax.js"],
  44.       "TML-CSS": { scale: 100 }
  45.     });
  46.  
  47.     MathJax.Hub.Startup.onload();
  48.     story.displayTiddler = config.extensions.MathJax.displayTiddler;
  49. };
  50. document.getElementsByTagName('head')[0].appendChild(mathjax_script);
  51.  
  52. config.formatters.push({
  53.         name: "mathJaxFormula",
  54.         match: "\\\\\\[|\\$\\$|\\\\\\(",
  55.         //lookaheadRegExp: /(?:\\\[|\$\$)((?:.|\n)*?)(?:\\\]|$$)/mg,
  56.         handler: function(w)
  57.         {
  58.                 switch(w.matchText) {
  59.                 case "\\[": // displayed equations
  60.                         this.lookaheadRegExp = /\\\[((?:.|\n)*?)(\\\])/mg;
  61.                         break;
  62.                 case "$$": // inline equations
  63.                         this.lookaheadRegExp = /\$\$((?:.|\n)*?)(\$\$)/mg;
  64.                         break;
  65.                 case "\\(": // inline equations
  66.                         this.lookaheadRegExp = /\\\(((?:.|\n)*?)(\\\))/mg;
  67.                         break;
  68.                 default:
  69.                         break;
  70.                 }
  71.                 this.lookaheadRegExp.lastIndex = w.matchStart;
  72.                 var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  73.                 if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  74.                         createTiddlyElement(w.output,"span",null,null,lookaheadMatch[0]);
  75.                         w.nextMatch = this.lookaheadRegExp.lastIndex;
  76.                 }
  77.         }
  78. });
  79. //}}}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top