- Notifications
You must be signed in to change notification settings - Fork108
A collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks
License
ForNeVeR/xaml-math
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
XAML-Math is a collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF andAvalonia XAML-based frameworks.
- For WPF, use NuGet packageWPF-Math:
- For Avalonia, useAvalonia-Math:
WPF-Math supports the following .NET variants:
- .NET Framework 4.6.2 or later
- .NET 6 or later
Avalonia-Math supports:
- .NET Framework 4.6.2 or later
- .NET Standard 2.0 or later
- .NET 6 or later
A part of XAML-Math independent of the UI frameworks is published on NuGet asXAML-Math Shared Code:
The simplest way of usingXAML-Math is to render a static formula in a XAML file as follows.
<!-- WPF--><Window …xmlns:controls="clr-namespace:WpfMath.Controls;assembly=WpfMath"> <controls:FormulaControlFormula="\left(x^2 + 2 \cdot x + 2\right) = 0" /></Window><!-- Avalonia--><Window …xmlns:controls="clr-namespace:AvaloniaMath.Controls;assembly=AvaloniaMath"> <controls:FormulaBlockFormula="\left(x^2 + 2 \cdot x + 2\right) = 0" /></Window>
For a more detailed sample, check out theexample project. It shows the usage of data binding and some advanced concepts.
The following example demonstrates usage ofTexFormula API to render the image into a PNG file using theRenderToPng extension method:
usingSystem;usingSystem.IO;usingWpfMath.Parsers;usingWpfMath;usingXamlMath.Exceptions;namespaceConsoleApplication2{internalclassProgram{publicstaticvoidMain(string[]args){conststringlatex=@"\frac{2+2}{2}";conststringfileName=@"T:\Temp\formula.png";try{varparser=WpfTeXFormulaParser.Instance;varformula=parser.Parse(latex);varpngBytes=formula.RenderToPng(20.0,0.0,0.0,"Arial");File.WriteAllBytes(fileName,pngBytes);}catch(TexExceptione){Console.Error.WriteLine("Error when parsing formula: "+e.Message);}}}}
Note thatXamlMath.TexFormulaParser::Parse may throw aXamlMath.Exceptions.TexException if it was unable to parse a formula.
If you need any additional control over the image format, consider using the extension methods from theWpfTeXFormulaExtensions class:
usingSystem;usingSystem.IO;usingSystem.Windows.Media.Imaging;usingWpfMath.Parsers;usingWpfMath.Rendering;usingXamlMath;conststringlatex=@"\frac{2+2}{2}";conststringfileName=@"T:\Temp\formula.png";varparser=WpfTeXFormulaParser.Instance;varformula=parser.Parse(latex);varenvironment=WpfTeXEnvironment.Create(TexStyle.Display,20.0,"Arial");varbitmapSource=formula.RenderToBitmap(environment);Console.WriteLine($"Image width:{bitmapSource.Width}");Console.WriteLine($"Image height:{bitmapSource.Height}");varencoder=newPngBitmapEncoder();encoder.Frames.Add(BitmapFrame.Create(bitmapSource));using(vartarget=newFileStream(fileName,FileMode.Create)){encoder.Save(target);Console.WriteLine($"File saved to{fileName}");}
You may also pass your ownIElementRenderer implementation toTeXFormulaExtensions::RenderTo method if you need support for any alternate rendering engines.
Build the project using.NET SDK 7.0 or later. Here's the build and test script:
$dotnet build XamlMath.All.sln --configuration Release$dotnettest XamlMath.All.sln
To approve the test results if they differ from the existing ones, execute thescripts/approve-all.ps1 script using PowerShell or PowerShell Core.
To publish the package, execute the following command:
$dotnet pack XamlMath.All.sln --configuration ReleaseThe library was originally ported from theJMathTex project, copyright 2004-2007 Universiteit Gent. The port was originally namedWPF-TeX and was written and maintained byAlex Regueiro. It was later available asWPF-Math on Launchpad, but was unmaintained from 2011 until it 2017, when was revived inits current form.
In 2023, after adding the Avalonia support, theWPF-Math project was renamed toXAML-Math.
The project code and all the resources are distributed under the terms ofMIT license.
Thefontscmex10.ttf,cmmi10.ttf,cmr10.ttf, andcmsy10.ttf andcmtt10.ttf are under theKnuth License.
The font filejlm_msam10.ttf (taken from JLaTeXMath project) is licensed under theOpen Font License.
XAML-Math (namedWPF-Math at the time) started as a direct port ofJMathTeX project written in Java, reusing both code and resources. JMathTeX is distributed under the terms of GNU GPL v2 license. XAML-Math, being a derived work, has a permission from JMathTeX authors to be redistributed under the MIT license. See theLicensing history for the details.
We're very grateful to JMathTeX authors for their work and allowing to redistribute the derived library. JMathTeX is written by:
- Kris Coolsaet
- Nico Van Cleemput
- Kurt Vermeulen
About
A collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
