我正在尝试简化/改进Makefile以编译我的论文.Makefile可以很好地编译整个文件; 我有这样的事情:
show: thesis.pdf
open thesis.pdf
thesis.pdf: *.tex
pdflatex --shell-escape thesis
Run Code Online (Sandbox Code Playgroud)
这允许我键入make并检测任何更改(如果有)并在显示之前重新编译.
现在我想将它扩展为有条件地编译单个章节.例如,这允许我编写make xpmt以只有一种方式获得一个章节:
xpmt: ch-xpmt.pdf
open ch-xpmt.pdf
ch-xpmt.pdf: xpmt.tex
pdflatex --shell-escape --jobname=ch-xpmt \
"\includeonly{xpmt}\input{thesis}"
Run Code Online (Sandbox Code Playgroud)
但是我不想为每个章节写下相同的内容.如何以足够的方式编写上述规则以避免重复?
(更多的练习是学习如何编写Makefile而不是解决任何真正的问题;显然在这种情况下复制和粘贴上面的代码实际上很简单!)
如果你有一个名为章xpmt(猜测这是"实验"?),并说,thry,anls,conc,或什么:
xmpt thry anls conc: %: ch-%.pdf
open $<
ch-%.pdf: %.tex
pdflatex --shell-escape --jobname=ch-$* "\includeonly{$*}\input{thesis}"
Run Code Online (Sandbox Code Playgroud)
或者用make变量做"正确"的方式,我认为它是这样的:
chapters = xmpt thry anls conc
main = thesis
.PHONY: $(chapters) show
show: $(main).pdf
open $<
$(main).pdf: $(main).tex $(addsuffix .tex,$(chapters))
pdflatex --shell-escape $(main)
$(chapters): %: ch-%.pdf
open $<
ch-%.pdf: %.tex
pdflatex --shell-escape --jobname=ch-$* "\includeonly{$*}\input{$(main)}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4468 次 |
| 最近记录: |