sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.57k stars 2.12k forks source link

numref in LaTeX output is broken #2360

Closed xuhdev closed 8 years ago

xuhdev commented 8 years ago

See this generated pdf file. It should refer Fig 1.1 but it refers Fig 1.

You can view a small example here.

Bisecting shows the culprit commit is 279ac7c23fe2f35025514d64c96f839bd518c786

@tk0miya

tk0miya commented 8 years ago

Thank you for letting me know. I fixed now :-)

andreacassioli commented 8 years ago

Hi guys, it seems the issue still pop up in 1.4. Here is the code

The whole example is in :numref:`doc.opt_server.tutorial_sync_code`.

.. literalinclude:: stripex/test_sync.py
   :caption: How to submit a job and solve the problem synchronously.
   :name: doc.opt_server.tutorial_sync_code
   :language: py

and here is the output screenshot from 2016-04-12 09 32 52

jfbu commented 8 years ago

I can not confirm the problem on current stable. With this index.rst, and numfig = True in the conf.py and suitable file in stripex/test_sync.py :

TEST
====

First Section
-------------

The whole example is in :numref:`doc.opt_server.tutorial_sync_codeA`.

.. literalinclude:: stripex/test_sync.py
   :caption: How to submit a job and solve the problem synchronously.
   :name: doc.opt_server.tutorial_sync_codeA
   :language: py

Second Section
--------------

The whole example is in :numref:`doc.opt_server.tutorial_sync_codeB`.

.. literalinclude:: stripex/test_sync.py
   :caption: How to submit a job and solve the problem synchronously.
   :name: doc.opt_server.tutorial_sync_codeB
   :language: py

The whole example is in :numref:`doc.opt_server.tutorial_sync_codeC`.

.. literalinclude:: stripex/test_sync.py
   :caption: How to submit a job and solve the problem synchronously.
   :name: doc.opt_server.tutorial_sync_codeC
   :language: py

The make latexpdf produces expected output with correct functional Listing 1.1, Listing 2.1 and Listing 2.2 links inside the PDF.

jfbu commented 8 years ago

I aslo tried in my test file after having cyclically permuted the three :numref:foo`` and it all works OK in all cases I tested.

Can you try to produce a minimal example with wrong link being produced?

andreacassioli commented 8 years ago

I will take a closer look and try to make a minimal example.

jfbu commented 8 years ago

You may have duplicate names doc.opt_server.tutorial_sync_code but I guess you have excluded that already.

Having a look at the relevant part of the LaTeX file would help:

  1. the location where there should appear a Listing \ref{foo:doc.opt_server.tutorial_sync_code}
  2. the location where the same doc.opt_server.tutorial_sync_code appears which with current stable should look like \def\SphinxLiteralBlockLabel{foo:doc.opt_server.tutorial_sync_code}.

The latter description applies with very recent Sphinx, as the PR #2415 was merged yesterday. Perhaps you are not on latest stable branch ?

jfbu commented 8 years ago

Perhaps you use names which differ only in casing? I just observed that ids are transformed to lower case at some point. Thus codeA and codea will give same label and this could cause what you observe.

andreacassioli commented 8 years ago

Hi @jfbu , thank you!

I am sure I have no duplicates and I always use lower case names.

In the generated Tex I have

The whole example is in \hyperref[tutorial-sync:doc-opt-server-tutorial-sync-code]{Listing \ref{tutorial-sync:doc-opt-server-tutorial-sync-code}}.

while the literal block contains

\phantomsection\label{tutorial-sync:doc-opt-server-tutorial-sync-code}

I am using the latests version from Pip. actually I run pip every time I build the docs.

jfbu commented 8 years ago

This looks good. More recent version will not have the \phantomsection\label{...}: it is handled differently at the LaTeX side, and more robustly.

Random thoughts:

  1. perhaps your problem will go away once pip version catches up with 1.4.1.
  2. perhaps some TeX package misbehaves.
  3. perhaps pdflatex is not run enough times. You could try go the build repertory, kill the aux file and run manually pdflatex on tex file enough times.
jfbu commented 8 years ago

You mentioned somewhere else using extensions like https://github.com/jterrace/sphinxtr/blob/master/extensions/numsec.py

Is it the case in this problem document ?

andreacassioli commented 8 years ago

Thank again. About your random thoughts:

  1. hopefully!
  2. not sure hoe to figure it out
  3. it runs 4 times, so I guess it should be enough...

and yes, I use numsec in this project.It is fundamental as titles are way too long and clutter the text. But in my understanding should not affect the tex output.

I think the next step is to wait 1.4.1

tk0miya commented 8 years ago

Maybe this is same problem as #2414 and it is fixed at 1.4.1.

If you still get the problem after 1.4.1, please open new issue. because I did not notice discussions on closed issue.

andreacassioli commented 8 years ago

I confirm now it works now, great job!

jfbu commented 8 years ago

very glad to hear that !