What does "\pdfendlink ended up in different nesting level than \pdfstartlink" mean?
Some background to this error (warning)
As their names suggest, the \pdfstartlink
and \pdfendlink
commands are used to create hyperlinks within TeX/LaTeX-generated PDF files—for example, links to different pages within the PDF file or links to websites. These commands are so-called primitives: low-level commands built into TeX engines—they are not macros. As a consequence, most users do not encounter them directly but use them indirectly via macros (commands) provided by packages such as hyperref
.
At the time of writing (December 2022) \pdfstartlink
and \pdfendlink
are supported by just two TeX engines: pdfTeX and LuaTeX (and LuaHBTeX). Historically, both pdfTeX and LuaTeX generated an error message of the form
\pdfendlink ended up in different nesting level than \pdfstartlink
in response to low-level problems related to the depth of box-nesting. Note that the text of this message originates deep within TeX engine software, it is not produced by any LaTeX package nor, of course, by Overleaf.
Starting with TeX Live 2021, pdfTeX and LuaTeX diverged in their handling of the underlying (box nesting) issue and now exhibit different behaviour:
- pdfTeX now issues that message as a warning, it no longer triggers an error and compilation does not terminate;
- LuaTeX (LuaHBTeX) continues to treat this issue as a fatal error, causing compilation to terminate—the wording of that error message differs slightly from the one given above.
Readers wishing to further explore the underlying cause of this error can:
- which compiles successfully with pdfLaTeX but triggers the error with LuaLaTeX;
- browse an in-depth technical discussion on GitHub, conducted between leading TeX and LaTeX experts.
At a practical level, what causes it?
At the user level, this warning (or error) can be triggered when using the hyperref
package and a hyperlink—such as a citation, URL or cross-reference—breaks across two pages or two columns in a multi-column document; i.e., the link starts near the end of one page (or column) and ends on the next page (or column).
As discussed, pdfTeX (pdfLaTeX) with TeX Live 2021 or later no longer generates an error but, at the time of writing (December 2022), LuaLaTeX continues to do so. If you are using LuaLaTeX, a temporary workaround whilst working on your document is to disable hyperlinks by writing
\hypersetup{draft}
just before your
\begin{document}
Although this prevents hyperlinks from appearing in your document, it avoids the error whilst writing and, when you're ready to compile the final document, you can comment out or delete \hypersetup{draft}
. If you are unlucky enough to still encounter this problem at the final-compilation stage, re-enable the draft
and then go through your PDF to find the possible offender (citations, cross-references, floats at top of pages...), so that you can, hopefully..., find a way to edit/reword your text to avoid the problem.
Further information
If you encounter this issue as a fatal error it can require some detective work to track the precise cause. tex.stackexchange has several discussions but note that some of these pages pre-date pdfTeX's downgrading of the error to a warning:
- https://tex.stackexchange.com/questions/1522/pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink
- https://tex.stackexchange.com/questions/63819/mysterious-error-pdfendlink-ended-up-in-different-nesting-level-than-pdfstart
- https://tex.stackexchange.com/questions/249579/pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink-error-with/
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class