Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx Documentation, numbered figure references

I'm trying to get numbered figures to work on my Sphinx documentation project using latexpdf output. I installed the Sphinx numfig.py extension found here https://bitbucket.org/arjones6/sphinx-numfig

However, whenever I use the :num: tag that is supposed to provide a cross reference with the figure's number I instead get the following

rst

.. _fig_logo:


.. figure:: logo.*

        Example of a figure

Reference to logo :num:`figure #fig_logo`

Generates output:

Reference to logo figure ??

Am I doing something wrong?

like image 600
John Lotacs Avatar asked Feb 22 '13 18:02

John Lotacs


1 Answers

Seems that if you have an underscore in your label name (like in fig_logo) sphinx replaces this with a minus (-, this makes sense as latex sometimes behaves strange in cases whit underscores), while the reference still uses the underscore. For that reason latex can not find the label referenced.

This is the resulting tex code generated by sphinx:

\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}}

(Note the difference between fig-logo as label and fig_logo as reference.)

If you replace the underscore by a minus for instance

.. _fig-logo:


.. figure:: logo.png

        Example of a figure

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

the tex code looks like this:

\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}}

and in the pdf generated this is resolved to

Reference to logo figure 1

Update

If you don't want to change all the labels you can update numfig: it should be sufficient to add the line

target = target.replace('_', '-')

just before line 27 in your copy of the extension.

I opened an issue on bitbucket.

like image 182
bmu Avatar answered Sep 20 '22 23:09

bmu