1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Make latex-parser.js render $$$ as display mode math

This commit is contained in:
Santiago Pelufo 2015-12-23 14:14:58 -03:00
parent aaf3e6bb9e
commit a94ba99ec2
2 changed files with 16 additions and 6 deletions

View File

@ -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"
}
}
}];
};
})();
})();

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$$
```
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>
<$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.