Closed sadqiang closed 5 years ago
You can use TextPainter/TextView. They are only on SkiaSharp/Xamarin.Forms right now, and here is some sample code: For SkiaSharp:
var painter = new CSharpMath.SkiaSharp.TextPainter
{
Text = @"Some Text $\frac23-5$ Auto line breaks $$\int^4_3$$ Some Text",
HighlightColor = SkiaSharp.SKColors.LightBlue
};
using (var surface = SkiaSharp.SKSurface.Create(new SkiaSharp.SKImageInfo(200, 200))) {
painter.Draw(surface.Canvas);
using (var snapshot = surface.Snapshot())
using (var pngData = snapshot.Encode())
using (var png = pngData.AsStream())
using (var file = System.IO.File.OpenWrite(@"C:\Some\Path\Output.png")) //replace path
png.CopyTo(file);
}
For Xamarin.Forms:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:math="clr-namespace:CSharpMath.Forms;assembly=CSharpMath.Forms"
x:Class="CSharpMathTextPainterDemo.Forms.MainPage"> <!-- Replace namespace -->
<math:TextView LaTeX="Text $3+4+5+6\cdot7^{5x^2}+a_n$ More text $$\int^5_2x^3+x^2-x-3dx$$ Text"/>
</ContentPage>
You can also use text commands such as \par
and accent commands. Besides $
and $$
shown above, you can also use \(
, \)
, \[
and \]
if you prefer the LaTeX-style commands instead of TeX ones.
@Happypig375 : Thank you very much. It is extremely interesting. Do you have a plan to accommodate Asymptote as well so we can draw mathematical diagrams without hustle ? 🥇
Thank you very much. It is extremely interesting.
Thanks for checking CSharpMath out, too!
Asymptote
I don't understand it. The only definition of an "Asymptote" is geometrical, which doesn't make sense in this sentence.
so we can draw mathematical diagrams without hustle
If you mean "plotting" by "draw mathematical diagrams", then I'd use Oxyplot if I were you.
🥇
Okay... Guess I'll take it. Thanks, I guess.
Thank you for replying. Here is the good link to know about Asymptote. It is often used in mathematical-oriented web sites. We can enter asymptote code (looks like C++) to input geometrical diagrams.
By the way, I will explore the CSharpMath wether or not it fits to my requirement.
At the bottom of the webpage...
Codes under the terms of the GNU LGPL.
Looks like it has a copyleft license, which I don't like.
Actually, you'd be much, much, much, ..., much better off using SkiaSharp as a drawing library directly. Not only because it supports C# directly and is backed by Xamarin (and by extension, Microsoft), but it covers the same area as Asymptote - a graphics library. There would be no point in porting Asymptote only to compete with SkiaSharp.
Anyways, question answered and accepted. Closing.
Sorry. Does SkiaSharp have 3D rendering capabilities?
For 3D drawing instead of 2D, please see UrhoSharp which is another Xamarin-backed project
Thank you for replying.
I have one more question: Is it also possible to \includegraphics in math:TextView?
No. Again use SkiaSharp directly for this.
Ok. Thank you.
@charlesroddie : If I have a bunch of images that are already in PDF or PNG, do I have to recreate them with SkiaSharp? (I have no clear idea about SkiaSharp, sorry)
If I am correct, the purpose of CSharpMath is to display math equation without using MathJax or KaTeX (that works only on web view control/widget). My question is how to display a mathematical passage in which there are some texts surrounding equations without a web view control? CSharpMath is not appropriate for this scenario?