Skip to content

_RenderLayoutBuilderPreserveBaseline receives infinite constraints when rendering LaTeX with \frac and \sqrt #120

@module171

Description

@module171

When rendering certain LaTeX formulas that include both \frac and \sqrt inside a layout with unbounded constraints (e.g., inside a Column or ListView without size limits), the widget throws an exception during layout:

_RenderLayoutBuilderPreserveBaseline object was given an infinite size during layout.
The exact size it was given was: Size(Infinity, Infinity)

The issue seems to originate from the LayoutBuilderPreserveBaseline in
lib/src/ast/nodes/sqrt.dart:68 and also occurs with fractions rendered via _FracPos.
This happens because the widget is given unconstrained height and width from its parent layout, which causes the render object to fail when calculating size.

import 'package:flutter/material.dart';
import 'package:flutter_math_fork/flutter_math.dart';

class TestMathError extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Column( // Unbounded height for children
children: [
Math.tex(r"\frac{1}{2} + \sqrt{21}"),
],
),
);
}
}
Expected behavior:
The widget should either:

Render the formula without throwing, by constraining itself to the available space, or

Throw a more informative error suggesting a wrapper (e.g., SizedBox, ConstrainedBox).

Actual behavior:
It throws during performLayout because it receives Size(Infinity, Infinity).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions