> 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/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` は、TeXエンジンでは pdfTeX と LuaTeX（および LuaHBTeX）の2つだけでサポートされています。歴史的には、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、相互参照などのハイパーリンクが複数段組の文書で2ページまたは2カラムにまたがって分割される場合、つまりリンクがあるページ（またはカラム）の末尾付近で始まり、次のページ（またはカラム）で終わる場合です。

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

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

お使いの

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

これにより文書にハイパーリンクは表示されなくなりますが、作業中のエラーは回避できます。最終版の文書をコンパイルする準備ができたら、コメントアウトするか `\hypersetup{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/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.
