繁体   English   中英

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

[英]Use Sphinx to make a bibliography in a latex document

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

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

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

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

我最后得到了一个编号的章节,称为“参考书目”,然后是两页之后的实际“参考书目”。

乳胶 pdf 文件目录的副本

我想要实现的是“参考书目”的目录标题,并且指向参考书目而没有额外的空白页。

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

1.使用两个不同的“索引”重组文本文件

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

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

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

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

   section_1
   section_2
   section_3
   bibliography

对于乳胶输出, 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

笔记

将 Sphinx .. only::指令与单个index.rst文件一起使用,如下所示不起作用 具体来说, latex文件会缺少内容。 这可能是由于.. only::指令的问题。

===============
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:: 指令,如下所示:

.. 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

为我解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM