AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-272373

user1509669's questions

Martin Hope
user1509669
Asked: 2019-07-28 00:42:37 +0800 CST

仅当 tex 文件有参考书目时,Makefile 才运行 bibtex 命令

  • 0

我想要一个包含任意数量的 .tex 文件的文件夹,我将在其中拥有一个 Makefile,它会在make运行时为每个 .tex 文件生成一个 .pdf 文件。我的限制是一些但不是所有的 .tex 文件都有参考书目。带有参考书目的 .tex 文件将有条件地使用 bibtex 工具生成 .bbl 文件,以在最终 .pdf 文件中构建参考。这是必需的,因为如果 bibtex 没有找到文本中引用的参考书目,它将返回错误代码并中止构建过程。下面是生成文件的建议解决方案,它不起作用,因为 ifneq 没有​​评估 FILE_BIBS 的值。

Makefile(注意:四个空格应该用制表符代替,否则解释器将无法正常工作)

SOURCES:=$(wildcard $(SRC_DIR)*.tex)
BIBS:=$(wildcard $(SRC_DIR)*.bib)
OUTPUT:=$(patsubst %.tex, %.pdf, $(SOURCES))

.PHONY: all
all: $(OUTPUT) 

# Build procedure for all .tex files
%.pdf: %.tex $(BIBS) 
    pdflatex $(patsubst %.tex, %, $<) > /dev/null
    # Scan the current .tex file for the phrase \bibliography and put the text
    # into a variable called FILE_BIBS, if there is no bibliography phrase in 
    # the file, FILE_BIBS will be empty
    $(eval FILE_BIBS=$(shell grep -m 1 '^[[:space:]]*\\bibliography[[:space:]]*{' $< | sed 's/\\//g' | sed 's/{//g' | sed 's/}//g'))
    echo $(FILE_BIBS)
    # If there are .bib files in the project 
ifneq ($(BIBS),)
    echo "there are bibs FILE_BIBS: $(FILE_BIBS)"
    # See if FILE_BIBS is not empty (the file uses a bibliography)
ifneq ($(FILE_BIBS),)
    # This should print out for outline.tex and not for outline2.tex
    # This does not print out in either case
    echo "file has bib"
    bibtex $(patsubst %.tex, %, $<) > /dev/null
    pdflatex $(patsubst %.tex, %, $<) > /dev/null
endif
endif
    pdflatex $(patsubst %.tex, %, $<) > /dev/null

.PHONY: clean
clean:
    -rm -f *.pdf *.log *.out *.aux *.dvi *.blg *.bbl 

大纲.tex

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apa}

\begin{document}

Types of integration \cite[81-82]{INCOSE-Handbook}.

\bibliography{references}{}

\end{document}

大纲2.tex

\documentclass{article}

\begin{document}

Hello.

\end{document}

参考文献.bib

@BOOK{INCOSE-Handbook,
  TITLE = {Systems Engineering Handbook},
  SUBTITLE = {A guide for system life cycle processes and activities},
  AUTHOR = {Walden, David D. and Roedler, Gerry J. and Forsberg, Kevin J. and Hamelin, R. Douglas and Shortell, Thomas M.},
  YEAR = {2015},
  PUBLISHER = {Wiley},
  EDITION = 4,
  ADDRESS = {7670 Opportunity Rd., Suite 220 San Diego, CA, USA 92111-2222}
}

输出

$ make 
pdflatex  outline2 > /dev/null
echo 
echo "there are bibs FILE_BIBS: "
there are bibs FILE_BIBS: 
pdflatex  outline2 > /dev/null
pdflatex  outline > /dev/null
echo bibliographybibliography
bibliographybibliography
echo "there are bibs FILE_BIBS: bibliographybibliography"
there are bibs FILE_BIBS: bibliographybibliography
pdflatex  outline > /dev/null

我们希望在构建大纲时看到 bibtex 调用,但我们没有。这表明第二个 ifneq 工作不正常。

Makefile 不起作用,因为第二个ifneq不起作用,当FILE_BIBS非空时评估 true。建议应允许用户通过运行在文件夹中构建所有 .tex 文件,make建议解决方案之外的新解决方案应仅使用命令行interface、make、pdftex、bibtex 和 Unix/Linux 环境中的标准工具,例如 awk、sed、grep。

make latex
  • 1 个回答
  • 337 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve