Skip to content

Commit d7550d7

Browse files
committed
Remove official tex support and add note in README for customRender instructions
1 parent 7801392 commit d7550d7

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Add the following to your `pubspec.yaml` file:
107107
| `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| `table`|
108108
| `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | `ul` |
109109
| `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` | `mfrac` |
110-
| `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | `tex` (custom tag for this package) | | | | |
110+
| `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | | |
111111

112112

113113
## Currently Supported CSS Attributes:
@@ -718,11 +718,26 @@ If you'd like to see more MathML features, feel free to create a PR or file a fe
718718

719719
### Tex
720720

721-
If you have a Tex string you'd like to render inside your HTML you can do that!
721+
If you have a Tex string you'd like to render inside your HTML you can do that using the same [`flutter_math`](https://pub.dev/packages/flutter_math) plugin.
722722

723-
Use the custom `<tex>` tag inside your HTML, and place your **raw** Tex string inside. The package uses the same logic as MathML rendering above, but doesn't need to parse the string, of course.
723+
Use a custom tag inside your HTML (an example could be `<tex>`), and place your **raw** Tex string inside.
724724

725-
The rendering error will also be called if your Tex string fails to render.
725+
Then, use the `customRender` parameter to add the widget to render Tex. It could look like this:
726+
727+
```dart
728+
Widget htmlWidget = Html(
729+
data: r"""<tex>i\hbar\frac{\partial}{\partial t}\Psi(\vec x,t) = -\frac{\hbar}{2m}\nabla^2\Psi(\vec x,t)+ V(\vec x)\Psi(\vec x,t)</tex>""",
730+
customRender: {
731+
"tex": (_, __, ___, element) => Math.tex(
732+
element.text,
733+
onErrorFallback: (FlutterMathException e) {
734+
//return your error widget here e.g.
735+
return Text(e.message);
736+
},
737+
),
738+
}
739+
);
740+
```
726741

727742
### Table
728743

lib/src/html_elements.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const REPLACED_ELEMENTS = [
8787
"rt",
8888
"ruby",
8989
"math",
90-
"tex",
9190
];
9291

9392
const LAYOUT_ELEMENTS = [

lib/src/replaced_element.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,17 @@ class MathElement extends ReplacedElement {
275275
MathElement({
276276
required this.element,
277277
this.texStr,
278-
String name = "[[MathElement]]",
278+
String name = "math",
279279
}) : super(name: name, alignment: PlaceholderAlignment.middle, style: Style());
280280

281281
@override
282282
Widget toWidget(RenderContext context) {
283-
if (element.localName == "math") {
284-
texStr = parseMathRecursive(element, r'');
285-
}
283+
texStr = parseMathRecursive(element, r'');
286284
return Container(
287-
width: element.localName == "math" ?
288-
MediaQuery.of(context.buildContext).size.width : null,
285+
width: MediaQuery.of(context.buildContext).size.width,
289286
child: Math.tex(
290287
texStr ?? '',
291-
mathStyle: element.parent!.localName != "body" ? MathStyle.text : MathStyle.display,
288+
mathStyle: MathStyle.display,
292289
textStyle: context.style.generateTextStyle(),
293290
onErrorFallback: (FlutterMathException e) {
294291
if (context.parser.onMathError != null) {
@@ -433,11 +430,6 @@ ReplacedElement parseReplacedElement(
433430
return MathElement(
434431
element: element,
435432
);
436-
case "tex":
437-
return MathElement(
438-
element: element,
439-
texStr: element.text,
440-
);
441433
default:
442434
return EmptyContentElement(name: element.localName == null ? "[[No Name]]" : element.localName!);
443435
}

0 commit comments

Comments
 (0)