4

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...)

LaRiFaRi
  • 159
  • 1
  • 8
  • 3
    A quick search gave me this, hope it helps http://stackoverflow.com/questions/8899204/how-to-render-a-formula-in-wpf-or-winforms – Joe Stanton Jul 25 '13 at 14:32
  • Does the requirement extend beyond standard XML style unicode characters where for example you could display something like the infinity symbol with `∞` ? – Chris W. Jul 25 '13 at 15:41
  • 1
    @JoeStanton Thx for the link. I found that, too. But everything there is "old", "inactive", "unofficial" or just to time consuming for my purpose. I was hoping to get newer ideas as XAML is getting more popular in the last time. I got some ideas from this link but hopefully there is something more practical out there. – LaRiFaRi Jul 26 '13 at 07:45
  • @ChrisW. Yes, I will be needing labels like \beta^prime_\infty or similar. Would like to take OT-fonts for that. I wonder why SVG and MathML (being XML) seem to be that hard to include in XAML (which is XML). The labels and formulas should be scalable to fit in text, graphics and docs. – LaRiFaRi Jul 26 '13 at 07:48
  • XML is simply a structural format. The semantics of XML content is entirely dependent on scenario; there's no reason to believe you could just mix and match SVG and XAML, any more than to expect you could e.g. embed XSLT in an XHTML document and have it "just work". If you have fonts with the symbols and graphics you want to use, then you should be able to use [`RichTextBox`](https://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox(v=vs.110).aspx) to display in WPF. – Peter Duniho Feb 07 '15 at 19:40

4 Answers4

2

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.

ForNeVeR
  • 6,726
  • 5
  • 24
  • 43
  • Does this support MathML? – VivekDev Dec 22 '18 at 14:01
  • 1
    @VivekDev no it doesn't. If you're able to provide your own MathML parser, then it's possible to convert to WPFMath data structures and reuse common rendering infrastructure. Feel free to contact us on GitHub if you want to help or propose the feature. – ForNeVeR Dec 22 '18 at 14:34
  • Ok, Thanks. First I will take a look at WPFMath and then decide. – VivekDev Dec 22 '18 at 14:42
  • Note that version 0.6 and lower support .NET framework 4.0 which is very userful. – Mihai Jul 15 '20 at 07:40
0

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

Liero
  • 25,216
  • 29
  • 151
  • 297
0

As far as I can see, the best rendering (on paper) is achieved with a late conversion from a vector file. I would prefer using either GDI+ (System.Drawing) or WPF (System.Media) to render a formula. Let me know if we can collaborate on a WPF solution.

0

I used https://github.com/std8590/xmcd2cs to convert most of my Mathcad xmcd files to C#.

Then I used the formulas in code and make the input variables available in UI.

std8590
  • 37
  • 2