• Stars
    star
    601
  • Rank 71,588 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks

XAML-Math

XAML-Math is a collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks.

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 as XAML-Math Shared Code: NuGet

Getting Started

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

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

<!-- Avalonia -->
<Window … xmlns:controls="clr-namespace:AvaloniaMath.Controls;assembly=AvaloniaMath">
    <controls:FormulaBlock 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 the 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;
using System.IO;
using WpfMath.Parsers;
using WpfMath;
using XamlMath.Exceptions;

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";

            try
            {
                var parser = WpfTeXFormulaParser.Instance;
                var formula = parser.Parse(latex);
                var pngBytes = formula.RenderToPng(20.0, 0.0, 0.0, "Arial");
                File.WriteAllBytes(fileName, pngBytes);
            }
            catch (TexException e)
            {
                Console.Error.WriteLine("Error when parsing formula: " + e.Message);
            }
        }
    }
}

Note that XamlMath.TexFormulaParser::Parse may throw a XamlMath.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 the WpfTeXFormulaExtensions class:

using System;
using System.IO;
using System.Windows.Media.Imaging;
using WpfMath.Parsers;
using WpfMath.Rendering;
using XamlMath;

const string latex = @"\frac{2+2}{2}";
const string fileName = @"T:\Temp\formula.png";

var parser = WpfTeXFormulaParser.Instance;
var formula = parser.Parse(latex);
var environment = WpfTeXEnvironment.Create(TexStyle.Display, 20.0, "Arial");
var bitmapSource = formula.RenderToBitmap(environment);
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 TeXFormulaExtensions::RenderTo method if you need support for any alternate rendering engines.

Documentation

Build and Maintenance Instructions

Build the project using .NET SDK 7.0 or later. Here's the build and test script:

$ dotnet build XamlMath.All.sln --configuration Release
$ dotnet test XamlMath.All.sln

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 XamlMath.All.sln --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 2017, when was revived in its current form.

In 2023, after adding the Avalonia support, the WPF-Math project was renamed to XAML-Math.

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.

The font file jlm_msam10.ttf (taken from JLaTeXMath project) is licensed under the Open Font License.

XAML-Math (named WPF-Math at the time) 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. XAML-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

More Repositories

1

AvaloniaRider

JetBrains Rider plugin for Avalonia development
Kotlin
375
star
2

Cesium

C compiler for the CLI platform
C#
316
star
3

ExtDiff

Compare documents using MS Word from the command line.
PowerShell
108
star
4

tdlib.native

Prebuilt binaries of TDLib distributed as a NuGet package.
PowerShell
95
star
5

ManagedSpy

Runtime introspect Windows Forms applications.
C++
77
star
6

msdn-delocalizer

Chrome and Firefox extension to force MSDN (and similar Microsoft documentation sites) to always use English locale.
TypeScript
49
star
7

Jabber-Net

[DEPRECATED] A modern fork of Jabber-Net
C#
36
star
8

Indihiang

Web log analyzing tool
C#
25
star
9

fornever.me

Friedrich von Never: Engineer, Programmer, Gentleman.
F#
25
star
10

awesome-old-game-remakes

A curated list of awesome open-source remakes of old games.
21
star
11

CyclopsChat

WPF-based XMPP chat application.
C#
18
star
12

O21

FOSS remake of U95, an old submarine arcade game from 1995.
F#
18
star
13

PascalABC.NET.SDK

MSBuild SDK for PascalABC.NET
C#
17
star
14

andivionian-status-classifier

Software project status classifier.
16
star
15

Fenrir

Git tool in F#
F#
16
star
16

bloodmasters

Arcade, oldschool multiplayer and bloodshed.
C#
16
star
17

Oddities

.NET libraries supporting several old and obscure data formats: DIB, MRB, NE, SHG, WinHelp.
C#
16
star
18

ProcessDoctor

Cross-platform process monitoring and control software.
C#
16
star
19

praefectus

Programmable organizer application suite.
F#
15
star
20

overtone

A modern FOSS remake of The Tone Rebellion.
F#
14
star
21

Megadeth

A Telegram moderation solution
C#
12
star
22

skalarprodukt

Experimental multidimensional arrays for F#
F#
11
star
23

ChangelogAutomation

A handy tool to automate changelog processing in CI.
C#
11
star
24

Fabricator

The sharpest devops tool.
F#
10
star
25

Vacuum

Temporary file cleanup tool
F#
9
star
26

cil-mode

Major emacs mode for editing Common Intermediate Language files.
Emacs Lisp
9
star
27

talk-lens

Talk about the LENS programming language.
HTML
7
star
28

SvgBuild

Managed tool set to render SVG images
C#
7
star
29

talk-marshal-unsafe

A talk (in Russian) about .NET marshaling and unsafe code.
HTML
6
star
30

ChangelogAutomation.action

GitHub action to process changelog file.
JavaScript
6
star
31

artwork

Some things I draw myself.
F#
6
star
32

rss-filter

Simple RSS filtering server not based on Play framework.
F#
6
star
33

Sound.Generator

Generate WAV files using Windows' TTS engine
C++
6
star
34

nightwatch

Stays alert while you sleep.
F#
6
star
35

git-submerge

Merge Git submodule into the main repo as if they've never been separate at all
Rust
5
star
36

platonus

Simple Markov-network text generator.
Scala
5
star
37

ProcessWatcher

A process auditing tool for Windows.
C#
5
star
38

adamantium

A compiler for CLR.
TypeScript
5
star
39

warcraft-2000-nuclear-epidemic

Sources of WarCraft 2000: Nuclear Epidemic, in the form they were made available by the developer.
C++
5
star
40

OPOS-CCO

OLE for Retail POS Common Control Objects with some patches.
C++
4
star
41

Smith

A modern Matrix client.
C#
4
star
42

old-mixer-tales

Wonderful stories of one strange old man.
Lua
4
star
43

interclient

A legacy connector for InterBase.
Java
4
star
44

file-link-executor

Starts executable files from the IntelliJ consoles.
Kotlin
4
star
45

strafesharp

.NET library and a support programs to control Corsair Strafe RGB keyboard
F#
4
star
46

Gyges

Tyrian rethinked.
F#
4
star
47

BetterFuck

Brainfuck language compiler for CLR.
C#
4
star
48

taskomatic

Import GitHub issues to TaskWarrior
C#
4
star
49

hell-api

Miranda IM managed plugin API adapter for .NET.
C#
4
star
50

malco

Malco programming language
C
4
star
51

1969

The Moon landing never happened, but we went to the Mars instead.
F#
4
star
52

wekan-to-taskwarrior

Import data from Wekan to Taskwarrior
PowerShell
3
star
53

SocketTestLab

Playing with sockets in .NET.
C#
3
star
54

env-exporter

Export computer's environment variables to a file.
PowerShell
3
star
55

loglist-frontend

Modern frontend for LogList
JavaScript
3
star
56

pocketeer

Pocket archival tool
F#
3
star
57

Tantalum

A simple algebraic computation system written in F#.
F#
3
star
58

doom-start-scripts

The stuff I keep forgetting all the time.
PowerShell
3
star
59

Mandelbrot

Application for real-time visualizing of Mandelbrot set.
C++
3
star
60

TankDriver

Simple game about tanks.
C#
3
star
61

net-core-slides

Talk about .NET Core in Russian
HTML
3
star
62

pascalabcnet.cecil

Mono.Cecil code generator for PascalABC.NET. See the issues section for details.
C#
3
star
63

Cerebellum

Server for sharing todo-notes between various clients.
Erlang
3
star
64

checktimer

Simple manual time tracking application
Scala
3
star
65

Numbers

CPU-based combination solver
F#
3
star
66

avalonia-pascalabc-net-showcase

Sample for AvaloniaUI written in PascalABC.NET
Pascal
3
star
67

mathtexdotnet

Ol' good MathTeX.NET
C#
3
star
68

cthulhu-bot

Just another XMPP bot using C++, boost and gloox technologies.
C++
3
star
69

PoshConsole

PoshConsole is a modern graphical PowerShell Console.
C#
3
star
70

Hammerfest

C&C3 Modernization Project
C#
2
star
71

fstar-tutorial

My solutions for the F* turorial
F*
2
star
72

modern-programming

Talk about modern programming in Russian.
HTML
2
star
73

w3gparser

WarCraft III replay analyzer toolkit
C#
2
star
74

dotfiles

My dotfiles and alike system entities.
Vim Script
2
star
75

EvilPlanner

A small lab application.
F#
2
star
76

wine-ng-mt_netcwmp

C
2
star
77

mithgolizer-miranda

Miganda NG plugin for banning the users.
C++
2
star
78

yog-sothoth

.NET-based XMPP logger
F#
2
star
79

git-basics

Talk about Git basics in Russian
HTML
2
star
80

GitWatcher

Powershell tool to watch directory changes and autocommit them to local git repository.
2
star
81

Technetium

Task management software
F#
2
star
82

cogitator

Simple but effective firewall for Windows
PowerShell
2
star
83

macrojson

Simple example of Scala macros and quasiquotes.
Scala
2
star
84

SvnUtils

PowerShell utility functions for the SVN version control.
PowerShell
2
star
85

Umov.Csxcad

CLI-based CSXCAD parser and writer.
F#
2
star
86

empty-repo-for-rexim-to-star

Empty repo for ForNeVeR to star
2
star
87

WindowsDebuggerIssue

C++
2
star
88

eBomber

Bomberbot server written in Erlang.
Erlang
2
star
89

processor

Simplified Windows process manager written in Rust.
Rust
2
star
90

FDTD-JAVA

Stephen Kirkup implementation of FDTD simulation in Java.
Java
2
star
91

SpySharp

Windows Forms introspection tool
F#
1
star
92

Huginn

It will be a graphical VCS client.
C++
1
star
93

Summatorium

A small benchmark for the good of all of us except the ones who are dead
C#
1
star
94

talk-javascriptservices

My talk about ASP.NET Core and JavaScriptServices.
HTML
1
star
95

PsJira

PowerShell JIRA client.
PowerShell
1
star
96

robocode-sniper

Simple bot for Robocode
Java
1
star
97

ps-path

PowerShell path extensions.
PowerShell
1
star
98

idea-conan-plugin

Conan C/C++ package manager plugin for IDEA-based IDEs
Kotlin
1
star
99

ML2Calculator

A notice from the past.
Pascal
1
star
100

fgitterc

Integrate gitter with IRC.
Frege
1
star