在C#/ WPF应用程序中使用pdflatex.exe将TeX转换为PDF

JTo*_*and 5 c# wpf latex tex pdflatex

是否有人在他们的C#/ WPF应用程序中使用pdflatex.exe从TeX文档创建PDF文档?我有我的TeX文档,我想将其转换为PDF并在应用程序中显示,但是,我不确定如何执行此操作,并且网上几乎找不到关于此类操作的信息。有谁知道做这种事情的最好方法是什么(在C#应用程序中通过pdflatex.exe将TeX文档转换为PDF)?

非常感谢!

Dar*_*ter 4

这是我使用的代码。它假设源代码与可执行文件位于同一文件夹中,并且如果需要,则包括运行 BibTeX(如果需要,只需排除第二个进程)。

string filename = "<your LaTeX source file>.tex";
Process p1 = new Process();
p1.StartInfo.FileName = "<your path to>\pdflatex.exe";
p1.StartInfo.Arguments = filename;
p1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p1.StartInfo.RedirectStandardOutput = true;
p1.StartInfo.UseShellExecute = false;

Process p2 = new Process();
p2.StartInfo.FileName = "<your path to>\bibtex.exe";
p2.StartInfo.Arguments = Path.GetFileNameWithoutExtension(filename);
p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p2.StartInfo.RedirectStandardOutput = true;
p2.StartInfo.UseShellExecute = false;

p1.Start();
var output = p1.StandardOutput.ReadToEnd();
p1.WaitForExit();

p2.Start();
output = p2.StandardOutput.ReadToEnd();
p2.WaitForExit();

p1.Start();
output = p1.StandardOutput.ReadToEnd();
p1.WaitForExit();

p1.Start();
output = p1.StandardOutput.ReadToEnd();
p1.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

是的,这可以稍微清理一下,当然,如果不调用 BibTeX,则可以在循环中调用(建议使用 3 次,以确保所有引用都正确)。此外,没有异常处理,因此您可能需要在进程调用等周围添加 try / catch 块。