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:
parent
aaf3e6bb9e
commit
a94ba99ec2
@ -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"
|
||||
}
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user