[英]Use Sphinx to make a bibliography in a latex document
下面显示了两种不同的方法,它们在 Sphinx 的html和latex输出中创建了一个参考书目部分。
1.使用两个不同的“索引”重组文本文件
在 Sphinx html和latex输出中创建参考书目部分的一种方法使用两个索引重组文本文件。
对于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 。 这种方法对html和latex输出使用相同的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.