flutter_html_latex 0.1.0
flutter_html_latex: ^0.1.0 copied to clipboard
LaTeX support for flutter_widget_from_html_core via math-tex HTML class rendering.
flutter_html_latex #
flutter_html_latex হলো Flutter HTML content এর ভিতরে LaTeX equation render করার একটি production-ready package।
এই package এ:
- Primary renderer:
flutter_math_fork(KaTeX-style, fast, clean layout) - Fallback renderer:
flutter_tex(MathJax-based complex formulas) - User-friendly widget API:
HtmlLatex(...)
কেন এই package? #
অনেক API/CMS এইভাবে equation দেয়:
<span class="math-tex">\(x^2 + 2x + 1\)</span>
flutter_widget_from_html_core একা এটা render করে না।
flutter_html_latex এই gap fill করে এবং customization দেয়।
Renderer Strategy (Important) #
Default behavior এখন:
mathJaxSupported = false(default)- Meaning:
flutter_math_forkকে prefer করবে - Only hard error হলে fallback যাবে
যখন data MathJax generated (যেমন inline aligned, equation) তখন:
mathJaxSupported = trueuse করা recommended- risky pattern হলে আগে থেকেই
flutter_texpath এ যাবে
Demo Images #
Repository demo screenshots:
demos/MathJax-Supported-false.pngdemos/MathJax-Supported-true.png
Quick understanding:
mathJaxSupported: false- KaTeX-style content এর জন্য best quality + alignment
- কিছু MathJax-only pattern problematic হতে পারে
mathJaxSupported: true- MathJax-heavy content safer
- fallback usage বেশি হতে পারে
Installation #
pubspec.yaml এ:
dependencies:
flutter_html_latex: ^1.0.0
Project Setup (Must Read) #
1) main.dart পরিবর্তন #
runApp এর আগে runtime initialize করো:
import 'package:flutter_html_latex/flutter_html_latex.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterHtmlLatexRuntime.ensureInitialized();
runApp(const MyApp());
}
2) AndroidManifest.xml পরিবর্তন #
example/android/app/src/main/AndroidManifest.xml এর <application> tag এ এটা add করা recommended:
<application
android:label="your_app"
android:enableOnBackInvokedCallback="true"
...>
Quick Usage #
HtmlLatex(
htmlData,
style: const TextStyle(
fontSize: 15,
color: Colors.black87,
),
)
HtmlLatex Parameters বিস্তারিত #
HtmlLatex(data, ...) constructor:
-
data(String, required)- HTML string input
-
style(TextStyle?)- default equation style
- color, fontSize, fontFamily, fontWeight, fontStyle, letterSpacing, wordSpacing, decoration map হয়
-
config(LatexHtmlWidgetFactoryConfig?)- low-level advanced config pass করতে
-
customStylesBuilder(Map<String, String>? Function(dynamic)?)- element ভিত্তিক CSS map return
-
customMathBuilder(Widget? Function(String, LatexStyleData)?)- specific formula custom widget দিয়ে override
-
onMathError(Widget? Function(Object, String)?)- render error হলে custom widget
-
enableFallback(bool?)flutter_math_forkerror হলেflutter_texfallback হবে কি না
-
mathJaxSupported(bool?)false: KaTeX-first mode (default behavior)true: MathJax-aware heuristics enabled
-
responsiveLayout(bool?)- wide equation হলে horizontal scroll wrapper
-
fallbackScaleInline(double?)- inline fallback size normalize
-
fallbackScaleBlock(double?)- block fallback size normalize
-
fallbackVerticalPadding(double?)- fallback equation vertical rhythm ঠিক করার জন্য
LatexHtmlWidgetFactoryConfig Parameters #
LatexHtmlWidgetFactoryConfig(...):
baseFontSize(default12.0)defaultColordefaultFontFamilycustomStylesBuildercustomMathBuilderonMathErrorenableFallback(defaulttrue)mathJaxSupported(defaultfalse)responsiveLayout(defaulttrue)fallbackScaleInline(default0.86)fallbackScaleBlock(default0.92)fallbackVerticalPadding(default2.0)hyphenationCharacter(default soft-hyphen)
Recommended Presets #
Preset A: KaTeX-first (recommended default) #
HtmlLatex(
data,
mathJaxSupported: false,
enableFallback: true,
)
Use when:
- তোমার data mostly KaTeX compatible
- তুমি
flutter_math_forkquality/performance maximize করতে চাও
Preset B: MathJax-heavy content #
HtmlLatex(
data,
mathJaxSupported: true,
enableFallback: true,
fallbackScaleInline: 0.84,
fallbackScaleBlock: 0.90,
fallbackVerticalPadding: 1.5,
)
Use when:
- data-তে
aligned,equationইত্যাদি frequent - freeze/crash-risk formulas safely render করতে চাও
Supported HTML Targets #
Package এই pattern detect করে:
<span class="math-tex">\( ... \)</span>
<span class="math-display">\[ ... \]</span>
<span class="math-inline">\( ... \)</span>
<math>\( ... \)</math>
Supported Delimiters #
\(...\)\[...\]$...$$$...$$
Troubleshooting #
-
Equation freeze/crash in debug
mathJaxSupported: trueকরে দেখোenableFallback: trueআছে কিনা নিশ্চিত করো
-
Fallback equation size mismatch
fallbackScaleInline,fallbackScaleBlock,fallbackVerticalPaddingtune করো
-
Formula not rendering
- delimiter syntax check করো
- malformed LaTeX কিনা check করো
Example Toggle (from example app) #
const kMathJaxSupported = true; // false / true switch
HtmlLatex(
item.explanation,
mathJaxSupported: kMathJaxSupported,
style: const TextStyle(fontSize: 15, color: Colors.black87),
fallbackScaleInline: 0.84,
fallbackScaleBlock: 0.90,
fallbackVerticalPadding: 1.5,
)
License #
MIT License. See LICENSE.