# Proper references to figures/code/tables/etc.

Georg Brandl created an issue

For things like scientific publications, floating envs like figures, tables and code displays need to be numbered and references must contain these numbers.

Could we also add that the target page number to references is shown, e.g. "(see page xx)". This would be useful for printed documents.

Not sure if this should be added as a separate issue, though.

+1 for me too.

P.S.: I'm also willing to contribute some code, but I may need some coaching for the dev process.

1. Hi, I did a hack because I really needed this behavior for my thesis report. I attach the patch.

The added code check the reference label and if it has '-num' as suffix write a \ref{} as latex output instead a \hyperref

Obviously , it's a dirty thing, but maybe could be a base to a new role like :refnum: or an alternative behavior (settable via conf.py) to :ref: just for figure targets.

I also wrote a post (in Spanish) with a little example of the problem an the result: http://nqnwebs.com/blog/article/referenciar-figuras-por-numero-en

2. For latex I changed by using "\ref" or "\autoref" for internal links. If you want to use "\autoref" or "\ref" could perhaps be switched with a config value, e.g. latex_use_autoref=True.

the patch doesn't work if latex_show_pagerefs is True, but this could easily be adapted.

3. For html I tried this with an extension (see attachment). This works for modification of the figurelabels and the references to figures. But: the figures are not numbered correctly, because every document stands for its own and consistent numbering for the all documents is not possble..

So I don't think this can be changed with an extension, but with something like the method "assign_section_numbers" in class BuildEnvironment.

If there is a dictionary for figures, tables and sections (there is one for sections) in the environment, one could use this to change figure and table captions and references.

by the way: thanks for sphinx. I'm beginning to understand it and I learned a lot.

I just want to add that in the current version of 1.1.2 the pagerefs for tables are set wrong. A phantomsection with the label is created before the tabular environment so that all references point to the page where the reference is set not to the page where the table is printed in LaTeX.

sphinxtr implements of some of this functionality.

Perhaps portions will be useful in a sphinx-core implementation.

Edit: For completeness of the sphinxtr reference: libmunin-thesis forked sphinxtr, refactored and extended functionality.