title: Getting Latex on C# WinForms
body: <p>Background: Beginner, just started with C#</p>
  
  <p>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 <a href="http://www.fmath.info/" rel="nofollow noreferrer">FMath</a>, however I can't get a simple working example of it functioning.</p>
  
  <p>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:</p>
  
  <pre><code>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 = "&lt;math&gt;&lt;mtext&gt;New Formula&lt;/mtext&gt;&lt;/math&gt;";
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>Any help or direction in fixing this error, or finding a way to render latex inside a winforms application, would be greatly appreciated.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is the stack trace of the exception:</p>
  
  <pre><code>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&amp; m)
  at System.Windows.Forms.Control.WndProc(Message&amp; m)
  at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
  at System.Windows.Forms.Form.WmShowWindow(Message&amp; m)
  at System.Windows.Forms.Form.WndProc(Message&amp; m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
  at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  </code></pre>