Skip to content

Commit b08d78c

Browse files
authored
Merge pull request #16 from foresightmobile/feature/latex-implementation
Markdown Latex Implementation
2 parents 9c8b45f + 26a1277 commit b08d78c

File tree

6 files changed

+234
-12
lines changed

6 files changed

+234
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
lib/generated_plugin_registrant.dart
3535

3636
# Exceptions to above rules.
37-
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
37+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
38+
example/android/app/.cxx/Debug
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// TODO(goderbauer): Restructure the examples to avoid this ignore, https://github.com/flutter/flutter/issues/110208.
6+
// ignore_for_file: avoid_implementing_value_types
7+
8+
import 'package:flutter/material.dart';
9+
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
10+
import 'package:flutter_markdown_plus_latex/flutter_markdown_plus_latex.dart';
11+
import 'package:markdown/markdown.dart' as md;
12+
13+
import '../shared/markdown_demo_widget.dart';
14+
15+
// ignore_for_file: public_member_api_docs
16+
17+
const String _markdownData = r"""
18+
This is inline latex: $f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}$
19+
20+
This is block level latex:
21+
22+
$$
23+
c = \pm\sqrt{a^2 + b^2}
24+
$$
25+
26+
This is inline latex with displayMode: $$f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}$$ and here is a very long text that should be in the same line.
27+
28+
The relationship between the height and the side length of an equilateral triangle is:
29+
30+
\[ \text{Height} = \frac{\sqrt{3}}{2} \times \text{Side Length} \]
31+
32+
\[ \text{X} = \frac{1}{2} \times \text{Y} \times \text{Z} = \frac{1}{2} \times 9 \times \frac{\sqrt{3}}{2} \times 9 = \frac{81\sqrt{3}}{4} \]
33+
34+
The basic form of the Taylor series is:
35+
36+
\[f(x) = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3 + \cdots\]
37+
38+
where \(f(x)\) is the function to be expanded, \(a\) is the expansion point, \(f'(a)\), \(f''(a)\), \(f'''(a)\), etc., are the first, second, third, and so on derivatives of the function at point \(a\), and \(n!\) denotes the factorial of \(n\).
39+
40+
In particular, when \(a=0\), this expansion is called the Maclaurin series.
41+
42+
""";
43+
44+
const String _notes = '''
45+
# Latex & ChatGPT Response Demo
46+
---
47+
48+
## Overview
49+
50+
...
51+
''';
52+
53+
class MarkdownLatexPluginDemo extends StatelessWidget implements MarkdownDemoWidget {
54+
const MarkdownLatexPluginDemo({super.key});
55+
56+
static const String _title = 'Latex & ChatGPT Response Demo';
57+
58+
@override
59+
String get title => MarkdownLatexPluginDemo._title;
60+
61+
@override
62+
String get description => 'Shows the functionality of the LaTeX plugin with a ChatGPT response.';
63+
64+
@override
65+
Future<String> get data => Future<String>.value(_markdownData);
66+
67+
@override
68+
Future<String> get notes => Future<String>.value(_notes);
69+
70+
static LatexElementBuilder builder = LatexElementBuilder();
71+
72+
@override
73+
Widget build(BuildContext context) {
74+
return Scaffold(
75+
body: SafeArea(
76+
child: Markdown(
77+
data: _markdownData,
78+
selectable: true,
79+
builders: <String, MarkdownElementBuilder>{'latex': builder},
80+
extensionSet: md.ExtensionSet(
81+
<md.BlockSyntax>[LatexBlockSyntax()],
82+
<md.InlineSyntax>[LatexInlineSyntax()],
83+
),
84+
),
85+
),
86+
);
87+
}
88+
}

example/lib/screens/home_screen.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../demos/centered_header_demo.dart';
88
import '../demos/custom_bullet_list_demo.dart';
99
import '../demos/extended_emoji_demo.dart';
1010
import '../demos/markdown_body_shrink_wrap_demo.dart';
11+
import '../demos/markdown_latex_plugin_demo.dart';
1112
import '../demos/minimal_markdown_demo.dart';
1213
import '../demos/original_demo.dart';
1314
import '../demos/subscript_syntax_demo.dart';
@@ -32,6 +33,7 @@ class HomeScreen extends StatelessWidget {
3233
const CenteredHeaderDemo(),
3334
const MarkdownBodyShrinkWrapDemo(),
3435
const CustomBulletListDemo(),
36+
const MarkdownLatexPluginDemo(),
3537
];
3638

3739
@override

example/pubspec.lock

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,56 @@ packages:
6565
flutter_markdown_plus:
6666
dependency: "direct main"
6767
description:
68-
path: ".."
69-
relative: true
70-
source: path
68+
name: flutter_markdown_plus
69+
sha256: "20bcb404e5ba9bc949320b6b314f2bf6a60df048106f1bc09c8310086eac004b"
70+
url: "https://pub.dev"
71+
source: hosted
7172
version: "1.0.2"
73+
flutter_markdown_plus_latex:
74+
dependency: "direct main"
75+
description:
76+
name: flutter_markdown_plus_latex
77+
sha256: "39ed8ddccc7e3e71bf812e74ca4541c4aa994e47dbc6c265acb49f42728721f1"
78+
url: "https://pub.dev"
79+
source: hosted
80+
version: "1.0.0"
81+
flutter_math_fork:
82+
dependency: transitive
83+
description:
84+
name: flutter_math_fork
85+
sha256: "284bab89b2fbf1bc3a0baf13d011c1dd324d004e35d177626b77f2fc056366ac"
86+
url: "https://pub.dev"
87+
source: hosted
88+
version: "0.7.3"
89+
flutter_svg:
90+
dependency: transitive
91+
description:
92+
name: flutter_svg
93+
sha256: c200fd79c918a40c5cd50ea0877fa13f81bdaf6f0a5d3dbcc2a13e3285d6aa1b
94+
url: "https://pub.dev"
95+
source: hosted
96+
version: "2.0.17"
7297
flutter_test:
7398
dependency: "direct dev"
7499
description: flutter
75100
source: sdk
76101
version: "0.0.0"
102+
http:
103+
dependency: transitive
104+
description:
105+
name: http
106+
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
107+
url: "https://pub.dev"
108+
source: hosted
109+
version: "1.3.0"
110+
http_parser:
111+
dependency: transitive
112+
description:
113+
name: http_parser
114+
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
115+
url: "https://pub.dev"
116+
source: hosted
117+
version: "4.1.2"
77118
leak_tracker:
78119
dependency: transitive
79120
description:
@@ -130,6 +171,14 @@ packages:
130171
url: "https://pub.dev"
131172
source: hosted
132173
version: "1.15.0"
174+
nested:
175+
dependency: transitive
176+
description:
177+
name: nested
178+
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
179+
url: "https://pub.dev"
180+
source: hosted
181+
version: "1.0.0"
133182
path:
134183
dependency: transitive
135184
description:
@@ -138,6 +187,30 @@ packages:
138187
url: "https://pub.dev"
139188
source: hosted
140189
version: "1.9.0"
190+
path_parsing:
191+
dependency: transitive
192+
description:
193+
name: path_parsing
194+
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
195+
url: "https://pub.dev"
196+
source: hosted
197+
version: "1.1.0"
198+
petitparser:
199+
dependency: transitive
200+
description:
201+
name: petitparser
202+
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
203+
url: "https://pub.dev"
204+
source: hosted
205+
version: "6.0.2"
206+
provider:
207+
dependency: transitive
208+
description:
209+
name: provider
210+
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
211+
url: "https://pub.dev"
212+
source: hosted
213+
version: "6.1.2"
141214
sky_engine:
142215
dependency: transitive
143216
description: flutter
@@ -191,6 +264,46 @@ packages:
191264
url: "https://pub.dev"
192265
source: hosted
193266
version: "0.7.3"
267+
tuple:
268+
dependency: transitive
269+
description:
270+
name: tuple
271+
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
272+
url: "https://pub.dev"
273+
source: hosted
274+
version: "2.0.2"
275+
typed_data:
276+
dependency: transitive
277+
description:
278+
name: typed_data
279+
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
280+
url: "https://pub.dev"
281+
source: hosted
282+
version: "1.4.0"
283+
vector_graphics:
284+
dependency: transitive
285+
description:
286+
name: vector_graphics
287+
sha256: "44cc7104ff32563122a929e4620cf3efd584194eec6d1d913eb5ba593dbcf6de"
288+
url: "https://pub.dev"
289+
source: hosted
290+
version: "1.1.18"
291+
vector_graphics_codec:
292+
dependency: transitive
293+
description:
294+
name: vector_graphics_codec
295+
sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146"
296+
url: "https://pub.dev"
297+
source: hosted
298+
version: "1.1.13"
299+
vector_graphics_compiler:
300+
dependency: transitive
301+
description:
302+
name: vector_graphics_compiler
303+
sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad"
304+
url: "https://pub.dev"
305+
source: hosted
306+
version: "1.1.16"
194307
vector_math:
195308
dependency: transitive
196309
description:
@@ -207,6 +320,22 @@ packages:
207320
url: "https://pub.dev"
208321
source: hosted
209322
version: "14.3.0"
323+
web:
324+
dependency: transitive
325+
description:
326+
name: web
327+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
328+
url: "https://pub.dev"
329+
source: hosted
330+
version: "1.1.1"
331+
xml:
332+
dependency: transitive
333+
description:
334+
name: xml
335+
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
336+
url: "https://pub.dev"
337+
source: hosted
338+
version: "6.5.0"
210339
sdks:
211-
dart: ">=3.4.0 <4.0.0"
340+
dart: ">=3.5.0 <4.0.0"
212341
flutter: ">=3.27.1"

example/pubspec.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
flutter_markdown_plus:
13-
path: ../
14-
markdown: ^7.0.0
12+
13+
flutter_markdown_plus: ^1.0.2
14+
flutter_markdown_plus_latex: ^1.0.0
15+
markdown: ^7.3.0
16+
1517

1618
dev_dependencies:
1719
flutter_test:

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
44
formatted with simple Markdown tags.
55
repository: https://github.com/foresightmobile/flutter_markdown_plus
66
issue_tracker: https://github.com/foresightmobile/flutter_markdown_plus/issues
7-
version: 1.0.2
7+
version: 1.0.3
88

99
environment:
1010
sdk: ^3.4.0
@@ -13,9 +13,9 @@ environment:
1313
dependencies:
1414
flutter:
1515
sdk: flutter
16-
markdown: ^7.1.1
17-
meta: ^1.3.0
18-
path: ^1.8.0
16+
markdown: ^7.3.0
17+
meta: ^1.15.0
18+
path: ^1.9.0
1919

2020
dev_dependencies:
2121
flutter_test:

0 commit comments

Comments
 (0)