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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With