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

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

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.

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

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.

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.

Related

How to handle floating images in OpenXML and convert to html equivalent

I am using OpenXML along with OpenXML Power Tools. So far I have managed to convert a lot of words functionality to html. The main point I can't yet figure out is floating images. I have taken the following example from PowerTools and slightly modified it to my needs.
https://github.com/EricWhiteDev/Open-Xml-PowerTools/blob/1990e7f5bfd00a5e7aab2e074fa7fc0b1be7cd3a/OpenXmlPowerToolsExamples/HtmlConverter01/HtmlConverter01.cs
The ImageHandler part is where I get stuck. I can generate an image (and I've converted to base 64 so I don't have to worry about external images) but it always goes to the left (or follows manual tabbing), even though it's a floating image that goes horizontally in the middle with a slight gap at the top.
Has anyone any experience on how to achieve this?
OpenXML Power Tools ignores all floating settings of images.
w:drawing with wp:inline and wp:anchor are handled the same way and result in the same html.

How to draw math symbols?

I need draw some pictures and save it into a JPG file.
I know that the C# GDI can draw string with method Graphics.DrawString.
But what troubles me is that I need draw some math symbols, like below:
So are there some libraries can help me to do that? How can I get the math symbols with GDI?
In case you don't find a pure .NET solution, I would look for a command-line tool or a native DLL library which can render standard formattings like MathML or LaTeX math expressions. You will find plenty of FOSS stuff for these and I don't think it would be too hard to integrate. In case you work with bitmaps, you can just tell the 3rd party to render a given size bitmap. If you need vectorized drawings, then you could aim to produce your entire output in LaTeX or maybe you can turn MathML/LaTeX formulas to RTF/HTML.

Dicom Images non square

I'm working with a set of DICOM images that are 512(columns) X 384(rows)
Is there a tool that would make the images 512X512? That is, filling the rows in this case to make it 512.
I've researched VTK with no luck.
Thanks!
Argh, you was almost there! In fact, VTK is not the proper tool for that. ITK is.
To be precise, VTK is for 3D visualization (that is, rendering of 3D objects), while ITK is specifically concerned for image processing.
So, using ITK, you could use a padding filter, here's a complete example from the official wiki, ready to be compiled and executed: http://public.kitware.com/pub/itk/Examples/src/Filtering/ImageGrid/PadAnImageWithAConstant/Documentation.html.
But, if you want to do the things in an easier way, I suggest MATLAB (ITK could be difficult to configure). In this case, this post could help: Padding an image in MATLAB.
Good luck!

Lightly styled text library for WPF?

Does anyone know of a lightly-marked-up-text to styled-text formatting library (ie. something like Markdown# or Textile.NET), but which produces a native XAML document (or rather, a FlowDocument model or similar that can be displayed directly in a WPF app), to avoid the use of a WebBrowser?
Bonus points for something lightweight. I'm hoping for something that will tolerate very frequent updates in the source text.
Alternatively, is there a lightweight HTML rendering control that can be used in WPF? (I don't consider the standard WebBrowser to be lightweight.)
I don't know of such a library pre-built, but I do have some thoughts for you that may be helpful.
The first big question in my mind is why you want to use something primitive like Markdown when you could be using RichTextBox. Markdown is required for StackOverflow and similar sites because of the limitations of the browser. But if your app is WPF this is not an issue.
One guess as to why you might want to do this is that you want your documents to be editable both in WPF and in a lowest-common-denominator web application. In that case you will need an engine that renders the markdown to HTML anyway, so why not leverage that same engine to convert the markdown to XAML?
Converting arbitrary HTML to XAML is very difficult, but converting the sort of HTML that a Markdown converter would spit out is another matter entirely. Most Markdown-style converters spit out only a few simple HTML tags, all of which are trivially convertible to equivalent XAML.
If you use an Markdown-to-HTML converter it will have done all of the really heavy lifting for you (parsing the text, etc) and left you with an XML-like document (HTML to be precise) that is relatively easy to parse. Also, if you are using the Markdown-to-HTML converter elsewhere you will have confidence that your Markdown parser will parse your Markdown syntax exactly the same for both HTML and XAML use because it will be the same parser in each case.
So basically what I am thinking is:
string html = MarkdownEngine.MarkdownToHtml(markdown);
string xaml = MarkdownHtmlToXamlTranslator.HtmlToXaml(html);
Where you design your implementation of MarkdownHtmlToXamlTranslator around whatever the markdown engine actually spits out. It could be a very simple XSLT, or you could use LINQ to XML along with XDocument construction techniques. Either way it should be a very small bit of code.

Locating Text within image

I am currently working on a project and my goal is to locate text in an image. OCR'ing the text is not my intention as of yet. I want to basically obtain the bounds of text within an image. I am using the AForge.Net imaging component for manipulation. Any assistance in some sense or another?
Update 2/5/09:
I've since went along another route in my project. However I did attempt to obtain text using MODI (Microsoft Office Document Imaging). It allows you to OCR an image and pull text from it with some ease.
This is an active area of research. There are literally oodles of academic papers on the subject. It's going to be difficult to give you assistance especially w/o more deatails. Are you looking for specific types of text? Fonts? English-only? Are you familiar with the academic literature?
"Text detection" is a standard problem in any OCR (optical character recognition) system and consequently there are lots of bits of code on the interwebs that deal with it.
I could start listing piles of links from google but I suggest you just do a search for "text detection" and start reading :). There is ample example code available as well.
recognizing text inside an image is indeed a hot topic for researchers in that field, but only begun to grow out of control when captcha's became the "norm" in terms of defense against spam bots. Why use captcha's as protection? well because it is/was very hard to locate (and read) text inside an image!
The reason why I mention captcha's is because the most advancement* is made within that tiny area, and I think that your solution could be best found there.
especially because captcha's are indeed about locating text (or something that resembles text) inside a cluttered image and afterwards trying to read the letters correctly.
so if you can find yourself a good open source captcha breaking tool you probably have all you need to continue your quest...
You could probably even throw away the most dificult code that handles the character recognition itself, because those OCR's are used to read distorted text, something you don't have to do.
*: advancement in terms of visible, usable, and practical information for a "non-researcher"
If you're ok with using an online API for this, the API at http://www.wisetrend.com/wisetrend_ocr_cloud.shtml can do text detection in addition to just OCR.
Stroke width transform can do that for you. That's at least what MS developed for their mobile phone OS. A discussion on the implementation is here at https://stackoverflow.com/

Categories

Resources