Sphinx文档,编号图引用

时间:2013-02-22 18:09:01

标签: python latex python-sphinx restructuredtext docutils

我正在尝试使用latexpdf输出将编号数字用于我的Sphinx文档项目。我安装了https://bitbucket.org/arjones6/sphinx-numfig

中的Sphinx numfig.py扩展程序

但是,每当我使用:num:标签时,它应该提供一个交叉引用,而不是数字,而是获取以下内容

RST

.. _fig_logo:


.. figure:: logo.*

        Example of a figure

Reference to logo :num:`figure #fig_logo`

生成输出:

参考徽标图 ??

我做错了吗?

1 个答案:

答案 0 :(得分:6)

似乎如果您的标签名称中有下划线(如fig_logo中所示),则sphinx将其替换为减号(-,这是有道理的,因为乳胶在下划线的情况下有时表现得很奇怪),而引用仍然使用下划线。 因此,乳胶无法找到所引用的标签。

这是由sphinx生成的结果tex代码:

\includegraphics{logo.png}
\caption{Example of a figure}\label{index:fig-logo}\end{figure}

Reference to logo \hyperref[index:fig_logo]{figure  \ref*{index:fig_logo}}

(请注意fig-logo作为标签与fig_logo之间的差异作为参考。)

如果用例如减号替换下划线

.. _fig-logo:


.. figure:: logo.png

        Example of a figure

Reference to logo :num:`figure #fig-logo`

tex代码如下所示:

\includegraphics{pandas_bar.png}
\caption{Example of a figure}\label{index:fig-logo}\end{figure}

Reference to logo \hyperref[index:fig-logo]{figure  \ref*{index:fig-logo}}

并在生成的pdf中将其解析为

参考徽标图1

更新

如果您不想更改所有标签,可以更新numfig:添加该行

就足够了
target = target.replace('_', '-')

在您的扩展程序副本中的27行前面。

我在bitbucket上打开了issue