Skip to content

Commit 6a81f57

Browse files
committed
fix latex rendering to flutter_math
1 parent 72d8849 commit 6a81f57

File tree

5 files changed

+95
-185
lines changed

5 files changed

+95
-185
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [0.1.13] - 20th Nov 2020:
2+
- Switch latex rendering to flutter_math
3+
14
## [0.1.12] - 20th Nov 2020:
25
- Fix Latex widget crashing sometimes
36

lib/custom_catex.dart

Lines changed: 0 additions & 173 deletions
This file was deleted.

lib/rich_text_parser.dart

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import 'package:html/parser.dart' as parser;
44
import 'package:cached_network_image/cached_network_image.dart';
55
import 'package:flutter/foundation.dart';
66
import 'package:matrix_link_text/link_text.dart';
7-
import 'custom_catex.dart';
87
import 'code_block.dart';
98
import 'package:flutter_highlight/themes/monokai.dart';
9+
import 'package:flutter_math/flutter_math.dart';
1010

1111
import 'image_properties.dart';
1212
import 'spoiler.dart';
@@ -804,7 +804,16 @@ class HtmlRichTextParser extends StatelessWidget {
804804
// do we have latex stuffs?
805805
if (node.attributes['data-mx-maths'] != null) {
806806
parseContext.addWidget(WidgetSpan(
807-
child: CustomCaTeX(node.attributes['data-mx-maths']),
807+
child: SingleChildScrollView(
808+
child: Math.tex(
809+
node.attributes['data-mx-maths'],
810+
onErrorFallback: (_) =>
811+
Text(node.attributes['data-mx-maths']),
812+
textStyle: parseContext.childStyle,
813+
mathStyle: MathStyle.text,
814+
),
815+
scrollDirection: Axis.horizontal,
816+
),
808817
alignment: PlaceholderAlignment.middle,
809818
));
810819
return; // we don't want to render the children (which is a fallback)
@@ -1213,8 +1222,16 @@ class HtmlRichTextParser extends StatelessWidget {
12131222

12141223
case "div":
12151224
if (node.attributes['data-mx-maths'] != null) {
1216-
parseContext.rootWidgetList
1217-
.add(CustomCaTeX(node.attributes['data-mx-maths']));
1225+
parseContext.rootWidgetList.add(SingleChildScrollView(
1226+
child: Math.tex(
1227+
node.attributes['data-mx-maths'],
1228+
onErrorFallback: (_) =>
1229+
Text(node.attributes['data-mx-maths']),
1230+
textStyle: parseContext.childStyle,
1231+
mathStyle: MathStyle.display,
1232+
),
1233+
scrollDirection: Axis.horizontal,
1234+
));
12181235
return;
12191236
}
12201237
continue myDefault;

pubspec.lock

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ packages:
2222
url: "https://pub.dartlang.org"
2323
source: hosted
2424
version: "2.3.1"
25-
catex:
26-
dependency: "direct main"
27-
description:
28-
name: catex
29-
url: "https://pub.dartlang.org"
30-
source: hosted
31-
version: "0.0.1+6"
3225
characters:
3326
dependency: transitive
3427
description:
@@ -118,6 +111,20 @@ packages:
118111
url: "https://pub.dartlang.org"
119112
source: hosted
120113
version: "0.6.0"
114+
flutter_math:
115+
dependency: "direct main"
116+
description:
117+
name: flutter_math
118+
url: "https://pub.dartlang.org"
119+
source: hosted
120+
version: "0.2.0+2"
121+
flutter_svg:
122+
dependency: transitive
123+
description:
124+
name: flutter_svg
125+
url: "https://pub.dartlang.org"
126+
source: hosted
127+
version: "0.19.1"
121128
flutter_test:
122129
dependency: "direct dev"
123130
description: flutter
@@ -191,6 +198,13 @@ packages:
191198
url: "https://pub.dartlang.org"
192199
source: hosted
193200
version: "1.3.0-nullsafety.3"
201+
nested:
202+
dependency: transitive
203+
description:
204+
name: nested
205+
url: "https://pub.dartlang.org"
206+
source: hosted
207+
version: "0.0.4"
194208
octo_image:
195209
dependency: transitive
196210
description:
@@ -205,6 +219,20 @@ packages:
205219
url: "https://pub.dartlang.org"
206220
source: hosted
207221
version: "1.8.0-nullsafety.1"
222+
path_drawing:
223+
dependency: transitive
224+
description:
225+
name: path_drawing
226+
url: "https://pub.dartlang.org"
227+
source: hosted
228+
version: "0.4.1+1"
229+
path_parsing:
230+
dependency: transitive
231+
description:
232+
name: path_parsing
233+
url: "https://pub.dartlang.org"
234+
source: hosted
235+
version: "0.1.4"
208236
path_provider:
209237
dependency: transitive
210238
description:
@@ -240,6 +268,13 @@ packages:
240268
url: "https://pub.dartlang.org"
241269
source: hosted
242270
version: "1.9.0"
271+
petitparser:
272+
dependency: transitive
273+
description:
274+
name: petitparser
275+
url: "https://pub.dartlang.org"
276+
source: hosted
277+
version: "3.1.0"
243278
platform:
244279
dependency: transitive
245280
description:
@@ -268,13 +303,27 @@ packages:
268303
url: "https://pub.dartlang.org"
269304
source: hosted
270305
version: "3.0.13"
306+
provider:
307+
dependency: transitive
308+
description:
309+
name: provider
310+
url: "https://pub.dartlang.org"
311+
source: hosted
312+
version: "4.3.2+2"
271313
pub_semver:
272314
dependency: transitive
273315
description:
274316
name: pub_semver
275317
url: "https://pub.dartlang.org"
276318
source: hosted
277319
version: "1.4.4"
320+
quiver:
321+
dependency: transitive
322+
description:
323+
name: quiver
324+
url: "https://pub.dartlang.org"
325+
source: hosted
326+
version: "2.1.5"
278327
rxdart:
279328
dependency: transitive
280329
description:
@@ -350,6 +399,13 @@ packages:
350399
url: "https://pub.dartlang.org"
351400
source: hosted
352401
version: "0.2.19-nullsafety.2"
402+
tuple:
403+
dependency: transitive
404+
description:
405+
name: tuple
406+
url: "https://pub.dartlang.org"
407+
source: hosted
408+
version: "1.0.3"
353409
typed_data:
354410
dependency: transitive
355411
description:
@@ -420,6 +476,13 @@ packages:
420476
url: "https://pub.dartlang.org"
421477
source: hosted
422478
version: "0.1.0"
479+
xml:
480+
dependency: transitive
481+
description:
482+
name: xml
483+
url: "https://pub.dartlang.org"
484+
source: hosted
485+
version: "4.5.1"
423486
sdks:
424487
dart: ">=2.10.0-110 <=2.11.0-161.0.dev"
425488
flutter: ">=1.20.0 <2.0.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
sdk: flutter
1414
cached_network_image: any
1515
matrix_link_text: any
16-
catex: ^0.0.1+6
16+
flutter_math: ^0.2.0+2
1717
flutter_highlight: ^0.6.0
1818
isolate: ^2.0.3
1919
highlight: ^0.6.0

0 commit comments

Comments
 (0)