将独立 tex 文件与 latxmk 结合时的最佳实践

将独立 tex 文件与 latxmk 结合时的最佳实践

我目前不确定如何最好地定义我的工作流程,并希望得到一些关于如何最好地进行的建议。也许我只是忽略了一些显而易见的事情。

假设有以下tinker.tex文件:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{image.tex}
    \documentclass[margin=1cm]{standalone}
    \begin{document}
        Hello world
    \end{document}
\end{filecontents}

\usepackage{graphicx}
\begin{document}
    \includegraphics{image.pdf}
\end{document}

并对其进行编译,latexmk -pdf -interaction=nonstopmode tinker.tex我期望通过运行 latex 编译步骤从现有图像中创建图像image.tex。但这并没有发生。

丢失的文件已被正确检测到(Latexmk: Missing input file 'image.pdf' [...]),因此我希望依赖项处理能够跳转到它?

有没有“正确”的方法来实现这一点?对于svg通过 inkscape 转换为 pdf 的文件,我有这种确切的行为。这使用自定义依赖项和自定义系统调用。我预计 latex 依赖项已经存在,还是需要从头开始定义?


我喜欢这样做,因为这样可以轻松地分别处理图像/图形,直到它们看起来正确,并且还可以将它们作为单独的文件供以后使用。

我知道我standalone也可以在根文档中加载包,并使用\includestandalone它甚至可以编译子文档。这需要传递,-shell-escape这可能不安全。但更重要的是,我希望latexmk已经能够做到这一点。所以这更多的是为了理解为什么它不起作用,而不是如何解决它

答案1

您需要定义自定义依赖项才能从 tex 文件创建 pdf 文件:

add_cus_dep( 'tex', 'pdf', 0, 'makeexternaldocument' );
sub makeexternaldocument {
    my ($base_name, $path) = fileparse( $_[0] );
    return system "latexmk", "-output-directory=$path", $_[0];
}

相关内容