> 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-tw/wen-yu-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://overleaf-pro.ayaka.space/latex/zh-tw/wen-yu-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.
