249

The hyperref documentation says: "Make sure it comes last of your loaded packages". The reason is that it redefines many LaTeX commands. It's a rule of thumb that helps to avoid errors.

However, there are exceptions, for instance the amsrefs user's guide notes that amsrefs has to be loaded after hyperref.

To avoid problems when adding hypertext functionality: do you know further such exceptions?

Werner
  • 603,163
Stefan Kottwitz
  • 231,401
  • 70
    Someone should write a package that takes a set of package names and loads them in the best order. Not me, though. – Jim Hefferon Feb 09 '12 at 01:02
  • 5
    My template (http://foundry.supelec.fr/gf/project/latextemplate/) tries to do exactly this. It is full of \ExecuteAfterPackagesequences. Although I have to check with all the packages meantioned here! – Matthias Pospiech Apr 25 '12 at 18:25
  • @MatthiasPospiech, could you please repost your template? The link seems dead. – user1202136 Aug 23 '13 at 09:55
  • 6
    Indeed, I changed the repository. It is now available for download at https://code.google.com/p/latexthesistemplate/downloads/list – Matthias Pospiech Aug 24 '13 at 15:04
  • 2
    @JimHefferon: Done by mhelvens: http://tex.stackexchange.com/q/123174/4918 – Tobi Mar 07 '14 at 01:38
  • 5
    @JimHefferon there’s the pkgloader package: i’ve only speed-read the docs, but it looks a good step towards automation for the job. (i assume it’s a never-ending process, keeping it up-to-date, but it's looking good.) – wasteofspace Sep 03 '14 at 20:46
  • The recent link of the template by @matthias-pospiech is http://www.matthiaspospiech.de/latex/vorlagen/allgemein/ – koppor Jun 04 '16 at 23:03
  • 2
    @Koppor: That is correct the repository however is (again changed, since google shut down code.google) https://github.com/pospiech/latex – Matthias Pospiech Jun 07 '16 at 10:25

15 Answers15

137
  • cleveref

Many others are documented in section 11.1 of the hyperref manual. Some are more complex than simply loading after hyperref. Here are some more common ones...

  • amsrefs
  • float before hyperref before algorithm
  • chappg
  • sidecap
  • linguex
FxMySz
  • 3
Lev Bishop
  • 45,462
  • 3
    Thanks, also for pointing to the README. hyperref has an extensive README. Though, some packages like cleveref, breakurl and others mentioned here weren't listed there. I'll check and perhaps send a note to the author, perhaps he would like to add them. – Stefan Kottwitz Aug 17 '10 at 10:56
  • 1
    Good idea to contact the author. Heiko is generally very responsive about this things. – Lev Bishop Aug 17 '10 at 16:56
  • Thanks for improving my answer by adding the packages with options! (I already gave +1 to your answer, thus I cannot "more-upvote" here.) – Stephen Feb 09 '12 at 18:50
  • 3
    As a note, sidecap no longer has to be loaded after hyperref (as of 2002/05/24 v1.5h according to the linked document.) – Canageek Mar 28 '12 at 22:41
  • 8
    I really think that this is an example of one of the weaknesses of LaTex. Very frustrating behavior. – Nicholas Hamilton Dec 09 '12 at 05:31
96

and probably also further packages with \RequirePackage{hyperref}. A quick search in TeX Live 2011 resulted in this list:

Packages with \RequirePackage[<some option(s)>]{hyperref}:

Stephen
  • 14,890
  • 1
    According to texdoc geometry, it should read: With mag <> 1000... I have edited the reply. – krlmlr Mar 21 '12 at 13:19
  • @user946850: Yes, there is a "not equal" sign in the pdf which died during copy & paste. Thanks for the correction! – Stephen Mar 22 '12 at 19:11
  • 1
    This may not be necessary any more for showkeys, as hyperref now has support for showkeys. See pages 207-208 of hyperref.pdf. – Ari Brodsky Feb 26 '14 at 21:02
  • 2
    Well, I'm partly wrong. \bibitem doesn't show its key if showkeys is loaded before hyperref. On the other hand, \autopageref gets broken if showkeys comes after hyperref. What to do? Maybe a bug report. – Ari Brodsky Feb 26 '14 at 21:42
  • could you update this to texlive 2017, if there are any changes? – Jonas Stein Jul 03 '17 at 09:40
53

Other common ones include

  • bookmark
  • glossaries
  • 1
    Thanks! glossaries isn't even mentioned in manual or README. bookmark is recommended in the manual though without telling the loading order. – Stefan Kottwitz Aug 17 '10 at 11:02
  • 6
    Hi Stefan, although glossaries can be loaded before hyperref, you have to jump through extra hoops to make it work quite as well. Nicola isn't terribly explicit about this in her glossaries manual, although in her only coded snippet involving hyperref she loads glossaries 2nd of all (see p. 69). For me, I've achieved much better results with glossary autohyperlinks loading the two packages in this order too. – Geoffrey Jones Aug 17 '10 at 11:34
  • 8
    @Stefan: Actually, the glossaries manual has this to say: “If you load the hyperref or html packages prior to loading the glossaries package, commands such as \glslink and \gls […] will automatically have hyperlinks …” – Konrad Rudolph Aug 17 '10 at 12:02
22

I experienced problem with the package ellipsis when loaded before hyperref.

In addition, as Joseph Wright writes here, https://tex.stackexchange.com/a/64605/9632, cmap has to be loaded after hyperref.

Sveinung
  • 20,355
16

The tabularx package is definitely one of the candidates. Otherwise links to footnotes are prevented.

  • 3
    tabularx should be loaded after or before hyperref? I'm loading it before and doesn't seem to give me any errors, and both documentations say nothing about it... – Mario S. E. Apr 24 '13 at 08:37
  • 3
    I doubt this is valid. Could you provide proof? – Werner Jul 25 '15 at 01:02
  • I can verify that tabularx, loaded before hyperref causes trouble when you use footnotes in tables that are put inside a minipage. – HATEthePLOT Oct 02 '17 at 18:22
  • Since loading tabularx/xltabular after hyperref the warning "pdfTeX warning (ext4): destination with the same identifier (name{table.X.X}) has been already used" is gone, too. – coreuter Jul 29 '20 at 06:45
11

cleveref is one.

Leo Liu
  • 5,445
10

minitoc

From the minitoc documentation (section 2.17 Using the hyperref package with minitoc; emphasis added):

Since version #31, minitoc works correctly with the powerful hyperref package [...] If you add the loading of the hyperref package to a document yet using minitoc, you will get error message about spurious closing braces. Just let finish the LaTeX run, then re-LaTeX the document. There will be no problem if you remove the loading of hyperref and add it again: the problem occurs only when upgrading from minitoc #30 to minitoc #31 (or higher) with a document already processed and adding hyperref at the same time! It seems better to process the document with minitoc #31 (or higher) without hyperref, then with hyperref, because some internal commands written into the auxiliary files have been modified. If used, the hyperref package must be loaded before minitoc.

Werner
  • 603,163
10

Although not mentioned in its manual,

  • footnotebackref

loads hyperref without options before beginning its work. On that account, it might make better sense in documents to load footnotebackref second of the two.

Nikki
  • 642
9

One more is

To quote its README:

Allows hyperref package and the natbib package with options numbers and sort&compress to work together. This means that multiple sequential citations (e.g [3,2,1]) will be compressed to [1-3], where the '1' and the '3' are (color-)linked to the bibliography.

koppor
  • 3,252
Simon
  • 4,262
  • 12
    As far as I can tell, hypernat is obsolete. You shouldn't load it either after or before hyperref. With modern versions of natbib and hyperref the sort&compress works and is linked without loading any other packages. – Lev Bishop Aug 23 '10 at 09:03
  • 1
    You're right... that's one less package I can load now. – Simon Sep 01 '10 at 04:47
8

I had some funny behaviour with pgfpages until I moved it after hyperref, but I'm not sure exactly what the issue was. I'm trying to replicate it, but I can't seem to get it to work at all now!

Seamus
  • 73,242
7

Another package is apacite.

See also http://promberger.info/linux/2009/03/18/latex-using-apacite-and-hyperref-in-the-same-document/

7

Status in 2024

There are still loading order requirements, either because hyperref must overwrite a command or because other packages (like cleveref) wants to overwrite hyperref definitions.

But LaTeX offers now various tools (like the hook management) to avoid such loading order dances and they should not be viewed as inevitable fate but as something that can (and should) be repaired. For example amsmath already can also be loaded after hyperref.

Report issues!

So if there is some issue: open an issue at the hyperref github, or ask here with a concrete example.

Ulrike Fischer
  • 327,261
6
  • ocgx2

Besides providing commands for the creation and manipulation of PDF Layers (officially named Optional Content Groups), this package re-implements hyperref's ocgcolorlinks option.

\usepackage{hyperref} % do NOT set [ocgcolorlinks] here!
\usepackage[ocgcolorlinks]{ocgx2}

This kind of coloured hyperlinks make use of PDF Layers in order to appear highlighted in the PDF viewer, but which are printed out on paper in the normal colour of the surrounding text, which is usually black.

As opposed to the original hyperref implementation, longer (ocg-)coloured links made with ocgx2 are allowed to wrap around line endings and page breaks.

AlexG
  • 54,894
2

It may be late answer (more a tip), but it cost me a lot to find out, so let me add a tip for other Brazilian users which for some documents must use the regional standard package abntex2cite.

abntex2cite must always be after hyperref. If abntex2cite is placed before hyperref, then the .bbl file will have errors and the references won't be properly written. The references are the main (if not only) reason to use abntex2cite.

\usepackage{hyperref}
\usepackage[alf]{abntex2cite}   % Normas ABNT - Always after hyperref
FHZ
  • 3,939
  • 2
    abntex2cite is unsupported and deprecated for years. the way to go now is biblatex-abnt. –  Mar 08 '20 at 01:02
  • 1
    I agree abntex2cite is unsupported and old and so on. I've tested biblatex with abnt of my own, It works fine and is the way to go ... The real problem is I just don't know how to convence people like my advisor to use biblatex instead of bibtex AND at the same time correctly use the regional standard. Although he insists to use natbib, but natbib just doesn't write references and citations properly for all (many useless) cases. And in 2018 there was a huge update at the norms, which means more potential issues to deal. – FHZ Mar 08 '20 at 02:16
  • as far as I know, biblatex-abnt does implement all abnt rules for references. natbib is just useless either with abntex2cite or with biblatex. The 2018 update wasn't that huge, either. –  Mar 08 '20 at 09:26
  • About the "hugeness". The 2002 version had 24 pages and the 201 version has 68. To my librarian it was "the hugest", but I've seen only some minor relevant changes (removing "< >" for urls is the main one in my opinion), but it takes some time to review all new examples. On the other hand, there are still people coming to me asking about their thesis/dissertation that must be on LaTeX and they've always used Word and sometimes their templates use the even older abnt.bst etc. In this scenario, changing from bibtex to biblatex seems a "little too big" step for many people. – FHZ Mar 08 '20 at 15:23
  • I doubt all those examples are really significant. Nobody cares, or if they care, they're really faking being advisors or committee members. At least with biblatex you can get in touch with people here on tex.stackexchange or even with the package writer himself if you need some extra functionality (besides all the extras biblatex provides already), whereas with bibtex you're basically stuck on your own. Anyway, good luck for ye all. –  Mar 08 '20 at 18:51
  • where is it said that abntex2cite has been deprecated in favor of biblatex-abnt? – Daniel Diniz Aug 17 '22 at 23:19
  • 1
    @DanielDiniz, Read the section "3 O novo pacote biblatex" at CTAN abntex2cite. You still may use abntex2cite and abntex-alf.bst, but you will need to edit them in order to achieve the standard given by ABNT NBR 6023:2018 and ABNT NBR 10520:2002. – FHZ Aug 18 '22 at 00:04
  • 1
    Read this small summary to understand what have changed between versions. If you're gonna choose biblatex updated to the 2018 version, you're gonna need to download files from GitHub biblatex. If you're gonna keep abntex2cite, you may ask me for files and/or details of implementation – FHZ Aug 18 '22 at 00:08
  • 1
    hm, I see. well, in any case, AFAIK pretty much every brazilian college claims to follow ABNT but follows instead a weird mix of ABNT and arbitrary in-house rules. my school (IFCH/Unicamp) uses "rules" from the 90's... so it's a bit radical to say that abnt2cite has been deprecated, when its defaults still handle 90% of its users' needs – Daniel Diniz Aug 18 '22 at 00:24
  • Strictly speaking, the "correct" use should be always following the newest version of each applied norm. Nevertheless, as I guess you read the abntex2cite section 4, there are very talented people in our universities (I'm also grad student from Unicamp) that just don't care or don't know about it. People will often follow the rules they have in their minds in opposition to check the actual standards. Our problem with both packages is that none of them are maintained anymore. Biblatex crew didn't update to CTAN the changes they did. Abntex stopped updating a long time ago. – FHZ Aug 18 '22 at 00:59
2

If hyperref comes before titlesec it produces the warning "The anchor of a bookmark and its parent's must not be the same" at \subsection and \subsubsection when using overleaf

Bamboo
  • 163