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

标签 c# wpf latex tex pdflatex

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

非常感谢!

最佳答案

这是我使用的代码。它假定源代码与可执行文件位于同一文件夹中,并在需要时包括运行 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();

是的,这可以稍微清理一下,当然如果不调用 BibTeX 就可以在循环中调用(推荐的次数是 3 次,以确保所有引用都是正确的)。此外,没有异常处理,因此您可能希望在进程调用等周围添加 try/catch block 。

关于c# - 在 C#/WPF 应用程序中使用 pdflatex.exe 将 TeX 转换为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5884789/

相关文章:

c# - 如何从 C# 代码中获取列表到 python 中的列表

c# - 如何检查数据读取器是否为 null 或为空

c# - 使用超链接发送邮件的 ASP.NET 应用程序

c# - 在 XAML 中使用在 Silverlight 代码中创建的静态对象

wpf - 我可以在WPF MVVM应用程序中使用App Domains来缩短启动时间,并且仅在需要时才加载程序集吗?

c# - 对路径 'Global\{xxx}_YYY-YYY:13552' 的访问被拒绝。吊火?

c# - 将数据异步加载到数据网格中

latex - 进入环境时抑制换行

python - wiki/docbook/latex文档模板系统

csv - LaTeX 和 pgf-pie 中 csv 文件的饼图