• Stars
    star
    637
  • Rank 70,628 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 6 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#
340
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
51
star
7

Generaptor

GitHub Actions configuration generator
F#
46
star
8

TruePath

File path abstraction library for .NET.
C#
41
star
9

Indihiang

Web log analyzing tool
C#
25
star
10

fornever.me

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

ProcessDoctor

Cross-platform process monitoring and control software.
C#
22
star
12

awesome-old-game-remakes

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

CyclopsChat

WPF-based XMPP chat application.
C#
20
star
14

bloodmasters

Arcade, oldschool multiplayer and bloodshed.
C#
20
star
15

O21

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

PascalABC.NET.SDK

MSBuild SDK for PascalABC.NET
C#
17
star
17

andivionian-status-classifier

Software project status classifier.
16
star
18

Fenrir

Git tool in F#
F#
16
star
19

Oddities

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

praefectus

Programmable organizer application suite.
F#
15
star
21

Megadeth

A Telegram moderation solution
C#
14
star
22

overtone

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

Todosaurus

IntelliJ Plaform plugin to manage TODO comments in the code.
Kotlin
12
star
24

ChangelogAutomation

A handy tool to automate changelog processing in CI.
C#
12
star
25

omea

The Integrated Information Environment
C#
12
star
26

skalarprodukt

Experimental multidimensional arrays for F#
F#
11
star
27

Fabricator

The sharpest devops tool.
F#
10
star
28

Vacuum

Temporary file cleanup tool
F#
9
star
29

cil-mode

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

talk-lens

Talk about the LENS programming language.
HTML
7
star
31

SvgBuild

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

talk-marshal-unsafe

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

ChangelogAutomation.action

GitHub action to process changelog file.
JavaScript
6
star
34

rider-plugin-template

JetBrains Rider plugin template
Kotlin
6
star
35

artwork

Some things I draw myself.
F#
6
star
36

ProcessWatcher

A process auditing tool for Windows.
C#
6
star
37

Sound.Generator

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

nightwatch

Stays alert while you sleep.
F#
6
star
39

warcraft-2000-nuclear-epidemic

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

intellij-updater

A GitHub Action to auto-update IntelliJ Platform version for IntelliJ-based IDE plugins
F#
6
star
41

rss-filter

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

git-submerge

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

platonus

Simple Markov-network text generator.
Scala
5
star
44

adamantium

A compiler for CLR.
TypeScript
5
star
45

dotnet-licenses

Set of tooling to maintain software license information in published packages.
F#
5
star
46

OPOS-CCO

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

Smith

A modern Matrix client.
C#
4
star
48

interclient

A legacy connector for InterBase.
Java
4
star
49

old-mixer-tales

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

file-link-executor

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

strafesharp

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

Gyges

Tyrian rethinked.
F#
4
star
53

BetterFuck

Brainfuck language compiler for CLR.
C#
4
star
54

pascalabcnet.cecil

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

taskomatic

Import GitHub issues to TaskWarrior
C#
4
star
56

hell-api

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

malco

Malco programming language
C
4
star
58

1969

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

pocketeer

Pocket archival tool
F#
3
star
60

SocketTestLab

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

env-exporter

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

loglist-frontend

Modern frontend for LogList
JavaScript
3
star
63

wekan-to-taskwarrior

Import data from Wekan to Taskwarrior
PowerShell
3
star
64

mathtexdotnet

Ol' good MathTeX.NET
C#
3
star
65

Tantalum

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

Mandelbrot

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

net-core-slides

Talk about .NET Core in Russian
HTML
3
star
68

doom-start-scripts

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

checktimer

Simple manual time tracking application
Scala
3
star
70

Cerebellum

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

Numbers

CPU-based combination solver
F#
3
star
72

avalonia-pascalabc-net-showcase

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

cthulhu-bot

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

PoshConsole

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

TankDriver

Simple game about tanks.
C#
3
star
76

Hammerfest

C&C3 Modernization Project
C#
2
star
77

fstar-tutorial

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

Lagger

A program to lag selected process on Windows.
C#
2
star
79

modern-programming

Talk about modern programming in Russian.
HTML
2
star
80

w3gparser

WarCraft III replay analyzer toolkit
C#
2
star
81

dotfiles

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

EvilPlanner

A small lab application.
F#
2
star
83

wine-ng-mt_netcwmp

C
2
star
84

yog-sothoth

.NET-based XMPP logger
F#
2
star
85

git-basics

Talk about Git basics in Russian
HTML
2
star
86

GitWatcher

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

Technetium

Task management software
F#
2
star
88

cogitator

Simple but effective firewall for Windows
PowerShell
2
star
89

macrojson

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

SvnUtils

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

Umov.Csxcad

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

empty-repo-for-rexim-to-star

Empty repo for ForNeVeR to star
2
star
93

mithgolizer-miranda

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

WindowsDebuggerIssue

C++
2
star
95

eBomber

Bomberbot server written in Erlang.
Erlang
2
star
96

processor

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

FDTD-JAVA

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

OneNoteImporter

OneNote Importer by Donovan Lange
C#
2
star
99

SpySharp

Windows Forms introspection tool
F#
1
star
100

Huginn

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