How to Render a Formula in Wpf or Winforms

How to render a formula in WPF or WinForms

Here's a list of options, pulled from several webpages online, as well as a few similar questions on SO

  • WPF-Math, a WPF library for rendering math-related TeX markup.
  • gNumerator is a WinForms control that renders MathML. It is native C#, but appears to be quite old.
  • Math Expressions, a commercial WinForms control for displaying and editing math equations. Note: Not free
  • There's an unofficial port of JMathTex to a C# WPF control
  • The Windows version of the LaTex editor Lyx uses a native library called MikTex you could take a look at. I saw mention somewhere that the tex4ht package renders math equations to images
  • MimeTex/MathTex, as you already mentioned
  • You could also use a WebBrowser control, and just locally include one of many javascript libraries for rendering LaTex.
  • You could pawn off the work onto Microsoft Word (Example - requires users to have MS Word installed!)

How do I render an equation from Math Input Panel in a WPF app and use MathML in the background?

I just want to post my answer for clearity.

I read somewhere that you can display an equation using a browser control, but Internet Explorer doesn't support MathML. For this reason, I tried to figure out if there was some kind of other browser control (like a firefox version) that i could use. After trying and failing at that, I stumbled upon MathPlayer from www.descci.com.

MathPlayer adds MathML support to IE en because of that, I was able to render equations in WPF using the browser control and style it using CSS.

Display equations in a WPF application

There exists this WPFMath library (also available on NuGet) that allows to render LaTeX formulas in a WPF control.

Usage would be:

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

How to draw an equation better?

You can draw any shape that you need with the Path class. That includes a variety of curves that are really quite easy to use, once you know what each parameter is for. You can find an introductory article that explains the basics in the Shapes and Basic Drawing in WPF Overview page on MSDN. You can find more drawing examples in the first linked page.

One thing to note is that you'd probably find it a lot easier to define your mathematical symbols using Blend and then use the auto generated XAML, rather than trying to compose it all in C#.

If you don't want to draw it all yourself, you can find a number of alternative solutions, such as third party libraries and controls, listed in the most popular answer to the How to render a formula in WPF or WinForms question here on StackOverflow.

display equations in windows form desktop application in c#

You might try out the following,

  1. Host a WebBrowser control
  2. Create HTML element with MathJax to render your equations.

It's not perfect, but at least should work.



Related Topics



Leave a reply



Submit