diff --git a/plugins/tiddlywiki/katex/latex-parser.js b/plugins/tiddlywiki/katex/latex-parser.js index 067510fc2..0aacfd488 100644 --- a/plugins/tiddlywiki/katex/latex-parser.js +++ b/plugins/tiddlywiki/katex/latex-parser.js @@ -29,23 +29,26 @@ 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), - text; + text, + displayMode; // Process the text if(match) { text = this.parser.source.substring(this.parser.pos,match.index); + displayMode = match.indexOf('$$$') != -1; this.parser.pos = match.index + match[0].length; } else { text = this.parser.source.substr(this.parser.pos); + displayMode = false; this.parser.pos = this.parser.sourceLength; } return [{ @@ -54,8 +57,13 @@ exports.parse = function() { text: { type: "text", value: text - }} + }, + displayMode: { + type: "text", + value: displayMode ? "true" : "false" + } + } }]; }; -})(); \ No newline at end of file +})(); diff --git a/plugins/tiddlywiki/katex/usage.tid b/plugins/tiddlywiki/katex/usage.tid index b8ffd15a7..bb9101092 100644 --- a/plugins/tiddlywiki/katex/usage.tid +++ b/plugins/tiddlywiki/katex/usage.tid @@ -6,10 +6,12 @@ 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 `$$`. + The underlying widget can also be used directly, giving more flexibility: ``` -<$latex text="\displaystyle f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi"> +<$latex text="f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi" displayMode="true"> ``` The KaTeX widget is provided under the name `<$latex>` and is also available under the alias `<$katex>`. It's better to use the generic `<$latex>` name unless you are running multiple ~LaTeX plugins and wish to specifically target KaTeX.