> 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/ja/to-2/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ファイル内の異なるページへのリンクやWebサイトへのリンクです。これらのコマンドはいわゆる *プリミティブ*：TeXエンジンに組み込まれた低レベルのコマンドであり、マクロではありません。その結果、多くのユーザーはそれらを直接扱うことはなく、以下のようなパッケージが提供するマクロ（コマンド）を介して間接的に使用します `hyperref`.

執筆時点（2022年12月）では `\pdfstartlink` と `\pdfendlink` は、pdfTeX と LuaTeX（および LuaHBTeX）の2つの TeX エンジンでのみサポートされています。歴史的に、pdfTeX と LuaTeX はどちらも *エラー* という形式のメッセージを生成していました

```latex
\pdfendlink は \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、相互参照などのハイパーリンクが、複数段組みの文書で2ページまたは2カラムにまたがって折り返される場合、つまりリンクが1ページ（または1カラム）の末尾付近で始まり、次のページ（またはカラム）で終わる場合に発生することがあります。

説明したように、TeX Live 2021 以降の pdfTeX（pdfLaTeX）はもはやエラーを生成しませんが、執筆時点（2022年12月）では LuaLaTeX は引き続き生成します。LuaLaTeX を使用している場合、文書作成中の一時的な回避策として、次のように書いてハイパーリンクを無効にできます

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

その直前に

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

このため文書内にハイパーリンクは表示されませんが、執筆中のエラーは回避できます。最終文書をコンパイルする準備ができたら、コメントアウトするか削除する `\hypersetup{draft}`\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/ja/to-2/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.
