stack ex
stack ex

Reputation: 111

Display a string variable in LaTeX using flutter_tex package (Dart)

I want to display math equations dynamically: enter image description here

Here is the successful output of a LaTeX equation:

output.add(
    TeXViewDocument(
      r"""<p> When \(a \ne 0 \), there are two solutions to \(x^2 + bx + c = 0\) </p>""",
      style: TeXViewStyle.fromCSS(
        'padding: 15px; color: black; background: white',
      ),
    ),
  );

When I try to pass the String variable "formula" in LaTeX, I can't get it to render:

String a = '10';
String formula = ' \(' + a + 'x^2\)';
output.add(
  TeXViewDocument(
    formula,
    style: TeXViewStyle.fromCSS(
      'padding: 15px; color: black; background: white',
    ),
  ),
);

How can I get my string variables to be rendered to LaTeX? I have tried using jsonEncode() or some other tricks to work with a raw string but nothing has worked. I checked the flutter_tex documentation but there are no examples passing variables for LaTeX output.

Upvotes: 1

Views: 864

Answers (1)

Eugene Kuzmenko
Eugene Kuzmenko

Reputation: 1507

Did you try something like this?

String a = '10';
String formula = "\\(${a}x^2\\)";

Upvotes: 4

Related Questions