WpfMath 0.9.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WpfMath --version 0.9.0
NuGet\Install-Package WpfMath -Version 0.9.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WpfMath" Version="0.9.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WpfMath --version 0.9.0
#r "nuget: WpfMath, 0.9.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WpfMath as a Cake Addin
#addin nuget:?package=WpfMath&version=0.9.0

// Install WpfMath as a Cake Tool
#tool nuget:?package=WpfMath&version=0.9.0

WPF-Math Build status NuGet

WPF-Math is a .NET library for rendering mathematical formulae using the LaTeX typsetting style, for the WPF framework.

Getting Started

The simplest way of using WPF-Math is to render a static formula in a XAML file as follows.

<Window ... xmlns:controls="clr-namespace:WpfMath.Controls;assembly=WpfMath">
    <controls:FormulaControl Formula="\left(x^2 + 2 \cdot x + 2\right) = 0" />
</Window>

For a more detailed sample, check out the example project. It shows the usage of data binding and some advanced concepts.

Screenshot of example project

Using a rendering API

The following example demonstrates usage of TexFormula API to render the image into a PNG file using the RenderToPng extension method:

using System.IO;
using WpfMath;

namespace ConsoleApplication2
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            const string latex = @"\frac{2+2}{2}";
            const string fileName = @"T:\Temp\formula.png";

            var parser = new TexFormulaParser();
            var formula = parser.Parse(latex);
            var pngBytes = formula.RenderToPng(20.0, 0.0, 0.0, "Arial");
            File.WriteAllBytes(fileName, pngBytes);
        }
    }
}

If you need any additional control over the image format, consider using the GetRenderer API:

using System;
using System.IO;
using System.Windows.Media.Imaging;
using WpfMath;

namespace ConsoleApplication2
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            const string latex = @"\frac{2+2}{2}";
            const string fileName = @"T:\Temp\formula.png";

            var parser = new TexFormulaParser();
            var formula = parser.Parse(latex);
            var renderer = formula.GetRenderer(TexStyle.Display, 20.0, "Arial");
            var bitmapSource = renderer.RenderToBitmap(0.0, 0.0);
            Console.WriteLine($"Image width: {bitmapSource.Width}");
            Console.WriteLine($"Image height: {bitmapSource.Height}");

            var encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
            using (var target = new FileStream(fileName, FileMode.Create))
            {
                encoder.Save(target);
                Console.WriteLine($"File saved to {fileName}");
            }
        }
    }
}

You may also pass your own IElementRenderer implementation to TexFormula.RenderFormulaTo method if you need support for any alternate rendering engines.

Documentation

Build and Maintenance Instructions

Build the project using .NET Core SDK 3.1. WPF-Math requires C# 8 and F# 4.7 support. Here's the build and test script:

$ dotnet build --configuration Release
$ dotnet test

To approve the test results if they differ from the existing ones, execute the scripts/approve-all.ps1 script using PowerShell or PowerShell Core.

To publish the package, execute the following command:

$ dotnet pack --configuration Release

History

The library was originally ported from the JMathTex project, copyright 2004-2007 Universiteit Gent. The port was originally named WPF-TeX and was written and maintained by Alex Regueiro. It was later available as WPF-Math on Launchpad, but was unmaintained from 2011 until it was revived in its current form.

License Notes

The project code and all the resources are distributed under the terms of MIT license.

The fonts cmex10.ttf, cmmi10.ttf, cmr10.ttf, and cmsy10.ttf and cmtt10.ttf are under the Knuth License.

WPF-Math started as a direct port of JMathTeX project written in Java, reusing both code and resources. JMathTeX is distributed under the terms of GNU GPL v2 license. WPF-Math, being a derived work, has a permission from JMathTeX authors to be redistributed under the MIT license. See the Licensing 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
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 8,354 7/15/2023
2.0.0 1,113 6/11/2023
1.1.0 2,243 4/30/2023
1.0.0 1,862 2/6/2023
0.13.1 1,036 1/29/2023
0.13.0 294 1/27/2023
0.12.0 1,092 1/7/2023
0.11.0 15,120 8/31/2021
0.10.0 1,052 7/6/2021
0.9.0 34,736 7/31/2020
0.8.0 2,204 1/3/2020
0.7.0 2,005 8/24/2019
0.6.0 3,592 11/19/2018
0.5.0 2,150 5/8/2018
0.4.0 12,095 9/11/2017
0.3.1 1,840 3/18/2017
0.3.0 1,627 2/24/2017
0.2.0 1,556 2/16/2017
0.1.0 1,653 2/11/2017

Extended delimiter support; newline command support; support for \{ and \} commands; bug fixes.