> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-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）仍然将此问题视为 **致命错误**，导致编译终止——该错误消息的措辞与上面给出的略有不同。

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

* &#x20;打开此 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://overleaf-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.
