.tex 文件中同时编译多个 ShellEscape

.tex 文件中同时编译多个 ShellEscape

我一直在做一个项目,在这个项目中,我将一个文档编译成不同的 .pdf,这要归功于我发现的一个技巧。在我的 .tex 文件中,我创建了一个空的 .pdf,以便借助 luacode 让 LaTeX 满意,然后我连续打开三个 Shell,要求使用不同的参数编译当前文档,并输出具有不同名称的 .pdf 文件。

我的主要问题是:是否可以\ShellEscape同时运行不同的文件,以便为较大的项目赢得编译时间。目前,由于线性结构,第二个文档仅在第一个文档完成后才开始编译。

我的第二个问题是:是否可以在编译结束时删除 \jobname.pdf,而不会让 LaTeX 不高兴?

我的代码:

\documentclass{standalone}

\RequirePackage{luacode}
\RequirePackage{shellesc}

%Creating an empty pdf to make LaTeX happy
\ifx\conditionmacro\undefined
  \begin{luacode*}
    function create_empty_pdf()
      local pdf_file = io.open(tex.jobname .. ".pdf", "wb")
      pdf_file:write("%PDF-1.5\n%%\n%%EOF")
      pdf_file:close()
    end
    create_empty_pdf()
  \end{luacode*}
\fi

\ifx\conditionmacro\undefined
\newcommand{\runlualatex}[2]{%#1=file name  ; #2=macro value ; ShellEscape > compiling document and defining \conditionmacro
\ShellEscape{%
  lualatex  --interaction=nonstopmode --halt-on-error --shell-escape --jobname="\jobname#1"
  "\gdef\string\conditionmacro{#2}\string\input\space\jobname"
}%
\ShellEscape{%
  lualatex  --interaction=nonstopmode --halt-on-error --shell-escape --jobname="\jobname#1"
  "\gdef\string\conditionmacro{#2}\string\input\space\jobname"
}%
\ShellEscape{%
  lualatex --interaction=nonstopmode --halt-on-error --shell-escape --jobname="\jobname#1"
  "\gdef\string\conditionmacro{#2}\string\input\space\jobname"
}%
}%
\fi

%Creating three .pdf \jobname-fileX
\ifx\conditionmacro\undefined
\runlualatex{-file1}{macro1}
\runlualatex{-file2}{macro2}
\runlualatex{-file3}{macro3}
\expandafter\stop
\fi

\begin{document}

Value of the \conditionmacro

\end{document}

答案1

如果可能的话,我建议使用 Lua(如何做到这一点是一个 Lua 编程问题,我认为例如https://stackoverflow.com/q/9480315/5267751有答案)

但如果你想使用 TeX,也是可以的:

\documentclass{article}
\begin{document}

\ExplSyntaxOn

% allocate new streams
\ior_new:N \__vince_tmpa_ior
\ior_new:N \__vince_tmpb_ior
\ior_new:N \__vince_tmpc_ior

% spawn processes
\ior_shell_open:Nn \__vince_tmpa_ior {sleep~2s; touch~a1.pdf}
\ior_shell_open:Nn \__vince_tmpb_ior {sleep~2s; touch~a2.pdf}
\ior_shell_open:Nn \__vince_tmpc_ior {sleep~2s; touch~a3.pdf}

% wait for processes to finish
\ior_close:N \__vince_tmpa_ior
\ior_close:N \__vince_tmpb_ior
\ior_close:N \__vince_tmpc_ior

\ExplSyntaxOff

\end{document}

如果对编译进行计时,则仅需要 2 秒。

相关内容