使用子文件包时,添加参考书目文件的适当位置在哪里?

使用子文件包时,添加参考书目文件的适当位置在哪里?

我正在尝试添加我的博士论文的 bib 文件,但收到一条错误消息,提示我有一个空的参考书目,并且缺少引文。我使用 subfiles 包来拆分各个章节和子章节,这很棒!但是,我希望参考书目能够正常工作,以便显示我的引文。

我的项目当前的文件结构如下:

dissertation/
|-- Dissertation.tex
|-- Dissertation.cls
|-- makefile (Dissertation, release, clean)
|-- Release/
|   |-- Dissertation.pdf
|-- Chapter1/
|   |-- Intro1.tex
|   |-- Methods1.tex
|   |-- Results1.tex
|   |-- Discussion1.tex
|   |-- Conclusion1.tex
|   |-- Figures/
|       | -- Figure1.pdf
|       | -- Figure2.pdf
|       | -- Figure3.pdf
|   |-- bib_files/ 
|       | -- bib1.bib
|   |-- makefile (Chapter1, Intro1, Methods1, release, clean, etc.)
|   |-- Release/
|   |-- | -- Chapter1.pdf
|   |-- | -- Intro1.pdf
|   |-- | -- Methods1.pdf
|-- Chapter2/
|   |-- Intro2.tex
|   |-- Methods2.tex
|   |-- Results2.tex
|   |-- Discussion2.tex
|   |-- Conclusion2.tex
|   |-- bib_files/ 
|       | -- bib2.bib
|   |-- Figures/
|       | -- Figure1.pdf
|       | -- Figure2.pdf
|       | -- Figure3.pdf
|   |-- makefile (Chapter2, Intro2, Methods2, release, clean, etc.)
|   |-- Release/
|   |-- | -- Chapter2.pdf
|   |-- | -- Intro2.pdf
|   |-- | -- Methods2.pdf
|-- AppendixA/
|   |-- AppendixA.tex
|   |-- Code/
|       | -- code1.py
|       | -- code2.m
|       | -- code3.cc
|   |-- Data/
|       | -- Data1.csv
|       | -- Data2.csv
|       | -- Data3.csv

我尝试将以下内容放入我的 main.tex 文件中:

% References
\addbibresource{./Chapter2/bib_files/bibliography.bib}
\addbibresource{./Chapter3/bib_files/bibliography.bib}
\addbibresource{./Chapter4/bib_files/bibliography.bib}

我也尝试过将这些命令放在各个章节中,但也没有用:

%%% -*-LaTeX-*-
\documentclass[../Dissertation]{subfiles}

\graphicspath{{Chapter2/Figures/}} % Graphics path for images
\addbibresource{./Chapter2/bib_files/bibliography.bib} % Chapter 2 references

\begin{document}
    
    % Needs to be capitalized (University Rules)
    \chapter{\uppercase{Chapter title here}}
    
    \hspace{\parindent}
    Experimental data measurement.
    
    \subfile{./Chapter2/0_Abstract}
    \subfile{./Chapter2/1_Introduction}
    \subfile{./Chapter2/2_Methods}
    \subfile{./Chapter2/3_Results}
    \subfile{./Chapter2/4_Discussion}
    \subfile{./Chapter2/5_Conclusion}
    \subfile{./Chapter2/6_Acknowledgment}
    
    % bibliography
    \printbibliography[segment=\therefsegment,heading=references]
    
\end{document}

然而,这些方法都没有成功。

在我的 .cls 文件中,我对参考书目进行了如下定义:

%----------------------------------------------------------------------%
%                               References
%----------------------------------------------------------------------%

\RequirePackage[defernums=true,
                hyperref,
                backref,
                backend=biber,
                style=ieee,
                natbib=true,
                refsegment=chapter,
                block=space
                ]{biblatex} % Use the bibtex backend, biber

\setlength\bibitemsep{1.5\itemsep} % Spacing between items in bilbiography

% Define typesetting of references heading
\defbibheading{references}[References]{% 
    \section{#1}% Add section so that the table of contents adds the chapter references
    \markboth{#1}{#1}%
    \singlespacing
}

%----------------------------------------------------------------------%
%                           Final Bibliography
%   Add type=book, article, online, thesis for specific references
%----------------------------------------------------------------------%

\def\finalBibliography{
    {\singlespacing
    \printbibliography[heading=bibintoc, title={\uppercase{Bibliography}}] % Whole
    }
}

在我的 main.tex 的最后,我调用它\finalBibliography来显示所有使用的引用。

在之前的帖子提供了很多帮助之后,我也使用 Ubuntu 来执行、编译和输出最终的 PDF,我的最终命令是make file

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

# Executables
default:
    ${TEX} ${DISSERTATION}
    ${OPEN} ${DISSERTATION}

# Order of compiling (LaTeX --> biber -->  LaTeX --> LaTeX)
file:
    ${TEX} ${DISSERTATION}
    ${BIBTOOLS} ${DISSERTATION}
    ${TEX} ${DISSERTATION}
    ${TEX} ${DISSERTATION}

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

这里是每个章节/部分的 makefile(特定于第 2 章):

CHAPTER = Chapter2
ABSTRACT = 0_Abstract
INTRODUCTION = 1_Introduction
METHODS = 2_Methods
RESULTS = 3_Results
DISCUSSION = 4_Discussion
CONCLUSION = 5_Conclusion
ACKNOWLEDGE = 6_Acknowledgment

# Tex commands
TEX = pdflatex -synctex=1 -interaction=nonstopmode --shell-escape 
BIBTOOLS = biber
OPEN = open -a Skim.app
RESOURCES = ${CHAPTER}.pdf

# Executables
default:
    ${TEX} ${CHAPTER}
    ${OPEN} ${CHAPTER}

clean:
    rm -rf auto *_minted-* *.log *.aux *.synctex.gz* *.out *.bcf *.run *run.xml *.pdf *.swo *.swp

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

chapter:
    ${TEX} ${CHAPTER}
    ${BIBTOOLS} ${CHAPTER}
    ${TEX} ${CHAPTER}
    ${TEX} ${CHAPTER}
    
file:   
    make chapter
    rm -rf Release
    mkdir Release
    cp ${RESOURCES} Release
    make clean

abstract:
    ${TEX} ${ABSTRACT}
    ${BIBTOOLS} ${ABSTRACT}
    ${TEX} ${ABSTRACT}
    ${TEX} ${ABSTRACT}

introduction:
    ${TEX} ${INTRODUCTION}
    ${BIBTOOLS} ${INTRODUCTION}
    ${TEX} ${INTRODUCTION}
    ${TEX} ${INTRODUCTION}
    
methods:
    ${TEX} ${METHODS}
    ${BIBTOOLS} ${METHODS}
    ${TEX} ${METHODS}
    ${TEX} ${METHODS}

results:
    ${TEX} ${RESULTS}
    ${BIBTOOLS} ${RESULTS}
    ${TEX} ${RESULTS}
    ${TEX} ${RESULTS}

discussion:
    ${TEX} ${DISCUSSION}
    ${BIBTOOLS} ${DISCUSSION}
    ${TEX} ${DISCUSSION}
    ${TEX} ${DISCUSSION}
    
conclusion:
    ${TEX} ${CONCLUSION}
    ${BIBTOOLS} ${CONCLUSION}
    ${TEX} ${CONCLUSION}
    ${TEX} ${CONCLUSION}

acknowledge:
    ${TEX} ${ACKNOWLEDGE}
    ${BIBTOOLS} ${ACKNOWLEDGE}
    ${TEX} ${ACKNOWLEDGE}
    ${TEX} ${ACKNOWLEDGE}

如果您有任何建议,那就太好了。这些命令似乎没有执行参考书目的创建。

以下是错误输出示例:

LaTeX Warning: Citation 'Kita_1992' on page 24 undefined on input line 146.


LaTeX Warning: Citation 'Kita_1990' on page 24 undefined on input line 152.

[24]) (./5_Conclusion.tex [25]) (./6_Acknowledgment.tex)

LaTeX Warning: Empty bibliography on input line 25.

[26] (./Chapter2.aux)

LaTeX Warning: There were undefined references.


Package biblatex Warning: Please (re)run Biber on the file:
(biblatex)                Chapter2
(biblatex)                and rerun LaTeX afterwards.

 )

尝试仅运行 biber 命令来创建参考书目后

BIBTOOLS = biber
bib:
    ${BIBTOOLS} ${DISSERTATION}

我收到此错误消息,但我不知道如何调试它:

biber Dissertation
INFO - This is Biber 2.14 (beta)
INFO - Logfile is 'Dissertation.blg'
ERROR - Cannot find 'Dissertation.bcf'!
INFO - ERRORS: 1
make: *** [Makefile:20: bib] Error 2

答案1

文件的确切位置.bib并不重要。在“正常”(非subfiles)设置中工作的大多数合理事物也适用于subfiles,但您需要考虑工作/编译目录中的更改对相对路径的影响。

你还没有分享太多关于文件夹设置的信息,所以我假设它大致如下

dissertation/
|-- main.tex
|-- chapter1/
|   |-- chap1.tex
|   \-- bib1.bib
|-- chapter2/
|   |-- chap2.tex
|   \-- bib2.bib

并且您maindissertation工作目录编译文件,并从其自己的目录中编译章节(因此cd chapter1,,,,,)。pdflatex chapter1biber chapter1pdflatex chapter1pdflatex chapter1

那么你main.tex应该看起来大致像这样

\documentclass[british]{report}
\usepackage{subfiles}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear, refsegment=chapter,]{biblatex}

\addbibresource{\subfix{chapter1/bib1.bib}}
\addbibresource{\subfix{chapter2/bib2.bib}}

\begin{document}
\subfile{chapter1/chap1}
\subfile{chapter2/chap2}

\printbibliography[title={Complete \refname}]
\end{document}

你的子文件如下

% chap1.tex
\documentclass[../main]{subfiles}

\begin{document}
\chapter{Lorem}
Lorem \autocite{sigfridsson}

\printbibliography[segment=\therefsegment, heading=subbibliography]
\end{document}

% chap2.tex
\documentclass[../main]{subfiles}

\begin{document}
\chapter{Dolor}
Dolor \autocite{nussbaum}

\printbibliography[segment=\therefsegment, heading=subbibliography]
\end{document}

我们必须解决的问题是文件名总是相对于您调用 LaTeX/Biber 的位置进行解析。因此,当您main.tex在 中编译时dissertation,所有文件名都是相对于该目录进行解析的,因此\addbibresource调用需要包含子目录名称chapter1/chapter2/。但是当您chap1.tex从 进行编译时chapter1,文件的相对路径.bib不是chapter1/bib1.bib,而只是bib1.bib。这就是\subfix我们所做的:它修复了子文件自行编译时的文件路径问题。


另一种但不太优雅的方法是明确分支我们是否正在排版主文件或子文件。

main.tex

\documentclass[british]{report}
\usepackage{subfiles}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear, refsegment=chapter,]{biblatex}

\ifSubfilesClassLoaded
  { }
  {
    \addbibresource{chapter1/bib1.bib}%
    \addbibresource{chapter2/bib2.bib}%
  }

\begin{document}
\subfile{chapter1/chap1}
\subfile{chapter2/chap2}

\printbibliography[title={Complete \refname}]
\end{document}

chapter1/chap1.tex

\documentclass[../main]{subfiles}

\addbibresource{bib1.bib}

\begin{document}
\chapter{Lorem}
Lorem \autocite{sigfridsson}

\printbibliography[segment=\therefsegment, heading=subbibliography]
\end{document}

答案2

Makefile感谢大家的评论!长话短说,大家都说对了。然而,执行命令却不起作用。

以下是之前的Makefile

# variables
FILE = Dissertation
TEX = pdflatex -synctex=1 -interaction=nonstopmode --shell-escape 
BIBTOOL = biber

tex:
    ${TEX} ${FILE}
bib:
    ${BIBTOOL} ${FILE}

我注意到,当我拆分每个命令,即make tex然后按make bib然后make tex使其tex起作用时,但运行时间很长且很耗时。

在被指出正确的方向后,程序latexmk用于处理多次编译,以确保引用/图表/参考文献等的顺序正确。对我的 进行此项更改后Makefile,一切似乎都运行良好。

以下是更新内容Makefile

# Linux Makefile to create a final pdf of the project

# Variables
FILE = PhD_Presentation

# 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 *.nav *.snm

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

相关内容