UCL / ucl-latex-thesis-templates

UCL LaTeX thesis templates.
Other
162 stars 108 forks source link

hyperref links broken #2

Open uccasco opened 10 years ago

uccasco commented 10 years ago

When compiling I was getting errors such as:

pdfTeX warning (dest): name{cite.whatever} has been referenced but does not exist, replaced by a fixed one

meaning that the links in the PDF just went to the first page.

To fix this, I found that adding: \usepackage{natbib}

before the line \usepackage{bibitem} did the trick.

I haven't found that this causes any other issues, so you might want to make this change on the repo.

ikirker commented 10 years ago

I haven't used \usepackage{bibitem} anywhere, that I can find. Are you sure you don't mean \usepackage{bibentry} ?

uccasco commented 10 years ago

Yes sorry I did mean \usepackage{bibentry}. My bad!

ikirker commented 10 years ago

Hmmm, I can't reproduce this. If you get the chance, can you send me the .log file? I'm wondering if it might be a difference between our versions.

ikirker commented 10 years ago

I still haven't managed to reproduce this with a small variety of LaTeX installations on various systems. If you let me know what kind of platform (OS, how you installed LaTeX on it) I might have better luck, but until then I'm not sure whether I should throw in natbib. It might be a sensible default inclusion anyway, given that some people might want to cite things in the way natbib allows in their theses.

uccasco commented 10 years ago

Sorry for the late reply... I'm currently running Linux Mint 13 and I installed LaTeX from the repo.

I don't know what the cause of this bug is, but I know it must occur in other instances as I got the idea to try natbib off stackexchange (I think). Perhaps the best thing would be just to include a comment in the source code that says if you're experiencing these problems, try including natbib...?

owainkenwayucl commented 10 years ago

That's quite an old Linux Mint although it is an LTS - possibly this is a problem resolved in later distro LaTeX packages?

ikirker commented 10 years ago

Have added as a known issue in the README and the MainPackages as suggested, but I'll try and throw those up in a VM and see what happens.

vixg commented 9 years ago

Hi - I'm trying to use this template for my thesis (UCL PhD student). I'm using Miktex under Winows 7 - I cant get the bibliography to link - even in your example main.tex file. I added the natbib package as suggested...here are the log warnings... Package natbib Warning: Citation example-citation' on page 8 undefined on input line 4. Package natbib Warning: Citationexample-citation' undefined on input line 6.

and it doesn't insert the bibliography ...any ideas of how to fix this would be really appreciated.

ikirker commented 9 years ago

(@vixg 's issue was taken care of via email)

TWAnthony commented 6 years ago

@ikirker I'm seeing the same kind of problem, what was the solution? I get it regardless of whether natbib is used.

Log: "This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex) ... LaTeX Warning: Citation `example-citation' on page 8 undefined on input line 4.

LaTeX Warning: Citation `example-citation' undefined on input line 6."

ikirker commented 6 years ago

@TWAnthony I think I didn't put vixg's problem+solution in here because it was unrelated to the issue above: I can't find the email now (that's not "I'm in a hurry", it's "it's not where I think it should be") but I think it may have simply been that they weren't running pdflatex the multiple times it needs to build the list of references and then insert the references into the document correctly on the subsequent runs.

TWAnthony commented 6 years ago

Okay- no worries. I've done a little more digging, and it seems like the problem is on my end (I've not yet worked out what). It's definitely not that I haven't multiple times, though.

da5nsy commented 5 years ago

Hi! The solution of using natbib works for me, but I dislike the natbib styles and would prefer the standard BibTex ones. Any suggestions? I'm working through Overleaf with pdfLaTeX

ikirker commented 5 years ago

@da5nsy I can't reproduce the error compiling the template on Overleaf, unfortunately. If you can send me your source -- or share it with me on Overleaf, if you prefer, I guess -- I'll see if I can work something out. (Email address in the README but remove the +GH.)

da5nsy commented 5 years ago

Thank you! Have given Overleaf access.

ikirker commented 5 years ago

@da5nsy I don't see the error at the top of this thread anywhere in your log output: could you clarify what the problem you're seeing is?

da5nsy commented 5 years ago

@ikirker - thanks for taking a look. The problem - when I comment out \usepackage{natbib} in MainPackages (which I've now done), the hyperlinks from the references fail to send the user to the bibliography. See the test reference I've put in at the start of LargeSphere (currently page 23). I recall also seeing the error that the OP saw, but now cannot see it (Of course - since I've been using natbib, there's now a huge number of errors generated by the usage of citet and citep, so they could just be hiding). A minor thing which I've just noticed, which may well be related, is that when you click on Bibliography in the contents page it doesn't take you there (it goes to the section immediately previous, Colophon in my case).

da5nsy commented 5 years ago

@ikirker - I've created a clone on Overleaf and invited you to that one so that I can keep working on the main doc and so that you can more agressively fiddle with the other one should that be useful. I've kicked you off the old one and invited you to the new one 'Thesis (Copy for working out referencing)'.

ikirker commented 5 years ago

@da5nsy Thanks, that's a good idea.

ikirker commented 5 years ago

Okay, note to self: the Bibliography link is broken because of the manual toc entry addition: at the moment, it happens before the bibliography section is generated, including the clear page and the rest. If you remove it from Main and uncomment the version in the cls file, it's in a better place.

Unfortunately this doesn't fix the other problem.

ikirker commented 5 years ago

Okay, I have a fix -- it's not ideally neat, but it does the job.

LinksAndMetadata.tex

%%
%% This file uses the hyperref package to make your thesis have metadata embedded in the PDF, 
%%  and also adds links to be able to click on references and contents page entries to go to 
%%  the pages.
%%

% Some hacks are necessary to make bibentry and hyperref play nicely.
% See: http://tex.stackexchange.com/questions/65348/clash-between-bibentry-and-hyperref-with-bibstyle-elsart-harv
% See also: hyperref documentation section on bibentry, 9.1.7, p39
% This is the first half of the bibentry/hyperref hack
% The second half is just after begin{document} in Main.tex
\makeatletter
    \let\saved@bibitem\@bibitem
\makeatother
\usepackage{bibentry}
% v-- this setup can be useful for checking links
%\usepackage[bookmarks,colorlinks=true,backref,hyperindex,debug,pdftex]{hyperref}
% v-- and this is the serious setup
\usepackage[bookmarks,pdftex,hidelinks]{hyperref} 

\AtBeginDocument{
    \hypersetup{
        anchorcolor=purple,
        citecolor=green,
        pdfsubject={A thesis upon the subject of Museum Lighting, Colour Constancy and Melanopsin.},
        pdfkeywords={Museum Lighting, Colour Constancy, Chromatic Adaptation, Melanopsin},
        pdfauthor={Daniel Garside},
        pdftitle={Museum Lighting, Colour Constancy and Melanopsin},
    }
}

% Creates hyperlinks automatically from DOIs, and allows for use of \doi{} rather than \url{} which means it can handle non-allowed characters in DOIs.
\usepackage{doi}

And in Main.tex, replace the line with just \nobibliography* with:

    \begingroup
        % This is the second half of the hack in LinksAndMetadata.tex
        % See hyperref documentation section on bibentry, 9.1.7, p39
        % I tried to move this to AtBeginDocument or AfterEndPreamble (requires etoolbox package)
        %  but there were errors I didn't understand.
        \makeatletter
        \let\@bibitem\saved@bibitem
        \nobibliography*
        % ^-- This is a trick that works with the bibentry package to let
        %  you put bibliography entries whereever you like.
        % I used this to put references to papers a chapter's work was 
        %  published in at the end of that chapter.
        \makeatother
    \endgroup

Ideally I'd like to move that section out of the way and into the LinksAndMetadata.tex, in something like an AtBeginDocument or AfterEndPreamble hook, but trying to do that at the moment gets me a bunch of cryptic errors that suggest I need to protect something more or possibly that some necessary definitions are not in scope.

da5nsy commented 5 years ago

Thanks @ikirker. I've implemented all that on my live version and it seems to be working. :raised_hands:

However, for a future hypothetical person, I note that re-enabling natbib now removes the contents page entry.

da5nsy commented 5 years ago

As a more general thing - I don't need full reference lines inline. Thus, as I understand it, I could live without the bibentry package, which seems to be the source of considerable difficulties in this template (which you have valiantly spent a great deal of time and energy on fixing).

With this in mind, I'm going to fiddle around and make a fork which doesn't use bibentry. I'll let you know how I get along. Let me know if this exists already.

da5nsy commented 5 years ago

With this in mind, I'm going to fiddle around and make a fork which doesn't use bibentry. I'll let you know how I get along. Let me know if this exists already.

If anyone wants the nuclear option (getting rid of bibentry): https://github.com/da5nsy/ucl-latex-thesis-templates/commit/ee9c8402aa8eb1fc32cb6db3bf52456bd94ba29b

ikirker commented 5 years ago

It's there right now because the template originates from an abstraction of my own thesis, which used it (as the comment implies). You're right that it might be better to remove it for simplicity and save some information somewhere about fixing it if you need it. I'll try to make a decision and fold the result in when I'm not spinning as many plates.