我正在开发一个用于软件文档的 Sphinx 项目,其中包括很多数字。我使用“numref”来引用图片。在 HTML 中它工作正常。在 LaTex 中,我得到了 Fig. ?? 网上的 numref 只有几个问题,答案对我没有帮助。谁能告诉我我做错了什么?
我使用 sphinx-quickstart 安装了 Sphinx 环境。我的 conf.py 中的相关行是:
# Conf.py
# Automatic numbering
numfig = True
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# Latex figure (float) alignment
# 'figure_align': 'htbp',
'figure_align': 'H' # disable floating
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'PDF_Test.tex', 'PDF generation',
'Niels de Nies', 'manual'),
]
我的来源(index.rst)看起来像:
#########################
Sphinx numref Test
#########################
My first chapter
----------------
The purpose of this test is to get the numref of figures working in LaTex.
Section 1
~~~~~~~~~
.. figure:: ../images/hippo.png
:name: hippo
:numref:`hippo` Hippopotamus
The figure above (:numref:`hippo`) shows an illuminated hippopotamus.
The 'numref' works fine in HTML, but results in Fig. ?? with LaTex
Below the alternative way using a label. The results are exactly the same:
Perfect for HTML, but undefined reference for latexpdf
.. _fig_hippo:
.. figure:: ../images/hippo.png
:name: hippo
:numref:`fig_hippo` Hippopotamus
在命令行 LaTeX 显示:
=== TeX engine is 'pdfTeX'
Latexmk: Index file 'PDF_Test.idx' was written
Latexmk: Log file says output to 'PDF_Test.pdf'
Latexmk: List of undefined refs and citations:
Reference `index:hippo' on page 1 undefined on input line 111
Reference `index:hippo' on page 1 undefined on input line 113
Latexmk: Summary of warnings from last run of (pdf)latex:
Latex failed to resolve 2 reference(s)
Latexmk: All targets () are up-to-date
在生成的 PDF_Test.tex 中,以下几行带来了麻烦:
\hyperref[\detokenize{index:hippo}]{Fig.\@ \ref{\detokenize{index:hippo}}} Hippopotamus
The figure above (\hyperref[\detokenize{index:hippo}]{Fig.\@ \ref{\detokenize{index:hippo}}}) shows an illuminated hippopotamus.
谁能给我一个线索如何解决这个问题?