• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ForNeVeR/wpf-math: .NET library for rendering mathematical formulae using the La ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ForNeVeR/wpf-math

开源软件地址(OpenSource Url):

https://github.com/ForNeVeR/wpf-math

开源编程语言(OpenSource Language):

C# 89.1%

开源软件介绍(OpenSource Introduction):

WPF-Math NuGet

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

It supports the following .NET runtimes:

  • .NET Framework 4.5.2 or later
  • .NET Core 3.1 or later
  • .NET 5.0 or later

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 SDK 5.0. 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



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap