Files
GitJournal/lib/core/markdown_latex.dart
Vishesh Handa b4f3c96889 Experimenting with different latex syntaxes
I'm still not sure which ones are used.
2021-08-26 08:33:20 +02:00

32 lines
906 B
Dart

import 'package:markdown/markdown.dart' as md;
// Mathjax :
// \\[ x = {-b \pm \sqrt{b^2-4ac} \over 2a} \\]
// \\( x = {-b \pm \sqrt{b^2-4ac} \over 2a} \\)
// FIXME: Should it be with a \\ or just \
// $$ \begin{equation} \label{label} ... \end{equation} $$
// `$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$`
// `$$c=\sqrt{a^2 + b^2}$$`
// with $$ it can span multiple lines
// For inline mode, you can either use $...$ or \(...\). As an example, \(E = mc^2\) yields E=mc2.
// Alternatively, \begin{math} and \end{math} can be used.
class MathJaxInlineSyntax extends md.InlineSyntax {
static final String _pattern = r'\\(.*\\)';
MathJaxInlineSyntax() : super(_pattern);
@override
bool onMatch(md.InlineParser parser, Match match) {
var text = match[1]!;
var el = md.Element('span', [md.Text(text)]);
el.attributes['type'] = 'mathjax';
parser.addNode(el);
return true;
}
}