[英]How to render a formula in WPF or WinForms
Update 2018 TL;DR; 更新2018 TL; DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math 用于WPF的LaTEX https://github.com/ForNeVeR/wpf-math
Original question I need to have a way to draw a mathematical formula in Windows Forms or WPF. 原始问题我需要一种在Windows Forms或WPF中绘制数学公式的方法。 Some "FormulaTextBox" control would be exactly what I need. 一些“ FormulaTextBox”控件正是我所需要的。
I'm not asking about full implementation of LaTEX, but at least something beyond RichTextBox possibilities, with division lines, square roots, etc. 我不是在问LaTEX的完整实现,而是至少要有RichTextBox可能性之外的东西,包括分隔线,平方根等。
Here's a list of options, pulled from several webpages online, as well as a few similar questions on SO 以下是一些选项的列表,这些选项来自在线的多个网页,以及关于SO的一些 类似 问题
tex4ht
package renders math equations to images 我在某处看到提到tex4ht
软件包将数学方程式渲染到图像 WebBrowser
control, and just locally include one of many javascript libraries for rendering LaTex. 您也可以使用WebBrowser
控件,只需在本地包括一个 的 许多 的JavaScript 库,用于渲染胶乳。 也许您可以使用Wolfram Alpha API检索图像。
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. 如果您想使用RichTextBox功能之外的其他功能来渲染饼图,除法和sqr根等,则可以只使用WebBrowserControl作为文本框。 Then to render formula's you could leverage techniques shown in this webpage, save it to your desktop and open the html file: 然后,要渲染公式,您可以利用此网页中显示的技术,将其保存到桌面并打开html文件:
http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html 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. 显然,您需要使用特殊的语法(或特殊的计算器按钮)来输入公式的内容,而从驱动该网页的customisations.js文件中我猜得出,您也可以创建自己的运算符和函数列表。
Here's what I'd do if none of the .NET specific solutions work for you: 如果没有.NET特定解决方案对您有用,这就是我要做的事情:
It's a bit hacky, but it'll work and your users won't know the difference. 这有点骇人听闻,但可以正常使用,您的用户也不知道有什么区别。 Download the Mathjax library. 下载Mathjax库。 When your user enters in the equation, you could convert the equation to LaTex or MathML. 当用户输入方程式时,可以将方程式转换为LaTex或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). 然后,您将使用LaTex或MathML并生成一个引用Mathjax的HTML文件,并在您的WebBrowser小窗口中显示该文件(对WinForms和WPF均有效)。 This shouldn't require an internet connection. 这不需要互联网连接。
Like I said, your users won't be any the wiser. 就像我说的那样,您的用户不会更明智。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.