跳轉到內容

LaTeX/使用 biblatex 和 biber 建立參考文獻

來自華夏公益教科書,自由的教科書,面向自由的世界

瞭解如何使用現代 biblatex 和 biber 建立參考文獻 - 簡短教程。

這只是一個關於 biblatex 和 biber 主要且最常用功能的簡短概述,以便建立參考文獻。更詳細的資訊可以在包文件中找到。


資料庫

[編輯 | 編輯原始碼]

使用 biblatex 和 biber 建立參考文獻意味著將所有可用的參考文獻資訊儲存在一個簡單的基於文字的資料庫中。名稱應儘可能唯一,例如 lauraPhd2016.bib。這在與您的顧問、學生或同事傳輸檔案時很有幫助。biber 用於處理資料庫。

樣本資料庫檔案可能如下所示

@article{wombat2016,
	author   = {Walther Wombat and Klaus Koala},
	title    = {The true meaning of 42},
	journal  = {Journal of modern skepticism},
	date     = {2016},
	keywords = {trusted},
}
@book{lion2010,
	author       = {Laura Lion and Gabrielle Giraffe and Carl Capybara},
	title        = {The dangers of asking the wrong question},
	publisher    = {publishing house},
	date         = {2010},
	keywords     = {trusted},
}
@online{wikibook,
	title        = {Generating Bibliographies with biblatex and biber},
	organization = {Wikibooks},
	date         = {2016},
	urldate      = {2016-03-07},
	url          = {https://wikibook.tw/wiki/LaTeX/Generating_Bibliographies_with_biblatex_and_biber},
	keywords     = {untrusted},
}

資料庫中的每個條目都以 @ 符號開頭,後面跟著條目型別。還有更多型別可用,包文件列出了所有型別。每個條目的參考文獻資訊儲存在一對括號中,以該條目的唯一關鍵字 (bibkey) 開頭。最簡單的展示資料的方法是在新行中列出每個欄位型別,內容用花括號括起來,後面跟著一個逗號。您提供資訊的順序並不重要。

請仔細檢視作者,每個作者之間用關鍵字 and 分隔。所有日期都以 YYYY-MM-DD 格式寫,如果其他資訊不可用,則只寫年份。檔案 biblatex-examples.bib 應該與包一起安裝,它包含一些示例條目。

設定 biber

[編輯 | 編輯原始碼]

Biber 是一個輔助程式的名稱,它對條目進行排序,並向 biblatex 包提供所有相關資訊。如果您不習慣使用命令列(也稱為終端),您應該將您的編輯器設定為為您呼叫 biber。設定我的編輯器以使用 biber 展示瞭如何在不同的編輯器中進行設定。


一個簡單的示例

[編輯 | 編輯原始碼]
\documentclass{article}
\usepackage[backend=biber]{biblatex}
\addbibresource{lauraPhd2016.bib}
\begin{document}
I doubt that there is any useful information here~\cite{wikibook}.

All we know is limited, apart from knowing the answer we all know. Or do we? Wombat and Koala have discovered some interesting things~\cite{wombat2016}.

Some people are too nosy. What can happen to them is described by Laura Lion~\cite[9]{lion2010}.

\printbibliography
\end{document}

它究竟是如何工作的?biblatex 包使用 backend=biber 選項載入,然後使用 \addbibresource 將您的資料庫檔案新增到參考文獻檔案列表中。請注意,副檔名是必須的,這發生在文件的前言中。

在文件中,您可以使用 \cite{bibkey} 引用資料庫中的一個條目。您的資料庫可以包含數百個條目,但最終列表中只會出現被引用的參考文獻。您可以使用 \nocite{<bibkey>} 將未引用的條目新增到列表中。如果您想新增資料庫中的所有條目,請使用 \nocite{*}

最後,使用 \printbibliography 列印您的參考文獻列表。

在主文件上執行 LaTeX(無論 latexpdflatex 等)都會導致以下 log 輸出。

LaTeX Warning: Citation 'wikibook' on page 1 undefined on input line 5.

LaTeX Warning: Citation 'wombat2016' on page 1 undefined on input line 7.

LaTeX Warning: Citation 'lion2010' on page 1 undefined on input line 9.

LaTeX Warning: Empty bibliography on input line 11.

[1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./lauraPhd2016Main.aux)

LaTeX Warning: There were undefined references.

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

我們會收到一些關於未定義的參考文獻的警告,沒有參考文獻,並且沒有使用正確的引用,我們只看到用粗體顯示的引用鍵。

The output before the compile chain is completed.

為了真正獲得參考文獻和引用,而不是僅僅獲得臭名昭著的 There were undefined references 警告,您必須在 latex 之後執行 biber 以從資料庫中提取相關資料。在按照 設定我的編輯器以使用 biber 中的說明設定 biber 後,您應該能夠透過在處理文件時按下一個按鈕來做到這一點。為了將參考文獻資訊合併到您的文件中,LaTeX 必須在處理資料之前處理 biber 生成的資料。總而言之,如果您有一個名為 lauraPhd2016Main.tex 的檔案,您(或您的編輯器)將不得不執行以下操作

$ latex lauraPhd2016Main
$ biber lauraPhd2016Main
$ latex lauraPhd2016Main

每次您的資料庫更新時,請務必透過呼叫 biber 來處理資料庫。

完整的結果可以在下面的圖片中看到。請注意,biblatex 包會新增一些小的細節。您能看到一些被列印但未定義的東西嗎?

參考文獻樣式

[編輯 | 編輯原始碼]

不同的科學學科使用不同的參考文獻樣式。總的來說,您可以將它們分為數字參考文獻系統(溫哥華)或作者-日期參考文獻系統(哈佛)。


biblatex 包[1] 提供不同的引用命令,它們生成不同的輸出(文內引用、腳註等)。下面給出了一些示例,包文件包含並解釋了整個集合的使用。


數字參考文獻

[編輯 | 編輯原始碼]

數字參考文獻是預設樣式。文字和參考文獻中都使用方括號內的數字。使用 \autocite 可以輕鬆地將樣式更改為腳註。sorting=none 生成一個按時間順序排序的參考文獻,即數字在文件末尾遞增。

\documentclass{article}
\usepackage[backend=biber,style=numeric,autocite=plain,sorting=none]{biblatex}
\addbibresource{lauraPhd2016.bib}
\begin{document}
I doubt that there is any useful information here.~\cite{wikibook}

All we know is limited, apart from knowing the answer we all
know. Or do we? \citeauthor{wombat2016} have discovered some interesting
things.~\autocite[compare][80]{wombat2016}

What can happen to nosy people is described by \textcite[9]{lion2010}.
\printbibliography
\end{document}

使用 autocite=footnote 會生成不同的輸出。你能發現所有區別嗎?


腳註中的引用

作者-日期參考文獻

[編輯 | 編輯原始碼]

如果您想要作者-日期參考文獻樣式,您可以在載入 biblatex 時使用 style=authoryearautocite 選項與 inline 選項一起使用時,會在使用 autocite 生成的引用周圍新增括號(類似於使用 \parencite)。在某些情況下,當引用是主題並且是句子的一部分時,\textcite 可能會有用。

\documentclass{article}
\usepackage[backend=biber,style=authoryear,autocite=inline]{biblatex}
\addbibresource{lauraPhd2016.bib}
\begin{document}
I doubt that there is any useful information here~\cite{wikibook}.

All we know is limited, apart from knowing the answer we all know. Or do we?~\cite{wombat2016}

Some people are too nosy. What can happen to them is described by Laura Lion~\autocite[9]{lion2010}.

Some people are too nosy. What can happen to them is described by \textcite[9]{lion2010}.

\printbibliography
\end{document}

APA 引用

[編輯 | 編輯原始碼]

美國心理學會 (APA) 定義了一種非常嚴格的作者-年份樣式。您可以使用 style=apa 以及額外定義語言對映來訪問它。

\usepackage[backend=biber,style=apa,autocite=inline]{biblatex}
\DeclareLanguageMapping{english}{english-apa}
\addbibresource{lauraPhd2016.bib}

將輸出與正常的作者-年份樣式進行比較。你能發現多少變化?

按條目型別分離參考文獻

[編輯 | 編輯原始碼]

假設您想要為所有引用的線上資源建立單獨的參考文獻。使用 \printbibliography 的可選引數沒問題。您還可以更改標題(以及其他內容)。

\documentclass{article}
\usepackage[backend=biber,defernumbers=true]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{westfahl:space,aristotle:physics,ctan,baez/online,markey,sigfridsson}
\printbibheading
\printbibliography[heading=subbibliography,type=online,title={All my online references}]
\printbibliography[heading=subbibliography,nottype=online,title={All my non-online references}]
\end{document}

拆分為不同的主題

[編輯 | 編輯原始碼]

您可以將參考文獻拆分為不同的主題,例如可信和不可信的來源,或主要和次要來源。透過向資料庫條目新增 keywords 標籤來告訴 biblatex 這些資訊。

@book{lion2010,
	author       = {Laura Lion and  Gabrielle Giraffe and Carl Capybara},
	title        = {The dangers of asking the wrong question},
	publisher    = {publishing house},
	date         = {2010},
	keywords     = {trusted},
}
\documentclass{article}
\usepackage[backend=biber,style=authoryear,refsection=section]{biblatex}
\addbibresource{lauraPhd2016.bib}
\begin{document}
\cites[see also][12]{wombat2016}[and][45]{lion2010}
\nocite{wikibook}
\printbibliography[keyword={trusted},title={All the trusted sources}]
\printbibliography[keyword={untrusted},title={All the untrusted sources}]
\end{document}

Splitting a biblatex bibiography into different topics using keywords

請注意,資料庫中的條目欄位稱為 keywords(複數),因為您可以擁有多個關鍵字(用逗號分隔)。當呼叫 \printbibliography 命令時,您必須使用單數。biblatex 擁有一個強大的資料過濾系統,更多資訊可以在手冊中找到。

每節或每章的參考文獻

[編輯 | 編輯原始碼]

有些人需要在每章或每節的末尾新增一個參考文獻列表。這可以使用 refsection 完成。

\documentclass{article}
\usepackage[backend=biber,defernumbers=true,refsection=section]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\section{Aster}
\cite{ctan,sigfridsson} and some text
\printbibliography[heading=subbibliography]
\section{Begonia}
\cite{aristotle:physics,markey}
\printbibliography[heading=subbibliography]
\section{Cichorium}
\cite{westfahl:space,baez/online}
\printbibliography[heading=subbibliography]
\end{document}


簡報中的參考文獻

[編輯 | 編輯原始碼]

您可以將 biblatex 包與 beamer 一起使用(請參閱 簡報部分)以在您的簡報中新增引用和參考文獻列表。建議立即使用完整的引用,這樣聽眾就不必等到最後才能看到資訊的來源。

\documentclass{beamer}
\usecolortheme{crane}
\usepackage{biblatex}
\addbibresource{lauraPhd2016.bib}
\begin{document}
\begin{frame}{42}
	Interesting
	\footfullcite{wombat2016}
\end{frame}
\nocite{*}
\begin{frame}{References}
\printbibliography
\end{frame}
\end{document}

A beamer presentation slide containing a citation using package biblatex . A beamer presentation slide containing the reference list using package biblatex .


返回主參考文獻頁面

華夏公益教科書