File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ For a more detailed sample, check out the [example project][example]. It shows t
2828The following example demonstrates usage of ` TexFormula ` API to render the image into a PNG file using the ` RenderToPng ` extension method:
2929
3030``` csharp
31+ using System ;
3132using System .IO ;
3233using WpfMath ;
3334
@@ -40,15 +41,24 @@ namespace ConsoleApplication2
4041 const string latex = @" \frac{2+2}{2}" ;
4142 const string fileName = @" T:\Temp\formula.png" ;
4243
43- var parser = new TexFormulaParser ();
44- var formula = parser .Parse (latex );
45- var pngBytes = formula .RenderToPng (20 . 0 , 0 . 0 , 0 . 0 , " Arial" );
46- File .WriteAllBytes (fileName , pngBytes );
44+ try
45+ {
46+ var parser = new TexFormulaParser ();
47+ var formula = parser .Parse (latex );
48+ var pngBytes = formula .RenderToPng (20 . 0 , 0 . 0 , 0 . 0 , " Arial" );
49+ File .WriteAllBytes (fileName , pngBytes );
50+ }
51+ catch (TexException e )
52+ {
53+ Console .Error .WriteLine (" Error when parsing formula: " + e .Message );
54+ }
4755 }
4856 }
4957}
5058```
5159
60+ Note that ` WpfMath.TexFormulaParser::Parse ` may throw a ` WpfMath.TexException ` if it was unable to parse a formula.
61+
5262If you need any additional control over the image format, consider using the extension methods from the ` WpfTeXFormulaExtensions ` class:
5363
5464``` csharp
You can’t perform that action at this time.
0 commit comments