如何从 Mac 中的 Java 程序编译 LaTex 文件

How to compile a LaTex file from Java program in Mac

我正在尝试使用终端命令 latex file.tex 来编译 .tex 文件。我的程序提取字符串上的 .tex 文件的绝对路径:

public void generateLatex(String path)
{
    String file = path;
    //...compile file;
}

有没有办法在给定路径上使用命令?我尝试使用 Process

Process p = Runtime.getRuntime().exec(executable + path);
p.waitFor();

但是没用

您可以使用流程构建器:

ProcessBuilder pb = new ProcessBuilder("latex", "yourlatex.tex")
            .inheritIO()
            .directory(new File("your directory path"));
Process process = pb.start();
process.waitFor();