在 C# WinForms 上获取 Latex [英] Getting Latex on C# WinForms

查看:49
本文介绍了在 C# WinForms 上获取 Latex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:初学者,刚开始使用C#

我正在制作一个C#WinForms应用程序,在该应用程序上我希望显示布局合理的数学表达式.对我来说,我猜想使用乳胶将是最好的方法.我遇到的问题是如何在winforms应用程序中呈现乳胶.到处搜索,我发现 FMath ,但是我无法获得一个简单的工作示例.

我已经安装了库和新控件(MathMLFormulaControl),并将控件添加到了项目中.加载表单后,将完成以下操作:

  private void Form1_Load(对象发送者,EventArgs e){fmath.controls.MathMLFormulaControl.setFolderUrlForFonts(@"C:\ Program Files \ MiKTeX 2.9 \ tex \ latex");fmath.controls.MathMLFormulaControl.setFolderUrlForGlyphs(@"C:\ Program Files \ MiKTeX 2.9 \ tex \ latex");mathMLFormulaControl1.Contents = "<math><mtext>新公式</mtext></math>";} 

但是,当尝试运行此命令时,最后一行给出了错误:"WinMathML.dll中发生了'fmath.ZP'类型的未处理异常".查看错误的详细信息(尽管无法完全理解它),我猜想那是因为它找不到胶乳字体文件,因为出现了消息:找不到文件'C:\ Program Files \MiKTeX 2.9 \ tex \ latex \ fonts.properties".我尝试了各种文件夹位置,不仅是示例中看到的位置,而且仍然遇到相同的错误.

我已经搜查了好几个小时,却一无所获,而对于C#来说,这是新手,很难理解这些错误的含义以及如何纠正这些错误.

在解决此错误方面的任何帮助或指导,或者找到一种在winforms应用程序中渲染乳胶的方法,将不胜感激.

编辑1

这是异常的堆栈跟踪:

fmath.GN.aS中的

 (String jaa,String kaa)在fmath.GN.XR(布尔gaa,字符串nX)在fmath.GN.UR(Z DX)在fmath.MathMLFormula.drawFormula(String tX)在fmath.controls.MathMLFormulaControl.BuildCanvas()在fmath.controls.MathMLFormulaControl.set_Contents(字符串值)在FMathTest.Form1.Form1_Load(Object sender,EventArgs e)中的C:\ Users \ MyName \ Documents \ Visual Studio 2015 \ Projects \ FMathTest \ FMathTest \ Form1.cs:line 24在System.Windows.Forms.Form.OnLoad(EventArgs e)在System.Windows.Forms.Form.OnCreateControl()在System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)在System.Windows.Forms.Control.CreateControl()在System.Windows.Forms.Control.WmShowWindow(Message& m)在System.Windows.Forms.Control.WndProc(Message& m)在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)在System.Windows.Forms.Form.WmShowWindow(Message&m)在System.Windows.Forms.Form.WndProc(Message& m)在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)处在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)处在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 

解决方案

我遇到了同样的问题,这是我使用的一个 hack:(顺便说一句,我使用的是 VS 2015.)我通过查看它来工作fmath的下载页面上提供的C#测试项目: http://www.fmath.info/java/download.jsp .在项目的根目录中,它们具有两个文件夹: fonts glyphs .我将它们复制到项目的根目录,并且我的代码(与您的代码非常相似)起作用.

另一方面,在显示Latex时,请确保在设置 Contents 字符串之前将 latex 标志设置为true:

  mathMLFormulaControl1.latex = true;mathMLFormulaControl1.Contents = @"\(x ^ 2 + 3 \)"; 

否则将引发不同的异常!

Background: Beginner, just started with C#

I'm making a C# WinForms application, on which I'd like to display well laid out mathematical expressions. To me, I would guess using latex would be the best way to do this. The issue I'm having is finding how latex can be rendered inside a winforms application. Searching around, I found FMath, however I can't get a simple working example of it functioning.

I've installed the library and the new control (MathMLFormulaControl) and added a control to the project. Upon the form loading, the following is done:

private void Form1_Load(object sender, EventArgs e)
    {
        fmath.controls.MathMLFormulaControl.setFolderUrlForFonts(@"C:\Program Files\MiKTeX 2.9\tex\latex");
        fmath.controls.MathMLFormulaControl.setFolderUrlForGlyphs(@"C:\Program Files\MiKTeX 2.9\tex\latex");
        mathMLFormulaControl1.Contents = "<math><mtext>New Formula</mtext></math>";
    }

However, when trying to run this, the last line gives the error: "An unhandled exception of type 'fmath.ZP' occurred in WinMathML.dll". Looking at the details of the error (although not being able to understand it completely), I guessed it was because it could not find the latex font files, since there was the message: "Could not find file 'C:\Program Files\MiKTeX 2.9\tex\latex\fonts.properties'.". I've tried various folder locations, not just the one seen in the example, and still got the same error.

I've been googling for hours and haven't got anywhere, and being new to C# it's difficult to understand what these errors mean and how to rectify them.

Any help or direction in fixing this error, or finding a way to render latex inside a winforms application, would be greatly appreciated.

EDIT 1

Here is the stack trace of the exception:

at fmath.GN.aS(String jaa, String kaa)
at fmath.GN.XR(Boolean gaa, String nX)
at fmath.GN.UR(Z DX)
at fmath.MathMLFormula.drawFormula(String tX)
at fmath.controls.MathMLFormulaControl.BuildCanvas()
at fmath.controls.MathMLFormulaControl.set_Contents(String value)
at FMathTest.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\MyName\Documents\Visual Studio 2015\Projects\FMathTest\FMathTest\Form1.cs:line 24
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

解决方案

I've had the same problem, and here's a hack I used: (Btw I'm using VS 2015.) I got it to work by looking at the C# test project provided on fmath's download page: http://www.fmath.info/java/download.jsp. In the project's root directory, they have the two folders: fonts and glyphs. I copied these to my project's root directory, and my code (very similar to yours) worked.

On another note, when displaying Latex, ensure you set the latex flag to true before you set the Contents string:

 mathMLFormulaControl1.latex = true;
 mathMLFormulaControl1.Contents = @"\(x^2+3\)";

Otherwise a different exception is thrown!

这篇关于在 C# WinForms 上获取 Latex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆