> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/wen-da/83-what-does-pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink-mean.md).

# “\pdfendlink ended up in different nesting level than \pdfstartlink”是什么意思？

## 关于此错误（警告）的一些背景

顾名思义， `\pdfstartlink` 和 `\pdfendlink` 这些命令用于在 TeX/LaTeX 生成的 PDF 文件中创建超链接——例如，指向 PDF 文件中不同页面的链接，或指向网站的链接。这些命令被称为 *原语*：TeX 引擎内置的低级命令——它们不是宏。因此，大多数用户不会直接遇到它们，而是通过诸如 `hyperref`.

在撰写本文时（2022年12月） `\pdfstartlink` 和 `\pdfendlink` 仅有两个 TeX 引擎支持：pdfTeX 和 LuaTeX（以及 LuaHBTeX）。历史上，pdfTeX 和 LuaTeX 都会生成一条 *错误* 信息，形式为

```latex
\pdfendlink ended up in different nesting level than \pdfstartlink
```

，以回应与盒子嵌套深度有关的底层问题。请注意，这条信息的文字内容源自 TeX 引擎软件深处，并非由任何 LaTeX 宏包产生，当然也不是由 Overleaf 产生的。

从 TeX Live 2021 开始，pdfTeX 和 LuaTeX 在处理底层（盒子嵌套）问题上的方式出现了分歧，现在表现出不同的行为：

* pdfTeX 现在将该信息作为 **警告**发出，它不再触发错误，而且编译 *不会* 终止；
* LuaTeX（LuaHBTeX）仍然将此问题视为 **致命错误**，从而导致编译终止——该错误信息的措辞与上面给出的略有不同。

希望进一步探究此错误根本原因的读者可以：

* 打开这个 Overleaf 项目

  它使用 pdfLaTeX 可以成功编译，但使用 LuaLaTeX 会触发该错误；
* 浏览 [GitHub 上的一篇深入技术讨论](https://github.com/latex3/latex2e/issues/94)，该讨论由顶尖的 TeX 和 LaTeX 专家参与。

## 从实际角度看，是什么导致了它？

在用户层面上，使用 `hyperref` 宏包并且某个超链接——例如引用、URL 或交叉引用——在多栏文档中跨越两页或两栏时，可能会触发此警告（或错误）；也就是说，链接在某一页（或某一栏）接近末尾处开始，并在下一页（或下一栏）结束。

如前所述，使用 TeX Live 2021 或更高版本的 pdfTeX（pdfLaTeX）现在不再生成错误，但在撰写本文时（2022年12月），LuaLaTeX 仍然会这样做。如果你使用的是 LuaLaTeX，在处理文档时，一个临时解决办法是，在你的

```latex
\hypersetup{draft}
```

之前写上

```latex
\begin{document}
```

虽然这会阻止超链接出现在文档中，但在编写时可以避免该错误，而且当你准备编译最终文档时，可以注释掉或删除 `\hypersetup{draft}`。如果你不幸在最终编译阶段仍然遇到这个问题，请重新启用 `draft` ，然后逐页查看你的 PDF，找出可能的“罪魁祸首”（引用、交叉引用、页面顶部的浮动体……），这样你就有望 *有望*……，找到一种编辑/改写文本的方法来避免该问题。

## 更多信息

如果你遇到的是一个致命错误，那么可能需要一些侦探工作来追查具体原因。tex.stackexchange 上有几篇相关讨论，但请注意，其中一些页面早于 pdfTeX 将该错误降级为警告之前：

* <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/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/wen-da/83-what-does-pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink-mean.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
