Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
gpt_markdown
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
saminsohag
2023-04-07 22:24:56 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5b813959cd684f85be3c65cfec9a076c795fac75
5b813959
1 parent
8be35f2a
bug fixed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
42 deletions
tex_text/CHANGELOG.md
tex_text/example/lib/main.dart
tex_text/example/pubspec.lock
tex_text/lib/tex_text.dart
tex_text/pubspec.yaml
tex_text/CHANGELOG.md
View file @
5b81395
## 0.1.7
*
Bug fixed.
## 0.1.6
*
Bug fixed.
## 0.1.5
*
New shortcut added.
...
...
tex_text/example/lib/main.dart
View file @
5b81395
...
...
@@ -39,13 +39,12 @@ class _MyAppState extends State<MyApp> {
child:
TexText
(
// TexText.newEasySyntax(_text.text),
_text
.
text
,
alignment:
TexAlignment
.
start
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlin
eLarge
.
titl
eLarge
?.
copyWith
(
// color: Colors.red,
),
color:
Colors
.
blue
,
),
mathStyle:
MathStyle
.
displayCramped
,
),
);
...
...
tex_text/example/pubspec.lock
View file @
5b81395
...
...
@@ -238,7 +238,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.
5
"
version: "0.1.
7
"
tuple:
dependency: transitive
description:
...
...
tex_text/lib/tex_text.dart
View file @
5b81395
...
...
@@ -4,65 +4,61 @@ import 'package:flutter/material.dart';
import
'package:flutter_math_fork/flutter_math.dart'
;
export
'package:flutter_math_fork/flutter_math.dart'
;
enum
TexAlignment
{
/// [TexAlignment.start] aligns the words at the start of the text
start
,
/// It aligns the words at the end of the text
end
,
/// It aligns the words at the center of the text
center
,
}
/// A LaTex text view.
///
/// Example:
/// ```dart
/// TexText(r"The equation is
<m>x^2+y^2=z^2<m>
") //Output: The equation is <LaTex formatted equation>
/// TexText(r"The equation is
$x^2+y^2=z^2$
") //Output: The equation is <LaTex formatted equation>
///
/// // <m><m> shows <m> result
/// TexText(r"The equation is <m><m>") //Output: The equation is <m>
/// // \$ shows $ result
/// TexText(r"The equation is \$") //Output: The equation is $
/// ```
class
TexText
extends
StatelessWidget
{
const
TexText
(
this
.
text
,
{
super
.
key
,
TextStyle
?
style
,
this
.
mathStyle
=
MathStyle
.
text
,
this
.
alignment
=
TexAlignment
.
start
})
:
_style
=
style
;
const
TexText
(
this
.
text
,
{
super
.
key
,
TextStyle
?
style
,
this
.
mathStyle
=
MathStyle
.
text
,
})
:
_style
=
style
;
final
String
text
;
final
TextStyle
?
_style
;
final
MathStyle
mathStyle
;
final
TexAlignment
alignment
;
//
final TexAlignment alignment;
/// LaTex to HTML parser
String
toHtml
()
{
return
toHtmlData
(
text
);
}
/// LaTex custom syntax
static
String
_newEasySyntax
(
String
data
)
{
return
data
.
replaceAll
(
r"\frac"
,
r"\cfrac"
)
.
replaceAll
(
r"\left["
,
r"["
)
.
replaceAll
(
r"\right]"
,
r"]"
)
.
replaceAll
(
r"["
,
r"{\left["
)
.
replaceAll
(
r"]"
,
r"\right]}"
)
.
replaceAll
(
r"["
,
r"{\left[{"
)
.
replaceAll
(
r"]"
,
r"}\right]}"
)
.
replaceAllMapped
(
RegExp
(
r'\\sqrt\{\\left\[\{(.*?)\}\\right\]\}'
),
(
match
)
=>
"
\\
sqrt[
${match[1].toString().replaceAll(r"\cfrac", r"\frac")}
]"
,
)
.
replaceAll
(
r"\left\{"
,
r"\{"
)
.
replaceAll
(
r"\right\}"
,
r"\}"
)
.
replaceAll
(
r"\{"
,
r"{\left\{"
)
.
replaceAll
(
r"\}"
,
r"\right\}}"
)
.
replaceAll
(
r"\{"
,
r"{\left\{{"
)
.
replaceAll
(
r"\}"
,
r"}\right\}}"
)
.
replaceAll
(
r"\left("
,
r"("
)
.
replaceAll
(
r"\right)"
,
r")"
)
.
replaceAll
(
r"("
,
r"{\left("
)
.
replaceAll
(
r")"
,
r"\right)}"
)
.
replaceAll
(
r"("
,
r"{\left({"
)
.
replaceAll
(
r")"
,
r"}\right)}"
)
.
replaceAll
(
RegExp
(
r"\\tf"
),
r"\therefore"
)
.
replaceAll
(
RegExp
(
r"\\bc"
),
r"\because"
)
.
replaceAllMapped
(
RegExp
(
r"([^A-Za-z]|^)(sin|cos|tan|cosec|sec|cot)([^A-Za-z]|$)"
),
(
match
)
=>
"{
\\
${match[2].toString()}
}
${match[3].toString()}
"
)
RegExp
(
r"([^A-Za-z\\]|^)(sin|cos|tan|cosec|sec|cot)([^A-Za-z]|$)"
),
(
match
)
=>
"
${match[1].toString()}
{
\\
,
\\
${match[2].toString()}
}
${match[3].toString()}
"
)
.
replaceAll
(
r"=>"
,
r"{\Rightarrow}"
)
.
replaceAll
(
RegExp
(
r"\\AA(\s|$)"
),
r"{
Å
}"
)
.
replaceAll
(
RegExp
(
r"\\AA(\s|$)"
),
r"{
\text{Å}
}"
)
.
replaceAll
(
r"*"
,
r"{\times}"
)
.
replaceAllMapped
(
RegExp
(
r"\\([a-z]?)mat(\s+?\S.*?)\\([a-z]?)mat"
),
...
...
@@ -89,17 +85,18 @@ class TexText extends StatelessWidget {
).trim();
}
/// Generate spans for widget
Widget _generateWidget(BuildContext context, String e) {
TextStyle? style = _style ?? Theme.of(context).textTheme.bodyMedium;
const dollar = r"
\
[-~
`
::
36
]
";
List<InlineSpan>
widget
s = [];
List<InlineSpan>
span
s = [];
e.replaceAll("
\\\$
", dollar).splitMapJoin(
RegExp(
r"
\$
(.*?)
\$
",
),
onMatch: (p0) {
widget
s.add(
span
s.add(
WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
...
...
@@ -109,7 +106,10 @@ class TexText extends StatelessWidget {
fontFamily: "
SansSerif
",
),
mathStyle: mathStyle,
textScaleFactor: 1.3,
textScaleFactor: 1,
settings: const TexParserSettings(
strict: Strict.ignore,
),
options: MathOptions(
sizeUnderTextStyle: MathSize.large,
color: style?.color ?? Theme.of(context).colorScheme.onSurface,
...
...
@@ -118,10 +118,12 @@ class TexText extends StatelessWidget {
mathFontOptions: FontOptions(
fontFamily: "
Main
",
fontWeight: style?.fontWeight ?? FontWeight.normal,
fontShape: FontStyle.normal,
),
textFontOptions: FontOptions(
fontFamily: "
Main
",
fontWeight: style?.fontWeight ?? FontWeight.normal,
fontShape: FontStyle.normal,
),
style: mathStyle,
),
...
...
@@ -139,7 +141,7 @@ class TexText extends StatelessWidget {
return p0[1].toString();
},
onNonMatch: (p0) {
widget
s.add(
span
s.add(
TextSpan(
text: p0.toString().replaceAll(dollar, "
\$
"),
style: style,
...
...
@@ -150,9 +152,8 @@ class TexText extends StatelessWidget {
);
return Text.rich(
TextSpan(
children:
widget
s,
children:
span
s,
),
textAlign: TextAlign.values[alignment.index],
);
}
...
...
tex_text/pubspec.yaml
View file @
5b81395
name
:
tex_text
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.
version
:
0.1.
5
version
:
0.1.
7
homepage
:
https://github.com/saminsohag/flutter_packages/tree/main/tex_text
environment
:
...
...
Please
register
or
login
to post a comment