Sphinx文档,编号图引用

Joh*_*acs 6 python latex restructuredtext docutils python-sphinx

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

但是,每当我使用:num:标签时,它应该提供与图形编号I的交叉引用,而不是得到以下内容

RST

.. _fig_logo:


.. figure:: logo.*

        Example of a figure

Reference to logo :num:`figure #fig_logo`
Run Code Online (Sandbox Code Playgroud)

生成输出:

参考徽标图

难道我做错了什么?

bmu*_*bmu 6

似乎如果您的标签名称中有下划线(如in 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}}
Run Code Online (Sandbox Code Playgroud)

(注意fig-logo标签和fig_logo参考之间的区别.)

例如,如果用负号替换下划线

.. _fig-logo:


.. figure:: logo.png

        Example of a figure

Reference to logo :num:`figure #fig-logo`
Run Code Online (Sandbox Code Playgroud)

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}}
Run Code Online (Sandbox Code Playgroud)

并在生成的pdf中解析为

参考徽标图1

更新

如果您不想更改可以更新的所有标签numfig:添加该行应该足够了

target = target.replace('_', '-')
Run Code Online (Sandbox Code Playgroud)

就在你的扩展名副本第27行之前.

我在bitbucket上打开了一个问题.