saminsohag

.$ syntex added with a gard condition for \(_\)

@@ -136,4 +136,4 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -136,4 +136,4 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
136 136
137 ## Additional information 137 ## Additional information
138 138
139 -You can find the source code [here.](https://github.com/saminsohag/flutter_packages/tree/main/gpt_markdown) 139 +You can find the source code [here.](https://github.com/saminsohag/flutter_packages/tree/main/gpt_markdown)
@@ -161,7 +161,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -161,7 +161,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
161 }, 161 },
162 textAlign: TextAlign.justify, 162 textAlign: TextAlign.justify,
163 // textScaler: const TextScaler.linear(1.3), 163 // textScaler: const TextScaler.linear(1.3),
164 - textScaleFactor: 1.7, 164 + textScaleFactor: 1,
165 style: const TextStyle( 165 style: const TextStyle(
166 // Regular text font size here. 166 // Regular text font size here.
167 fontSize: 15, 167 fontSize: 15,
@@ -30,9 +30,29 @@ class TexMarkdown extends StatelessWidget { @@ -30,9 +30,29 @@ class TexMarkdown extends StatelessWidget {
30 30
31 @override 31 @override
32 Widget build(BuildContext context) { 32 Widget build(BuildContext context) {
  33 + String tex = data.trim();
  34 + if (!tex.contains(r"\(")) {
  35 + tex = tex
  36 + .replaceAllMapped(
  37 + RegExp(
  38 + r"(?<!\\)\$\$(.*?)(?<!\\)\$\$",
  39 + ),
  40 + (match) => "\\[${match[1] ?? ""}\\]")
  41 + .replaceAllMapped(
  42 + RegExp(
  43 + r"(?<!\\)\$(.*?)(?<!\\)\$",
  44 + ),
  45 + (match) => "\\(${match[1] ?? ""}\\)");
  46 + tex = tex.splitMapJoin(
  47 + RegExp(r"\[.*?\]|\(.*?\)"),
  48 + onNonMatch: (p0) {
  49 + return p0.replaceAll("\\\$", "\$");
  50 + },
  51 + );
  52 + }
33 return ClipRRect( 53 return ClipRRect(
34 child: MdWidget( 54 child: MdWidget(
35 - data.trim(), 55 + tex,
36 textDirection: textDirection, 56 textDirection: textDirection,
37 style: style, 57 style: style,
38 onLinkTab: onLinkTab, 58 onLinkTab: onLinkTab,