From 8e0239035357e31395cec7dafc2ee64c1f115714 Mon Sep 17 00:00:00 2001 From: Santiago Pelufo Date: Thu, 24 Dec 2015 13:45:45 -0300 Subject: [PATCH] Revert katex plugin to using `$$`. Use multiline for display mode. --- editions/katexdemo/tiddlers/HelloThere.tid | 26 ++++++++++++++++------ plugins/tiddlywiki/katex/latex-parser.js | 6 ++--- plugins/tiddlywiki/katex/usage.tid | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/editions/katexdemo/tiddlers/HelloThere.tid b/editions/katexdemo/tiddlers/HelloThere.tid index e0a32b20a..0d058a371 100644 --- a/editions/katexdemo/tiddlers/HelloThere.tid +++ b/editions/katexdemo/tiddlers/HelloThere.tid @@ -22,30 +22,42 @@ These examples are taken from http://khan.github.io/KaTeX/ !! Example 1 -To render in display mode use `$$$`: +If the text between `$$` contains newlines it will rendered in display mode: ``` -$$$ f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi $$$ +$$ +f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi +$$ ``` -$$$ f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi $$$ +$$ +f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi +$$ !! Example 2 ``` -$$$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } $$$ +$$ +\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } +$$ ``` -$$$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } $$$ +$$ +\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } +$$ !! Example 3 ``` -$$$ 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for }\lvert q\rvert<1. $$$ +$$ +1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for }\lvert q\rvert<1. +$$ ``` -$$$ 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for }\lvert q\rvert<1. $$$ +$$ +1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for }\lvert q\rvert<1. +$$ !! Widget Example diff --git a/plugins/tiddlywiki/katex/latex-parser.js b/plugins/tiddlywiki/katex/latex-parser.js index 0aacfd488..6b72c7f51 100644 --- a/plugins/tiddlywiki/katex/latex-parser.js +++ b/plugins/tiddlywiki/katex/latex-parser.js @@ -29,13 +29,13 @@ exports.types = {inline: true}; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /\$\$\$?(?!\$)/mg; + this.matchRegExp = /\$\$(?!\$)/mg; }; exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - var reEnd = /\$\$\$?/mg; + var reEnd = /\$\$/mg; // Look for the end marker reEnd.lastIndex = this.parser.pos; var match = reEnd.exec(this.parser.source), @@ -44,7 +44,7 @@ exports.parse = function() { // Process the text if(match) { text = this.parser.source.substring(this.parser.pos,match.index); - displayMode = match.indexOf('$$$') != -1; + displayMode = text.indexOf('\n') != -1; this.parser.pos = match.index + match[0].length; } else { text = this.parser.source.substr(this.parser.pos); diff --git a/plugins/tiddlywiki/katex/usage.tid b/plugins/tiddlywiki/katex/usage.tid index bb9101092..8e7e53bb9 100644 --- a/plugins/tiddlywiki/katex/usage.tid +++ b/plugins/tiddlywiki/katex/usage.tid @@ -6,7 +6,7 @@ The usual way to include ~LaTeX is to use `$$`. For example: $$\displaystyle f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi$$ ``` -To make math render in display mode, use `$$$` instead of `$$`. +Single line equations will render in inline mode. If there are newlines between the `$$` delimiters, the equations will be rendered in display mode. The underlying widget can also be used directly, giving more flexibility: