-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathtex_view_document_example.dart
147 lines (131 loc) · 4.93 KB
/
tex_view_document_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import 'package:flutter/material.dart';
import 'package:flutter_tex/flutter_tex.dart';
class TeXExample {
static TeXViewWidget introduction =
_teXViewWidget(r"""<h4>Flutter \( \rm\TeX \)</h4>""", r"""
<p>Flutter \( \rm\TeX \) is a Flutter Package to render so many types of equations based on \( \rm\LaTeX \), It also includes full HTML with JavaScript
support.</p>
""");
static TeXViewWidget quadraticEquation =
_teXViewWidget(r"<h4>Quadratic Equation</h4>", r"""
When \(a \ne 0 \), there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$<br>""");
static TeXViewWidget mathML =
_teXViewWidget(r"<h4>MathML (MathJax Only)</h4>", r"""
<math xmlns = "http://www.w3.org/1998/Math/MathML">
<mrow>
<mrow>
<msup> <mi>x</mi> <mn>2</mn> </msup> <mo>+</mo>
<mrow>
<mn>4</mn>
<mo></mo>
<mi>x</mi>
</mrow>
<mo>+</mo>
<mn>4</mn>
</mrow>
<mo>=</mo>
<mn>0</mn>
</mrow>
</math>""");
static TeXViewWidget bohrRadius = _teXViewWidget(r"<h4>Bohr's Radius</h4>",
r"""\( a_0 = \frac{{\hbar ^2 }}{{m_e ke^2 }} \)""");
static TeXViewWidget relationEnergyPrincipalQuantum = _teXViewWidget(
r"<h4>Relationship between Energy and Principal Quantum Number</h4>",
r"""\( E_n = - R_H \left( {\frac{1}{{n^2 }}} \right) = \frac{{ - 2.178 \times 10^{ - 18} }}{{n^2 }}joule \)""");
static TeXViewWidget chemistryEquations =
_teXViewWidget(r"<h4>Chemistry Equations</h4>", r"""<p>
\( \ce{CO2 + C -> 2 CO} \) <br>
\( \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} \)<br>
Scroll long formulas in Katex $$ \ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x Nh4 ^ + x H2O} $$ <br>
</p>""");
static TeXViewWidget matrix = _teXViewWidget(r"<h4>Matrix</h4>", r"""<p>
$$ \begin{bmatrix}
a & b \\
c & d
\end{bmatrix}$$</p>""");
static TeXViewWidget alignedTag = _teXViewWidget(r"<h4>Aligned Tag</h4>", r"""
$$
\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}
$$""");
static TeXViewWidget others = _teXViewWidget(r"<h4> Others </h4>", r"""<p>
$$ \oint_C {E \cdot d\ell = - \frac{d}{{dt}}} \int_S {B_n dA} $$<br>
$$
y = \frac{{n!}}{{k!\left( {n - k} \right)!}}p^k q^{n - k} = \left( {\begin{array}{*{20}c}
n \\
k \\
\end{array}} \right)p^k q^{n - k}
$$
</p>""");
static TeXViewWidget _teXViewWidget(String title, String body) {
return TeXViewColumn(
style: const TeXViewStyle(
margin: TeXViewMargin.all(10),
padding: TeXViewPadding.all(10),
borderRadius: TeXViewBorderRadius.all(10),
border: TeXViewBorder.all(TeXViewBorderDecoration(
borderWidth: 2,
borderStyle: TeXViewBorderStyle.groove,
borderColor: Colors.green))),
children: [
TeXViewDocument(title,
style: const TeXViewStyle(
padding: TeXViewPadding.all(10),
borderRadius: TeXViewBorderRadius.all(10),
textAlign: TeXViewTextAlign.center,
width: 250,
margin: TeXViewMargin.zeroAuto(),
backgroundColor: Colors.green)),
TeXViewDocument(body,
style: const TeXViewStyle(margin: TeXViewMargin.only(top: 10)))
]);
}
}
class TeXViewDocumentExamples extends StatelessWidget {
const TeXViewDocumentExamples({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text("TeXViewDocument"),
),
body: TeXView(
child: TeXViewColumn(children: [
TeXExample.introduction,
TeXExample.mathML,
TeXExample.quadraticEquation,
TeXExample.relationEnergyPrincipalQuantum,
TeXExample.alignedTag,
TeXExample.bohrRadius,
TeXExample.chemistryEquations,
TeXExample.matrix,
TeXViewDetails(
title: "Collapsible Widget",
style: const TeXViewStyle(backgroundColor: Colors.amber),
body: TeXExample.matrix,
),
if (TeXRederingServer.renderingEngine.name == 'mathjax') ...[
TeXExample.others
]
]),
style: const TeXViewStyle(
margin: TeXViewMargin.all(10),
elevation: 10,
borderRadius: TeXViewBorderRadius.all(25),
border: TeXViewBorder.all(
TeXViewBorderDecoration(
borderColor: Colors.blue,
borderStyle: TeXViewBorderStyle.solid,
borderWidth: 5),
),
backgroundColor: Colors.white,
),
),
);
}
}