Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display mathematical expressions in WPF labels or panels?

I am writing software which displays a lot of mathematical content. As in windows forms it is already hard to set a subscript or a Greek letter in a label, I am thinking of switching to WPF.

At the moment I am searching for the best way to render a mathematical expression, a formula or just a symbol inside my graphical user interface. They have to be shown in labels or drawn graphs/pictures. No live/just-in-time renderings but beautiful fix symbols.

What is the best way to do that? I thought, that MathML should be supported well, but I can't find a lot regarding that. I would be glad to hear some advice.

Here is, where I can get my symbols from (or what I would prefer):

  • LaTeX-code (First choice! Code is already there and same appearance in Software and documentation would be marvellous)
  • MathML-code (LaTeX-code in Word 2007 or higher -> Word equations -> copy as plain MathML to clipboard)
  • SVG (some rendering of LaTeX in Inkscape and export to XAML)
  • xmcd Files (Mathcad XML Document. Don't know how, but at least it's XML)
  • html Files (written by LaTeX->html or Mathcad->html

What I wouldn't consider personally, but maybe there are good solutions to:

  • Images (png-icons, pdf, dvi, eps, svg directly imported)
  • Symbols (like copy pasted from Character Map. Don't like the fonts, wouldn't find all I need and exchange of formula syntax would not be given)

I think using LaTeX, MathML or html would be great as they could be used for documentation as well. I also could think about exporting calculation results to *.tex files or internally generate graphics completely with LaTeX (tikz, pgfplots...)

like image 350
LaRiFaRi Avatar asked Oct 22 '22 04:10

LaRiFaRi


2 Answers

Consider using open-source WPF-Math library (disclaimer: I'm its' current maintainer).

It can help you to display the LaTeX expression in a WPF window. It also uses vector graphic instead of bitmaps, so the formulae will scale nice on the modern displays.

like image 73
ForNeVeR Avatar answered Oct 24 '22 13:10

ForNeVeR


I would go with pure xaml approach using datatemplates. There is no need for another vector format or rednering engine. You can use datatemplate for each expression in expression tree. Using viewboxes you can achieve stretching, so topmost expressions will be larger then inner expressions. Your datatemplates will generate visual tree from you expression tree. I mean there will be contentpresenters inside contentpresenter.

The great advatage is that the expression visualisation can be responsive and interactive, just like math expression in MS Word, or Excel.

I could help you with implementation, since this is not trivial, if you are not familiar with wpf datatemplates

like image 35
Liero Avatar answered Oct 24 '22 12:10

Liero