Rendering math or related science symbols in android app is a fully clientside phenomena.
We can accomplish this with the following steps in Android Studio using Java:
1. Include a latex library in your build.gradle file(if you are using android studio).
The latex library I used for this purpose is from katex.
We have to just add the following line inside the dependencies section of the app level build.gradle file:
6. Now render the text containing mathematics(maths) and related science symbols with the following:
mathView.setDisplayText(str); //str contains the string along with or without math/science symbols.
7. Finally add this MathView instance to a layout or other viewgroup.
The below method in java implements the above steps:
private void putMathSymbols(LinearLayout parent,String str, int fsize){
MathView mathView = new MathView(getApplicationContext());
mathView.setTextSize(fsize);
mathView.setViewBackgroundColor(android.R.color.holo_blue_light);
mathView.setTextColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white)); // not essential
mathView.setDisplayText(str);
parent.addView(mathView);
}
INSTRUCTION: The text (str in the above example) that contains maths or related science symbols, must be enclosed by two ‘\$’ signs. i.e. the text should be preceded by a ‘\$’ sign and must be followed by another ‘\$’ sign. To print special characters or symbols we have to put the correct notation preceded with an escape character ‘\’(back slash}.
For example:
"The cube of 5 i.e. \$5^3\$ brings out 125" => this will print: "The cube of 5 i.e. $5^3$ brings out 125".
Example 2:
\$X^2 + Y^2 = Z^2\$ => This will print: $X^2 + Y^2 = Z^2$
Example 3:
\$\sqrt{X^2 + Y^2}\$ => This will print: $\sqrt{X^2+Y^2}$
Example 4:
This is \$\theta$ => This will print: This is θ.