Sphinx documentation, reference to numbered figures

I am trying to get numeric numbers 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, which should provide a cross reference with a digit number, I get the following

first

.. _fig_logo: .. figure:: logo.* Example of a figure Reference to logo :num:`figure #fig_logo` 

Generates output:

Logo link

Am I doing something wrong?

+6
source share
1 answer

It seems that if you have an underscore in the label name (for example, in fig_logo ), sphinx replaces it with a minus sign ( - this makes sense, since latex sometimes behaves strangely in cases with underscore), while the link is still uses an underscore. For this reason, latex cannot find the tag 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 a label and fig_logo as a link.)

If you replace the underscore with a minus sign, for example

 .. _fig-logo: .. figure:: logo.png Example of a figure Reference to logo :num:`figure #fig-logo` 

tex code is as follows:

 \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 pdf file it is allowed

Logo Link 1

Update

If you don't want to change all the shortcuts you can update numfig : this is enough to add a line

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

before line 27 in your copy of the extension.

I opened issue on a bitbucket.

+6
source

All Articles