Home > Back-end >  flutter TexView - Insert values to raw strings
flutter TexView - Insert values to raw strings

Time:10-19

I'm trying to get the flutter package flutter_tex result

I also tried the $-operator before the variable like in a dart string, but because a raw string is needed, this doesn't work. Is there a way to implement variable values in a raw string with this package?

CodePudding user response:

It is not strictly necessary to use a raw string. Doing so just makes it more convenient to type all the back slashs and brackets required in LaTeX code.

You could always work with regular string, this just makes it more incovenient to produce correct LaTeX. Instead, I would suggest manually replacing the placeholder:

int number = 42;
String latex = r"<br> $$x={\sqrt{factorB}}$$";
latex = latex.replaceAll("factorB", number.toString());

If you would like to support more advanced interpolation via expressions, I would recommend placing all of that logic inside the replace method. This here is an example

int factorB = 17;
int factorB = 1;    
String latex = r"exprA(x${exprB}$exprC)²exprD";
latex = latex.replaceAll("exprA", 42);
latex = latex.replaceAll("exprB", factorB >= 0 ? " " : "");
latex = latex.replaceAll("exprC", factorC >= 0 ? " " : "");
latex = latex.replaceAll("exprD", 33);
  • Related