1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-28 15:08:46 +00:00

Merge pull request #2145 from spelufo/katex-displaymode

Make latex-parser.js render $$$ as display mode math
This commit is contained in:
Jeremy Ruston 2015-12-23 17:19:58 +00:00
commit 3dc001620c
2 changed files with 16 additions and 6 deletions

View File

@ -29,23 +29,26 @@ exports.types = {inline: true};
exports.init = function(parser) { exports.init = function(parser) {
this.parser = parser; this.parser = parser;
// Regexp to match // Regexp to match
this.matchRegExp = /\$\$(?!\$)/mg; this.matchRegExp = /\$\$\$?(?!\$)/mg;
}; };
exports.parse = function() { exports.parse = function() {
// Move past the match // Move past the match
this.parser.pos = this.matchRegExp.lastIndex; this.parser.pos = this.matchRegExp.lastIndex;
var reEnd = /\$\$/mg; var reEnd = /\$\$\$?/mg;
// Look for the end marker // Look for the end marker
reEnd.lastIndex = this.parser.pos; reEnd.lastIndex = this.parser.pos;
var match = reEnd.exec(this.parser.source), var match = reEnd.exec(this.parser.source),
text; text,
displayMode;
// Process the text // Process the text
if(match) { if(match) {
text = this.parser.source.substring(this.parser.pos,match.index); text = this.parser.source.substring(this.parser.pos,match.index);
displayMode = match.indexOf('$$$') != -1;
this.parser.pos = match.index + match[0].length; this.parser.pos = match.index + match[0].length;
} else { } else {
text = this.parser.source.substr(this.parser.pos); text = this.parser.source.substr(this.parser.pos);
displayMode = false;
this.parser.pos = this.parser.sourceLength; this.parser.pos = this.parser.sourceLength;
} }
return [{ return [{
@ -54,7 +57,12 @@ exports.parse = function() {
text: { text: {
type: "text", type: "text",
value: text value: text
}} },
displayMode: {
type: "text",
value: displayMode ? "true" : "false"
}
}
}]; }];
}; };

View File

@ -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$$ $$\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: 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> <$latex text="f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi" displayMode="true"></$latex>
``` ```
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. 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.