Showing
5 changed files
with
50 additions
and
42 deletions
@@ -39,13 +39,12 @@ class _MyAppState extends State<MyApp> { | @@ -39,13 +39,12 @@ class _MyAppState extends State<MyApp> { | ||
39 | child: TexText( | 39 | child: TexText( |
40 | // TexText.newEasySyntax(_text.text), | 40 | // TexText.newEasySyntax(_text.text), |
41 | _text.text, | 41 | _text.text, |
42 | - alignment: TexAlignment.start, | ||
43 | style: Theme.of(context) | 42 | style: Theme.of(context) |
44 | .textTheme | 43 | .textTheme |
45 | - .headlineLarge | 44 | + .titleLarge |
46 | ?.copyWith( | 45 | ?.copyWith( |
47 | - // color: Colors.red, | ||
48 | - ), | 46 | + color: Colors.blue, |
47 | + ), | ||
49 | mathStyle: MathStyle.displayCramped, | 48 | mathStyle: MathStyle.displayCramped, |
50 | ), | 49 | ), |
51 | ); | 50 | ); |
@@ -238,7 +238,7 @@ packages: | @@ -238,7 +238,7 @@ packages: | ||
238 | path: ".." | 238 | path: ".." |
239 | relative: true | 239 | relative: true |
240 | source: path | 240 | source: path |
241 | - version: "0.1.5" | 241 | + version: "0.1.7" |
242 | tuple: | 242 | tuple: |
243 | dependency: transitive | 243 | dependency: transitive |
244 | description: | 244 | description: |
@@ -4,65 +4,61 @@ import 'package:flutter/material.dart'; | @@ -4,65 +4,61 @@ import 'package:flutter/material.dart'; | ||
4 | import 'package:flutter_math_fork/flutter_math.dart'; | 4 | import 'package:flutter_math_fork/flutter_math.dart'; |
5 | export 'package:flutter_math_fork/flutter_math.dart'; | 5 | export 'package:flutter_math_fork/flutter_math.dart'; |
6 | 6 | ||
7 | -enum TexAlignment { | ||
8 | - /// [TexAlignment.start] aligns the words at the start of the text | ||
9 | - start, | ||
10 | - | ||
11 | - /// It aligns the words at the end of the text | ||
12 | - end, | ||
13 | - | ||
14 | - /// It aligns the words at the center of the text | ||
15 | - center, | ||
16 | -} | ||
17 | - | ||
18 | /// A LaTex text view. | 7 | /// A LaTex text view. |
19 | /// | 8 | /// |
20 | /// Example: | 9 | /// Example: |
21 | /// ```dart | 10 | /// ```dart |
22 | -/// TexText(r"The equation is <m>x^2+y^2=z^2<m>") //Output: The equation is <LaTex formatted equation> | 11 | +/// TexText(r"The equation is $x^2+y^2=z^2$") //Output: The equation is <LaTex formatted equation> |
23 | /// | 12 | /// |
24 | -/// // <m><m> shows <m> result | ||
25 | -/// TexText(r"The equation is <m><m>") //Output: The equation is <m> | 13 | +/// // \$ shows $ result |
14 | +/// TexText(r"The equation is \$") //Output: The equation is $ | ||
26 | /// ``` | 15 | /// ``` |
27 | class TexText extends StatelessWidget { | 16 | class TexText extends StatelessWidget { |
28 | - const TexText(this.text, | ||
29 | - {super.key, | ||
30 | - TextStyle? style, | ||
31 | - this.mathStyle = MathStyle.text, | ||
32 | - this.alignment = TexAlignment.start}) | ||
33 | - : _style = style; | 17 | + const TexText( |
18 | + this.text, { | ||
19 | + super.key, | ||
20 | + TextStyle? style, | ||
21 | + this.mathStyle = MathStyle.text, | ||
22 | + }) : _style = style; | ||
34 | final String text; | 23 | final String text; |
35 | final TextStyle? _style; | 24 | final TextStyle? _style; |
36 | final MathStyle mathStyle; | 25 | final MathStyle mathStyle; |
37 | - final TexAlignment alignment; | 26 | + // final TexAlignment alignment; |
38 | 27 | ||
39 | /// LaTex to HTML parser | 28 | /// LaTex to HTML parser |
40 | String toHtml() { | 29 | String toHtml() { |
41 | return toHtmlData(text); | 30 | return toHtmlData(text); |
42 | } | 31 | } |
43 | 32 | ||
33 | + /// LaTex custom syntax | ||
44 | static String _newEasySyntax(String data) { | 34 | static String _newEasySyntax(String data) { |
45 | return data | 35 | return data |
46 | .replaceAll(r"\frac", r"\cfrac") | 36 | .replaceAll(r"\frac", r"\cfrac") |
47 | .replaceAll(r"\left[", r"[") | 37 | .replaceAll(r"\left[", r"[") |
48 | .replaceAll(r"\right]", r"]") | 38 | .replaceAll(r"\right]", r"]") |
49 | - .replaceAll(r"[", r"{\left[") | ||
50 | - .replaceAll(r"]", r"\right]}") | 39 | + .replaceAll(r"[", r"{\left[{") |
40 | + .replaceAll(r"]", r"}\right]}") | ||
41 | + .replaceAllMapped( | ||
42 | + RegExp(r'\\sqrt\{\\left\[\{(.*?)\}\\right\]\}'), | ||
43 | + (match) => | ||
44 | + "\\sqrt[${match[1].toString().replaceAll(r"\cfrac", r"\frac")}]", | ||
45 | + ) | ||
51 | .replaceAll(r"\left\{", r"\{") | 46 | .replaceAll(r"\left\{", r"\{") |
52 | .replaceAll(r"\right\}", r"\}") | 47 | .replaceAll(r"\right\}", r"\}") |
53 | - .replaceAll(r"\{", r"{\left\{") | ||
54 | - .replaceAll(r"\}", r"\right\}}") | 48 | + .replaceAll(r"\{", r"{\left\{{") |
49 | + .replaceAll(r"\}", r"}\right\}}") | ||
55 | .replaceAll(r"\left(", r"(") | 50 | .replaceAll(r"\left(", r"(") |
56 | .replaceAll(r"\right)", r")") | 51 | .replaceAll(r"\right)", r")") |
57 | - .replaceAll(r"(", r"{\left(") | ||
58 | - .replaceAll(r")", r"\right)}") | 52 | + .replaceAll(r"(", r"{\left({") |
53 | + .replaceAll(r")", r"}\right)}") | ||
59 | .replaceAll(RegExp(r"\\tf"), r"\therefore") | 54 | .replaceAll(RegExp(r"\\tf"), r"\therefore") |
60 | .replaceAll(RegExp(r"\\bc"), r"\because") | 55 | .replaceAll(RegExp(r"\\bc"), r"\because") |
61 | .replaceAllMapped( | 56 | .replaceAllMapped( |
62 | - RegExp(r"([^A-Za-z]|^)(sin|cos|tan|cosec|sec|cot)([^A-Za-z]|$)"), | ||
63 | - (match) => "{\\${match[2].toString()}}${match[3].toString()}") | 57 | + RegExp(r"([^A-Za-z\\]|^)(sin|cos|tan|cosec|sec|cot)([^A-Za-z]|$)"), |
58 | + (match) => | ||
59 | + "${match[1].toString()}{\\,\\${match[2].toString()}}${match[3].toString()}") | ||
64 | .replaceAll(r"=>", r"{\Rightarrow}") | 60 | .replaceAll(r"=>", r"{\Rightarrow}") |
65 | - .replaceAll(RegExp(r"\\AA(\s|$)"), r"{Å}") | 61 | + .replaceAll(RegExp(r"\\AA(\s|$)"), r"{\text{Å}}") |
66 | .replaceAll(r"*", r"{\times}") | 62 | .replaceAll(r"*", r"{\times}") |
67 | .replaceAllMapped( | 63 | .replaceAllMapped( |
68 | RegExp(r"\\([a-z]?)mat(\s+?\S.*?)\\([a-z]?)mat"), | 64 | RegExp(r"\\([a-z]?)mat(\s+?\S.*?)\\([a-z]?)mat"), |
@@ -89,17 +85,18 @@ class TexText extends StatelessWidget { | @@ -89,17 +85,18 @@ class TexText extends StatelessWidget { | ||
89 | ).trim(); | 85 | ).trim(); |
90 | } | 86 | } |
91 | 87 | ||
88 | + /// Generate spans for widget | ||
92 | Widget _generateWidget(BuildContext context, String e) { | 89 | Widget _generateWidget(BuildContext context, String e) { |
93 | TextStyle? style = _style ?? Theme.of(context).textTheme.bodyMedium; | 90 | TextStyle? style = _style ?? Theme.of(context).textTheme.bodyMedium; |
94 | const dollar = r"\[-~`::36]"; | 91 | const dollar = r"\[-~`::36]"; |
95 | - List<InlineSpan> widgets = []; | 92 | + List<InlineSpan> spans = []; |
96 | 93 | ||
97 | e.replaceAll("\\\$", dollar).splitMapJoin( | 94 | e.replaceAll("\\\$", dollar).splitMapJoin( |
98 | RegExp( | 95 | RegExp( |
99 | r"\$(.*?)\$", | 96 | r"\$(.*?)\$", |
100 | ), | 97 | ), |
101 | onMatch: (p0) { | 98 | onMatch: (p0) { |
102 | - widgets.add( | 99 | + spans.add( |
103 | WidgetSpan( | 100 | WidgetSpan( |
104 | alignment: PlaceholderAlignment.baseline, | 101 | alignment: PlaceholderAlignment.baseline, |
105 | baseline: TextBaseline.alphabetic, | 102 | baseline: TextBaseline.alphabetic, |
@@ -109,7 +106,10 @@ class TexText extends StatelessWidget { | @@ -109,7 +106,10 @@ class TexText extends StatelessWidget { | ||
109 | fontFamily: "SansSerif", | 106 | fontFamily: "SansSerif", |
110 | ), | 107 | ), |
111 | mathStyle: mathStyle, | 108 | mathStyle: mathStyle, |
112 | - textScaleFactor: 1.3, | 109 | + textScaleFactor: 1, |
110 | + settings: const TexParserSettings( | ||
111 | + strict: Strict.ignore, | ||
112 | + ), | ||
113 | options: MathOptions( | 113 | options: MathOptions( |
114 | sizeUnderTextStyle: MathSize.large, | 114 | sizeUnderTextStyle: MathSize.large, |
115 | color: style?.color ?? Theme.of(context).colorScheme.onSurface, | 115 | color: style?.color ?? Theme.of(context).colorScheme.onSurface, |
@@ -118,10 +118,12 @@ class TexText extends StatelessWidget { | @@ -118,10 +118,12 @@ class TexText extends StatelessWidget { | ||
118 | mathFontOptions: FontOptions( | 118 | mathFontOptions: FontOptions( |
119 | fontFamily: "Main", | 119 | fontFamily: "Main", |
120 | fontWeight: style?.fontWeight ?? FontWeight.normal, | 120 | fontWeight: style?.fontWeight ?? FontWeight.normal, |
121 | + fontShape: FontStyle.normal, | ||
121 | ), | 122 | ), |
122 | textFontOptions: FontOptions( | 123 | textFontOptions: FontOptions( |
123 | fontFamily: "Main", | 124 | fontFamily: "Main", |
124 | fontWeight: style?.fontWeight ?? FontWeight.normal, | 125 | fontWeight: style?.fontWeight ?? FontWeight.normal, |
126 | + fontShape: FontStyle.normal, | ||
125 | ), | 127 | ), |
126 | style: mathStyle, | 128 | style: mathStyle, |
127 | ), | 129 | ), |
@@ -139,7 +141,7 @@ class TexText extends StatelessWidget { | @@ -139,7 +141,7 @@ class TexText extends StatelessWidget { | ||
139 | return p0[1].toString(); | 141 | return p0[1].toString(); |
140 | }, | 142 | }, |
141 | onNonMatch: (p0) { | 143 | onNonMatch: (p0) { |
142 | - widgets.add( | 144 | + spans.add( |
143 | TextSpan( | 145 | TextSpan( |
144 | text: p0.toString().replaceAll(dollar, "\$"), | 146 | text: p0.toString().replaceAll(dollar, "\$"), |
145 | style: style, | 147 | style: style, |
@@ -150,9 +152,8 @@ class TexText extends StatelessWidget { | @@ -150,9 +152,8 @@ class TexText extends StatelessWidget { | ||
150 | ); | 152 | ); |
151 | return Text.rich( | 153 | return Text.rich( |
152 | TextSpan( | 154 | TextSpan( |
153 | - children: widgets, | 155 | + children: spans, |
154 | ), | 156 | ), |
155 | - textAlign: TextAlign.values[alignment.index], | ||
156 | ); | 157 | ); |
157 | } | 158 | } |
158 | 159 |
1 | name: tex_text | 1 | name: tex_text |
2 | description: This package for Flutter allows you to show text on a Flutter app with LaTex math formula and normal text from string. It is vary easy to use and works for all of the platforms. | 2 | description: This package for Flutter allows you to show text on a Flutter app with LaTex math formula and normal text from string. It is vary easy to use and works for all of the platforms. |
3 | -version: 0.1.5 | 3 | +version: 0.1.7 |
4 | homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_text | 4 | homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_text |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment