shiblon / latex-makefile

A Makefile for LaTeX - drop it in, type make, and magic happens.
Other
186 stars 30 forks source link

latex should be run once more if there is natbib + hyperref back-references #62

Closed shiblon closed 8 years ago

shiblon commented 8 years ago

Originally reported on Google Code with ID 49

Hi,

Back-references are hyper links in the bibliography that return to pages
that have citations. The problem is that if I use natbib to order the
citations with hyperref back-references, the Makefile doesn't run latex
enough times to make it happen.

The problem is that neither hyperref nor natbib will warn you that you need
to re-run so 
1. I just submitted a bug to the maintainers of the packages
2. In the mean time, I suggest a new macro to be added which would be
triggered if FORCED_ADDITIONAL_LATEX_PASS is on or something. That can
always come handy for somebody else later.

Below is an example demonstrating the bug. Note that the bug happens with
bibtex too. Observe how a magical link appears after the item in the
bibliography if you compile twice.

Also, please note that .brf files are generated by the hyperref package
while processing the tex file so they should probably be added to the
auxiliary clean targets.

That's all :D

===========================
\documentclass{article}
\usepackage[sectionbib,square,sort,compress]{natbib}
\usepackage[pagebackref=true]{hyperref}
\begin{document}
a citation:~\cite{lamport94}
\begin{thebibliography}{9}
\bibitem{lamport94}
  Leslie Lamport,
  \emph{\LaTeX: A Document Preparation System}.
  Addison Wesley, Massachusetts,
  2nd Edition,
  1994.
\end{thebibliography}
\end{document}

Reported by fdemesmay on 2009-11-07 08:22:51

shiblon commented 8 years ago
Actually, it is even easier to just unroll the last iteration of the loop...
The whole world is going to compile once more but who cares, it's so much faster than
dvitops and pstopdf that it really doesn't matter....

my fix:

    if [ x"$$run" = x"1" ]; then \
        $(call remove-files,$@.1st.make); \
        for i in 2 3 4 5; do \
            $(if $(findstring 3.79,$(MAKE_VERSION)),\
                $(call echo-build,$*.tex,$@,$$$$i),\
                $(call echo-build,$*.tex,$@,$$i)\
            ); \
            $(call run-latex,$*); \
            $(call test-run-again,$*) || break; \
        done; \
+        $(if $(findstring 3.79,$(MAKE_VERSION)),\
+            $(call echo-build,$*.tex,$@,$$$$i),\
+            $(call echo-build,$*.tex,$@,$$i)\
+        ); \
+        $(call run-latex,$*); \
   else \
        $(MV) $@.1st.make $@; \
    fi; \

Reported by fdemesmay on 2009-11-07 08:45:39

shiblon commented 8 years ago
Oh, one probably needs to add the following line too :)

 i="final";\

Reported by fdemesmay on 2009-11-07 10:14:38

shiblon commented 8 years ago
Interesting idea in general, but this patch concerns me a bit.  It turns out that an
extra 
invocation of LaTeX is only cheap in some circumstances.  If building a beamer 
presentation or a large dissertation, it's a huge pain in the neck.

I'll take a look and see if there is some way we can figure out that an extra run is

needed automatically.

Reported by shiblon on 2009-11-07 19:36:09

shiblon commented 8 years ago
It's fixed upstream and issues a rerun warning now.

From Oberdiek: "In case of backref: To improve the situation I have updated to 1.29:
It adds a rerun warning in case of pdfTeX/LuaTeX based on the MD5 sum
and the file size."

I couldn't check the code yet since it's not public but I will test it against the
latex-makefile. Note that .brf files still need to be replaced though.

Reported by fdemesmay on 2009-11-14 10:44:36

shiblon commented 8 years ago
typo: 
.brf files still need to be deleted though.

Reported by fdemesmay on 2009-11-14 10:45:19

shiblon commented 8 years ago
Awesome that you got it fixed upstream.  The brf deletion is fixed in r631595c796da.

Also in version 2.1.36, available as a download.

Reported by shiblon on 2009-11-15 05:01:37

shiblon commented 8 years ago
I confirm that it works with the new upstream code, including deletion of .brf files.

Just for reference, the new warnings look like this:

Package hyperref Warning: Rerun to get outlines right
(hyperref)                or use package `bookmark'.

Package backref Warning: Rerun to get bibliographical references right.

Reported by fdemesmay on 2009-11-15 09:51:48

shiblon commented 8 years ago
OK - just to confirm, then.  The makefile is properly detecting this new rerun warning

from the upstream fix, and running enough times now?

Reported by shiblon on 2009-11-15 15:20:15

shiblon commented 8 years ago
Yes it is.

Reported by fdemesmay on 2009-11-15 16:09:28

shiblon commented 8 years ago
Excellent - marking verified.

Reported by shiblon on 2009-11-15 16:32:38