33

Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math

Original question I need to have a way to draw a mathematical formula in Windows Forms or WPF. Some "FormulaTextBox" control would be exactly what I need.

I'm not asking about full implementation of LaTEX, but at least something beyond RichTextBox possibilities, with division lines, square roots, etc.

MajesticRa
  • 13,770
  • 12
  • 63
  • 77
  • 1
    this [article](http://cmiles.info/2009/10/03/some-experiences-in-the-display-of-mathematical-equations-in-wpf/) looks like it could help – Jake Berger Jan 30 '12 at 16:27
  • Looks interesting from the first glance. Thank you! I will review it tomorrow and post here. – MajesticRa Jan 30 '12 at 21:53

4 Answers4

36

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!)
ForNeVeR
  • 6,726
  • 5
  • 24
  • 43
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • +1 You probably deserve this bountry... I didn't see your WebBrowser control point before I posted my answer. – Jeremy Thompson Jan 31 '12 at 04:36
  • 7
    WPF-Math is now active. I've forked it to GitHub, contacted the original author and got his blessing. See https://github.com/ForNeVeR/wpf-math – ForNeVeR Feb 12 '17 at 05:36
2

Perhaps you can use the Wolfram Alpha API to retrieve the images.

TJHeuvel
  • 12,403
  • 4
  • 37
  • 46
  • 1
    Thank you for a response. But isn't it web-only? How to embed the thing as stadalone winforms control? Could you, please, provide some short hints or code? – MajesticRa Jan 30 '12 at 09:53
  • Its a bit of a gamble, but you can just call the API from your winforms app using WebRequest and parse the response as XML to get the right node. Then just set the source of a PictureBox to the url. – TJHeuvel Jan 30 '12 at 09:56
  • 1
    That's why "standalone" word was used. "using WebRequest" is too much burden for a standalone application. In some rare cases it could be acceptable, I agree. But it is definitely not a general answer for winforms or WPF. – MajesticRa Jan 30 '12 at 10:14
  • +1 - even if it is a stand-alone app, a mode to go online and use Wolfram Alpha's API is a good idea. – Jeremy Thompson Jan 31 '12 at 04:21
  • 6
    "a mode to go online and use Wolfram" - a good joke, yes)) Tell it your clients))) – MajesticRa Jan 31 '12 at 06:18
0

If you want something beyond a RichTextBox abilities to render pie, divisions and sqr roots and etc, you could just use WebBrowserControl(s) as textbox's. Then to render formula's you could leverage techniques shown in this webpage, save it to your desktop and open the html file:

http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html

Obviously you'll need a special syntax (or special calculator buttons) to enter the formula's and I'm guessing from looking at the customisations.js file driving that webpage that you could make your own list of operators and functions too.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
0

Here's what I'd do if none of the .NET specific solutions work for you:

It's a bit hacky, but it'll work and your users won't know the difference. Download the Mathjax library. When your user enters in the equation, you could convert the equation to LaTex or MathML. You would then take the LaTex or MathML and generate an HTML file that references Mathjax and display the file in your tiny WebBrowser window (valid for both WinForms and WPF). This shouldn't require an internet connection.

Like I said, your users won't be any the wiser.

JP Richardson
  • 38,609
  • 36
  • 119
  • 151