gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:26:19 25 4
gpt4 key购买 nike

有没有人在他们的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com