> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-wen-zhang/13-getting-started-with-biblatex.md).

# BibLaTeX 入门

**作者：Josh Cassidy（2013年7月）**

多年来，LaTeX 用户一直使用 BibTeX，并配合多个附加宏包，例如 `natbib` 来撰写参考文献。不过，现在有了一个新选择：BibLaTeX。它旨在为你提供更多选项，方便地配置参考文献/引文。很方便的是，现有的 `.bib` 文件为了与 BibLaTeX 配合工作，通常不需要做太多修改。除了 300 多页的 [BibLaTeX 文档](http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf)，CTAN 还有一份有用的 [BibLaTeX“速查表”](http://tug.ctan.org/info/biblatex-cheatsheet/biblatex-cheatsheet.pdf)。为了补充这些资源，这里提供一个视频教程，后面还有一些笔记/示例帮助你入门。

{% embed url="<https://www.youtube.com/embed/nH9If8c5VCs>" %}

### 基本命令和样式

首先，你在 tex 文件中用于将参考文献加入文档的命令与之前相当不同。在导言区中你需要使用以下代码：

```latex
\usepackage{biblatex}
\addbibresource{}
```

第一个命令只是加载 `biblatex` 宏包。第二个用于指定你想使用哪些 bib 文件。你只需在花括号中输入文件名，包括 `.bib` 扩展名。然后在文档正文中，不再使用 `\bibliography` 命令来生成参考文献，而是使用 `\printbibliography` 命令。使用 BibTeX 时，你通过 `\bibliographystyle` 命令来指定参考文献样式。在 `biblatex` 中我们不再使用这个命令，而是通过向 `\usepackage` 命令传入更多参数来指定样式选项。为此我们输入 `style=` 后跟样式名称，放在紧接花括号之前的方括号中。例如：

```latex
\usepackage[style=numeric]{biblatex}
```

或者，如果你想为引文和参考文献分别声明不同的样式，可以使用 `citestyle` 和 `bibstyle`这几个词。示例如下：

```latex
\usepackage[citestyle=alphabetic,bibstyle=authortitle]{biblatex}
```

在继续之前，我会快速展示这些样式在引文和实际参考文献条目中的效果。不过，你可以 [查阅文档](http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf) 了解完整的样式列表。

* 该 `数字` 样式： ![BiBLaTeXnumeric.png](/files/e40df73fff1a28567865e8c3cb73cc20112e2080)-  `字母式` 样式： ![BiBLaTeXalphabetic.png](/files/05c1bcb468bb7b5664e3de0de9a7cfcb735c6044)-  `读法` 样式： ![BiBLaTeXreading.png](/files/c35a922388f605dd4aeec0fa5f725e267d354e3f)-  `作者-年份` 样式： ![BiBLaTeXauthoryear.png](/files/8dcc0b7d82a4cb45f95b5c17cf39ceeb49e1a9b5)

你可以向 `\usepackage` 命令提供的另一个参数是排序选项。例如：

```latex
\usepackage[style=authoryear,sorting=ynt]{biblatex}
```

这将使用作者-年份样式，然后按年份、姓名、标题对参考文献条目排序。以下是一些可用的不同排序选项列表：

* `nty`—按姓名、标题、年份排序条目；
* `nyt`—按姓名、年份、标题排序条目；
* `nyvt`—按姓名、年份、卷、标题排序条目；
* `anyt`—按字母标签、姓名、年份、标题排序条目；
* `anyvt`—按字母标签、姓名、年份、卷、标题排序条目；
* `ynt`—按年份、姓名、标题排序条目；
* `ydnt`—按年份（降序）、姓名、标题排序条目；
* `none`—不排序。条目按其在正文中出现的顺序显示。

如果你没有指定顺序，默认是 `nty`.

### 引文命令

引文命令也在 `biblatex`中进行了全面改造。 `前注` 和 `后注` 作为参数传入：

* a `前注` 是一个像“see”这样的词或短语，会被插入到引文开头；
* a `后注` 是你想插入到引文末尾的文本。

要加入这些注释，你需要在引文命令中使用两组方括号。示例如下：

```latex
\cite[see][page 12]{latexcompanion}
```

在这个示例中，我们已经加载了 `字母式` 样式和 `latexcompanion` 只是引文键。文本中的引用效果如下：

![BiBLaTeXprepost.png](/files/46313168568f091cc8173879e01d7c40ecd2b6e2)

如果你只打开一组方括号，就会假定括号中的内容是一个 `后注`，所以如果你只想要一个 `前注` ，请确保你仍然打开第二组方括号，然后把它留空。

此外，还有许多不同的引文命令可供使用。以下是一些标准命令：

* `\cite`—最基本的一个。除使用 `字母式` 或 `数字` 样式时会使用方括号外，不加任何括号打印；
* `\parencite`—打印带括号的引文，除使用 `字母式` 或 `数字` 样式时会使用方括号外，不加任何括号打印；
* `\footcite`—将引文放入脚注。

### 将参考文献分类

关于 `biblatex` 的一个优点是，你可以按来源类型对参考文献进行分类。以下是按来源类型分类的示例：

```latex
\printbibheading
\printbibliography[type=book,heading=subbibliography,title={Book Sources}]
\printbibliography[nottype=book,heading=subbibliography,title={Other Sources}]
```

在这个例子中，我们将参考文献分成两部分，一部分是书籍来源，另一部分是非书籍来源。示例输出如下：

![BiBLaTeXtypes.png](/files/b5b5336807a5f1a72f154e56cb4d8d4704d77105)

另一种对参考文献分类的方法是使用关键词筛选器。为此，你需要在你的 `关键词` 条目中添加一个 `.bib` 文件。例如：

```latex
@article{key,
	keywords = {keywordA,keywordB,keywordC}
```

下面是按关键词分类的示例：

```latex
\printbibheading
\printbibliography[keyword=major,heading=subbibliography,title={Major Sources}]
\printbibliography[keyword=minor,heading=subbibliography,title={Minor Sources}]
```

对应的输出如下：

![BiBLaTeXmajor.png](/files/5633dac2efb89b2d4a5bc80f2b329f15b045b93a)

看起来有一天，BibTeX 很快就只会成为 LaTeX 历史中的一段篇章了！希望这对你开始使用 BibLaTeX 有所帮助。 `biblatex`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-wen-zhang/13-getting-started-with-biblatex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
