【问题标题】:Consecutive commands using Ubuntu makefile to compile latex project使用 Ubuntu makefile 编译 Latex 项目的连续命令
【发布时间】:2021-02-28 23:21:33
【问题描述】:

我正在尝试使用 Makefile 创建 LaTeX 项目。我似乎无法让操作顺序正常工作

DISSERTATION = Dissertation
TEX = pdflatex -synctex=1 -interaction=nonstopmode --shell-escape 
BIBTOOL = biber
OPEN = open -a Skim.app
RESOURCES = ${DISSERTATION}.pdf

###### Targets #####

# compile the LaTeX document
tex:
    ${TEX} ${DISSERTATION}

# create bibliography file for LaTeX
bib:
    ${BIBTOOL} ${DISSERTATION}

# Order of operations (LaTeX --> biber -->  LaTeX --> LaTeX)
order: tex bib tex tex

# Second attempt
file:
    ${TEX} ${DISSERTATION}
    ${BIBTOOL} ${DISSERTATION}
    ${TEX} ${DISSERTATION}
    ${TEX} ${DISSERTATION}

clean:  
    rm -rf auto *_minted-* *.log *.aux *.synctex.gz *.out *.toc *.run *.bcf *.lof *.lot *.tdo *.run.xml *.pdf *.bbl *.blg
    
release:
    rm -rf Release
    mkdir Release
    cp *.pdf Release
    make clean

我目前在终端中输入make order,它只编译一次tex文件并退出。它不会调用 biber 来创建用于重新排序引用的引用。

我还尝试了命令make file,它只是将它们整理好,它做同样的事情。在第一个命令 ${TEX} ${DISSERTATION} 之后退出。

这里是相关的终端错误信息:

(see the transcript file for additional information){/usr/share/texlive/texmf-d
ist/fonts/enc/dvips/base/8r.enc}</usr/share/texlive/texmf-dist/fonts/type1/publ
ic/amsfonts/cm/cmex10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/ams
fonts/cm/cmmi10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/
cm/cmr10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy
10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/mathpazo/fplmr.pfb></u
sr/share/texlive/texmf-dist/fonts/type1/public/mathpazo/fplmri.pfb></usr/share/
texlive/texmf-dist/fonts/type1/urw/palatino/uplb8a.pfb></usr/share/texlive/texm
f-dist/fonts/type1/urw/palatino/uplr8a.pfb></usr/share/texlive/texmf-dist/fonts
/type1/urw/palatino/uplri8a.pfb>
Output written on Dissertation.pdf (70 pages, 9452807 bytes).
SyncTeX written on Dissertation.synctex.gz.
Transcript written on Dissertation.log.
make: *** [Makefile:14: tex] Error 1

但是,当我单独执行命令时,这确实有效!即make tex --> make bib --> make tex --> make tex

make releasemake clean 命令完美运行。

我不确定我在这里做错了什么。由于我对 Linux 的了解有限,我很难过。如果有人知道,请告诉我。谢谢!

【问题讨论】:

  • Makefile 的编写方式存在一些基本问题,但即使我们要解决这些问题,由于需要运行多次传递,为 LaTeX 项目获取正确的 Makefile 仍然很棘手的某些命令。我想您可能想通读this question 的答案,其中会更详细地探讨这一切。
  • 感谢您的帮助!我使用他们答案中的参考资料之一更新了我的 Makefile。希望我写得正确。我会把它作为这个问题的答案发布。如果您对如何正确编写它有任何建议,那就太好了。

标签: ubuntu makefile


【解决方案1】:

这是我更新的 Makefile,似乎解决了我上面提到的问题。我必须下载 latexmk 以解决多个编译步骤以正确顺序获得引用。

# Linux Makefile to create a final pdf of the project

# Variables
FILE = Dissertation

# PDF LaTeX specific
PDFLATEX = "pdflatex -interaction=nonstopmode -synctex=1 --shell-escape"

# You want latexmk to *always* run, because make does not have all the info.
# Also, include non-file targets in .PHONY so they are run regardless of any
# file of the given name existing.
.PHONY: ${FILE}.pdf all clean

# The first rule in a Makefile is the one executed by default ("make"). It
# should always be the "all" rule, so that "make" and "make all" are identical.
all: ${FILE}.pdf

# CUSTOM BUILD RULES

# In case you didn't know, '$@' is a variable holding the name of the target,
# and '$<' is a variable holding the (first) dependency of a rule.
# "raw2tex" and "dat2tex" are just placeholders for whatever custom steps
# you might have.

%.tex: %.raw
    ./raw2tex $< > $@

%.tex: %.dat
    ./dat2tex $< > $@

# MAIN LATEXMK RULE

# -pdf tells latexmk to generate PDF directly (instead of DVI).
# -pdflatex="" tells latexmk to call a specific backend with specific options.
# -use-make tells latexmk to call make for generating missing files.

# -interaction=nonstopmode keeps the pdflatex backend from stopping at a
# missing file reference and interactively asking you for an alternative.

# --shell-escape allows for *minted to run code highlighting

# -f forces latexmk to run until compiling has been complete regardless of
#  cross referencing (i.e. it continues to run until references are in the
#  correct location)

${FILE}.pdf: ${FILE}.tex
    latexmk -pdf -pdflatex=${PDFLATEX} -f -use-make ${FILE}.tex

# Clean up unnecessary files
clean:
    latexmk -C
    # specific to latexmk

clear:  
    rm -rf auto *_minted-* *.log *.aux *.synctex.gz *.out *.toc *.run *.bcf *.lof *.lot *.tdo *.run.xml *.pdf *.bbl *.blg

release:
    rm -rf Release
    mkdir Release
    cp *.pdf Release
    make clear
    make clean

谢谢!

【讨论】:

  • 您的答案应该是严格的答案。 %.pdf: %.tex 指定从 tex 文件中创建 pdf 文件的规则,其中词干可以是任何东西。在配方中,$* 扩展为词干,$@ 扩展为您正在制作的目标,等等;有关详细信息,请参阅 Make 文档。
  • 我会编辑它,所以我不会以问题结束。谢谢!
  • 所以配方应该是%.pdf: %.tex(换行符)(制表符)latexmk -pdf -pdflatex=${PDFLATEX} -f -use-make $&lt;,它告诉Make如何从foo.tex制作foo.pdf,从bar.tex制作bar.pdf等。这条规则不是.PHONY,所以你应该删除它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-26
  • 1970-01-01
  • 1970-01-01
  • 2021-11-23
相关资源
最近更新 更多