Display equation to mathematical format [duplicate] - c#

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.

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

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

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.

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.

Related

How to render a formula in WPF or WinForms

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.
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!)
Perhaps you can use the Wolfram Alpha API to retrieve the images.
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.
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.

How to plot XY graph in C#?

I am developing an application in C# which deals with specific genetic algorithm problem. The execution of the algorithm provides output parameters that are required to draw a chart.The graphic chart consists of 2 independent axis, lets say X is number of generation and Y represents corresponding maximum value of fitness function. To be more specific, I've uploaded picture from Excel so here it is :
http://img97.imageshack.us/img97/2046/graphnb.png
My priority is to make this application fully-functional by allowing user (who sets random execution factors such as mutation percentage, population and generation number, number of elite individuals, etc.) to see generated X-Y graph inside the generated "Form" in C#. I've found site that partially solves my problem, but that's not the whole point (http://csharp.net-informations.com/excel/csharp-excel-chart-picturebox.htm). So I'm asking if there is a way to implement mentioned graph by not using any other applications, but maybe only C# libraries and functions for plotting or something like that? Hope I made myself clear. Best regards.
Free and native answer is http://zedgraph.org/wiki/index.php?title=Main_Page
Does not involve WPF
Does not cost
Only C# libraries
Works inside a .NET WinForm
personally I like XtraChart of DeveloperExpress, but there are also many many other cheaper or more expensive alternatives, also other questions similar to yours here in SO: WPF chart controls
I like to use libraries whenever I can so I can focus on my real business case instead of trying to re-invent the wheel everytime, also because usually it's not trivial to reach the same level of results of people working hard to deliver specific components.
As all have said you have to work on WPF (different platform then WinForms) with 3rd party charting library that are much easier to integrate with your application.
If you want to know further about charting library then you should see this page
Click here
If you can use it, try WPF. It's much better for developing graphically rich user interfaces than standard Windows Forms -- especially if you don't want to use third-party libraries.

Screen scraper application (not HTML)

I need screen scraper application which will recognize text from the screen (and not use winapi to do this so source could be in image file). I found a lot of commercial solutions, but I need something open source or free.
I plan to include it in my C# project, so there should be some SDK available.
Thanks.
You could use Tessnet to do character recognition of your images. If you want to screen scrape the desktop, you could potentially just take a screen shot, turn it into an image, and use the OCR library above.
Depending on what you want to do, I have found screen scraper useful for applying patterns against a web site and saving the data that I care about. The tutorial page should give you an idea of what it does.
Screen Scraper's free edition allows scripting in Interpreted Java, JScript, JavaScript, Python, and VBScript... is that close enough?

embed user customizable richtext or html in winforms

I am writing a c# winforms application which needs to enable its users to add content to its interface. I have looked at the RichTextBox and the WebBrowser controls, but I'm not sure which route to take. The content would contain text with newlines and several tags that will include images which are in the project resources.
This is my text [niceimage] and it
includes an image and another: [smiley]
The disadvantage of the RichTextBox control is that I would need to craft richtext by hand which I am not familiar with. Also the .net framework does not have the functionality to make Metafiles from Images, the format RTF uses for embedding images.
The problems I had with the WebBrowser is that I have no idea how to load a page via a stream. I tried the DocumentStream to no avail. Also I need to include images which would need embedded images in the html string, which might not be supported. Another issue is that the WebBrowser control might be too heavy as the control will appear in several places in the application. It als needs to load very quickly for the application to feel snappy.
You may want to look at the WPF RichTextBox which is supposed to be a major improvement over the .NET 2.0 version. Here's an article that elaborates upon the improvements.
Additionally, many Component development firms offer their own commercial version that has many feature and usability improvements. You may want to evaluate some of them, assuming that you are open to purchasing such a component. Try Googling for "RichTextBox component".
For the functionality that you require, I feel that using a WebBrowser (especially in multiple places in the application) would be overkill.

Printing in VB.Net/C# Forms Application -- Layout Designer?

I maintain a vb.net forms application that prints various labels to label printers. (Label printers are just like any printer, just smaller print area/lower resolution)
The system uses a legacy printing method that's supported in the printer hardware, but has been out of general use for over a decade. I'm adding logic to print from the PrintDocument class. I like the flexibility of the class, but layout is a bit tedious. (Defining the sizes/locations of each DrawString command, etc.)
Are there any software products or open source UI designers for generating print document layout? The designer output must be something I can integrate into my code (dll is OK, just not a separate executable) and can not have a per user license. (Lots of users on my system)
Have a look at this thread Visual Print Design for .NET.
Also, you might consider a PDF template that you can inject with the values, then print the PDF, not perfect, but it could work depending on your needs.
When I looked for a similar need, I ran across some solutions that were marketed as business card designers that looked like it'd fit the bill.
Since what I need is fairly simple I went ahead and rolled my own simple desinger. Found at a great little class that makes controls movable/resizable which saved a bunch of time. Thanks all for the ideas.

Categories