使用Sphinx在latex文档中创建参考书目
我目前正在使用Sphinx制作一个latex文档。我对参考书目有一些问题。 我希望参考书目出现在目录中,没有章节号 当我将参考书目作为一个单独的部分包含时,例如,使用以下重新构造的文本文件:使用Sphinx在latex文档中创建参考书目,latex,python-sphinx,restructuredtext,bibliography,Latex,Python Sphinx,Restructuredtext,Bibliography,我目前正在使用Sphinx制作一个latex文档。我对参考书目有一些问题。 我希望参考书目出现在目录中,没有章节号 当我将参考书目作为一个单独的部分包含时,例如,使用以下重新构造的文本文件: ************ Bibliography ************ .. bibliography:: NullFeaturesInQGIS.bib :style: plain 最后我写了一个编号的章节,叫做“参考书目”,两页之后是实际的“参考书目” 我想要实现的是一个目录标题“参考书
************
Bibliography
************
.. bibliography:: NullFeaturesInQGIS.bib
:style: plain
最后我写了一个编号的章节,叫做“参考书目”,两页之后是实际的“参考书目”
我想要实现的是一个目录标题“参考书目”,它指向参考书目而不需要额外的空白页。下面显示了两种不同的方法,它们在Sphinx的html和latex输出中创建参考书目部分 1。使用两个不同的“索引”重组文本文件 一种在Sphinx html和latex输出中创建参考书目部分的方法使用两个索引重新构造的文本文件 对于html输出,
index.rst
文件应该如下所示:
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
bibliography
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
************
Bibliography
************
.. bibliography:: bibtex_filename.bib
:style: plain
对于latex输出,index_latex.rst文件应如下所示:
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
bibliography
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
************
Bibliography
************
.. bibliography:: bibtex_filename.bib
:style: plain
书目.rst
文件应如下所示:
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
bibliography
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
************
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
文件并使用。。原始::
指令
下面的内容改编自。这种方法对html和latex输出使用相同的index.rst
文件。index.rst
文件应该与上面显示的html输出相同,并且应该包括对书目.rst
文件的引用。书目.rst
文件需要有。。原始::
指令开头:
.. raw:: latex
\cleardoublepage
\begingroup
\renewcommand\chapter[1]{\endgroup}
\phantomsection
************
Bibliography
************
.. bibliography:: bibtex_filename.bib
:style: plain
注意
使用斯芬克斯。。仅限::
指令和一个index.rst
文件,如下所示不起作用。具体来说,latex文档将丢失内容。这可能是由于
使用狮身人面像。。only::index.rst文件中的指令如下所示:
.. only:: html
************
Bibliography
************
.. bibliography:: bibtex_filename.bib
:style: plain
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
bibliography
并保留一个index.rst文件,如下所示:
.. only:: html
************
Bibliography
************
.. bibliography:: bibtex_filename.bib
:style: plain
===============
Project Heading
===============
.. toctree::
:maxdepth: 2
:caption: Contents:
section_1
section_2
section_3
bibliography
为我解决了这个问题。我猜您使用的是sphinxcontrib bibtex扩展。如果只删除
参考书目
章节标题会发生什么?如果删除参考书目章节标题,我仍然会得到两个空白页面,并且没有任何目录。对于临时解决方案,我有单独的index.rst文件,用于Sphinx的html和latex输出。在html的index.rst文件中,我在目录树(目录)中包含一个带有书目指令的书目部分,在latex的index.rst文件中,我删除了书目部分和书目指令。这给了我我所需要的结果。也许这使用原始乳胶,经过适当调整,可以避免两个分开的index.rst文件(未经测试)。感谢jfbu,它测试了您引用的黑客,并且工作正常。我现在已把它包括在我的答复中。