使用Sphinx在latex文档中制作参考书目

Use Sphinx to make a bibliography in a latex document

我目前正在使用 Sphinx 生成乳胶文档。我对参考书目有一些疑问。 我希望参考书目出现在 table 目录中,但没有章节编号。

当我将参考书目作为一个单独的部分包含时,例如使用以下重组文本文件:

************
Bibliography
************

.. bibliography:: NullFeaturesInQGIS.bib
   :style: plain

我最后写了一个编号为 "Bibliography" 的章节,然后是实际的 "Bibliography" 两页之后。

我想要实现的是 table 的内容标题 "Bibliography" 并且指向参考书目而没有额外的空白页。

下面显示了两种不同的方法,它们在 Sphinx 的 htmllatex 输出中创建参考书目部分。

1.使用两个不同的 "index" 重组文本文件

一种在 Sphinx htmllatex 输出中创建参考书目部分的方法使用两个 index 重组文本文件。

对于 html 输出,index.rst 文件应该是这样的:

===============
Project Heading
===============

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   section_1
   section_2
   section_3
   bibliography

对于 latex 输出,index_latex.rst 文件应该是这样的:

===============
Project Heading
===============

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   section_1
   section_2
   section_3

bibliography.rst 文件应该是这样的:

************
Bibliography
************

.. bibliography:: bibtex_filename.bib
   :style: plain

在 Sphinx 配置文件中(例如 conf.py),您需要区分这两个不同的索引文件。例如:

# The html index document.
master_doc = 'index'

# The latex index document
latex_doc = 'index_latex'

2。使用一个 index.rst 文件并使用 .. raw:: 指令

以下内容改编自https://github.com/sphinx-doc/sphinx/issues/4775。此方法对 htmllatex 输出使用相同的 index.rst 文件。 index.rst 文件应与上面显示的 html 输出相同,并且应包含对 bibliography.rst 文件的引用。 bibliography.rst文件开头需要有.. raw::指令:

.. raw:: latex

   \cleardoublepage
   \begingroup
   \renewcommand\chapter[1]{\endgroup}
   \phantomsection

************
Bibliography
************

.. bibliography:: bibtex_filename.bib
   :style: plain

注意

对单个 index.rst 文件使用 Sphinx .. only:: 指令,如下所示 不起作用 。具体来说,latex 文档将丢失内容。这可能是由于 problems with the .. only:: directive.

===============
Project Heading
===============

.. only:: html

   .. toctree::
      :maxdepth: 2
      :caption: Contents:

      section_1
      section_2
      section_3
      bibliography

.. only:: latex

   .. toctree::
      :maxdepth: 2
      :caption: Contents:

      section_1
      section_2
      section_3

仅在 bibliography.rst 文件中使用 Sphinx ..:: 指令,如下所示:

.. only:: html

    ************
    Bibliography
    ************

.. bibliography:: bibtex_filename.bib
   :style: plain

并保留一个 index.rst 文件,如下所示:

===============
Project Heading
===============

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   section_1
   section_2
   section_3
   bibliography

帮我解决了。