我建议使用我的WPF-Math分支.我已经联系了原始的WPF-Math作者,现在正式维护现代框架库.实际上,它的形状非常好.
这是一个重要但不完整的解决方案,因为WPF-Math只是一个渲染,而不是完整的公式编辑器.
存在一些选择:
wpf-math这是一个将基于数学的TeX渲染到WFP的API,并且有一些有限的代码可以将Expression
和转换为TeX。
另一个选择是使用MS Word,它具有一些相当先进的功能,可以将常规数学公式作为简单的字符串,并以漂亮的格式呈现它们。这是使用该功能的一些代码。
public class FormulaImageConverter: IDisposable
{
private Guid _guid;
private Application _wordApp;
private Document _doc;
private Range _range;
private string _saveName;
private string _extractPath;
public FormulaImageConverter(Application wordApp)
{
_wordApp = wordApp;
_guid = Guid.NewGuid();
string guidToString = _guid.ToString("N");
string saveNameBase = System.IO.Path.Combine(System.IO.Path.GetTempPath(), guidToString);
_saveName = saveNameBase + ".html";
_extractPath = saveNameBase + @"_files\image002.gif";
_wordApp.Visible = false;
_doc = _wordApp.Documents.Add();
_range = _doc.Range();
_range.Text = "5";
_doc.OMaths.Add(_range);
}
public byte[] ConvertFormulaToImage(string eq)
{
_range.Text = eq;
_doc.OMaths.BuildUp();
_doc.SaveAs(_saveName, WdSaveFormat.wdFormatHTML,Type.Missing,Type.Missing,false,Type.Missing,null,false);
return System.IO.File.ReadAllBytes(_extractPath);
}
public void Dispose()
{
_range = null;
_doc = null;
_wordApp.Documents.Close(WdSaveOptions.wdDoNotSaveChanges);
((_Application)_wordApp).Quit(false);
_wordApp = null;
System.IO.File.Delete(_saveName);
for (int i = 0; i < 2; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
Run Code Online (Sandbox Code Playgroud)