> 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/latexer/03-display-math-should-end-with.md).

# 表示数式は$$で終わるべきです

## はじめに

TeXエンジンには数学式を組版する2つの方法があります：

* *インライン数式モード* これは数式内容が段落内に含まれる場合であり、
* *ディスプレイ数式モード* これは数式内容が別々に表示され、その上下に追加の空白が入る場合です。

*従来は*TeXの初期の頃には、組版されることを意図した数式は *インライン*、通常は段落内で、単一の `$` 文字： `$ インライン数式コンテンツ...$` で囲まれ、そして *表示* 用の数式は `$` 文字： `$$ ディスプレイ数式コンテンツ...$$`.

## エラーの原因 Display math should end with $$

エラーメッセージ `Display math should end with $$` は、TeXエンジンがディスプレイ数式の組版を終えようとしたものの、誤ったTeXマークアップのためにディスプレイ数式モードからきれいに抜け出せないときに生成されます。エラーメッセージが示すように、ディスプレイ数式として組版される सामग्रीは2つ目の `$$` の組で終わっていません。

### 例：単一のエラー

このエラーは次の例で示されます：

```latex
\documentclass{article}
\usepackage[textwidth=8cm]{geometry}
\begin{document}
\noindent \verb|$$ E=mc^2$| はエラーを生成します。なぜなら数式が
\texttt{\$\$} で始まっているのに、単一の \texttt{\$} で終わっているからです：

$$ E=mc^2$

\noindent\verb|$$ E=mc^2$ $| も、
終端の \texttt{\$} 文字の間に空白があるため、エラーを生成します：

$$ E=mc^2$ $
\end{document}
```

[この **エラーを発生させる** Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Errors+in+display+math\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Btextwidth%3D8cm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+%5Cverb%7C%24%24+E%3Dmc%5E2%24%7C+generates+an+error+because+the+math+is+%0Astarted+by+%5Ctexttt%7B%5C%24%5C%24%7D+but+terminated+by+a+single+%5Ctexttt%7B%5C%24%7D%3A%0A%0A%24%24+E%3Dmc%5E2%24%0A%0A%5Cnoindent%5Cverb%7C%24%24+E%3Dmc%5E2%24+%24%7C+also+generates+an+error+because+of+the+space+between%0Athe+terminating+%5Ctexttt%7B%5C%24%7D+characters%3A%0A%0A%24%24+E%3Dmc%5E2%24+%24%0A%5Cend%7Bdocument%7D)

この例では次の出力が生成されます（両方のエラーを強調するために画像を編集しています）：

![OLdisplaymatherrors.png](/files/ee588c2e777492b25584d389a281cd8c2869fccb)

### 例：2つのエラー

**注**：状況によっては、 *また* 関連するエラー [Missing $ inserted](/latex/ja/latexer/25-missing-inserted.md)を見ることもあります。次の例では `$$E=mc^2`と書くことで、両方の終端 `$` 文字：

```latex
\documentclass{article}
\usepackage[textwidth=8cm]{geometry}
\begin{document}
\noindent 次の例では、終端の \texttt{\$} 文字を両方とも省略しており、\texttt{Missing \$ inserted} と \texttt{Display math should end with \$\$.} のエラーが発生します。

$$E=mc^2
\end{document}
```

[この **エラーを発生させる** Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Two+errors+in+display+math\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Btextwidth%3D8cm%5D%7Bgeometry%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+The+following+example+omits+both+terminating+%5Ctexttt%7B%5C%24%7D+characters%2C+triggering+the+errors+%5Ctexttt%7BMissing+%5C%24+inserted%7D+and+%5Ctexttt%7BDisplay+math+should+end+with+%5C%24%5C%24.%7D%0A%0A%24%24E%3Dmc%5E2%0A%5Cend%7Bdocument%7D)

この例では次の出力が生成されます:

![OLdisplaymathtwoerrors.png](/files/e1555100127cdc7edcc9f72760bc436ea7d3b8c3)

## 解決策

上で示したエラーについては、修正は簡単です——末尾の `$$` をディスプレイ数式の最後に追加してください：

```latex
\documentclass{article}
\begin{document}
\noindent 解決策は、
の正しい終端を \verb|$$E=mc^2$$| と書くことで確保することです：

$$E=mc^2$$
\end{document}
```

[この **修正版** Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Errors+in+display+math\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+The+solution+is+to+ensure+correct+termination+of+the+%0Adisplay+math+by+writing+%5Cverb%7C%24%24E%3Dmc%5E2%24%24%7C%3A%0A%0A%24%24E%3Dmc%5E2%24%24%0A%5Cend%7Bdocument%7D)

## 数学式を組版するのに $ 文字を使わない

現在では、標準的な（受け入れられている）ベストプラクティスは、 *避けることです* 明示的な `$` 文字を使って数学式を組版するのではなく、代わりにLaTeXの *区切り記号を* 使うことです。特にディスプレイ数式ではそうです：

* の **ディスプレイ数式**：次のように書きます `\[ ディスプレイ数式コンテンツ \]` の代わりに `$$ *ディスプレイ* 数式コンテンツ...$$`
* の **インライン数式**：次のように書きます `\( インライン数式コンテンツ \)` の代わりに `$ *インライン* 数式コンテンツ...$`

実際には、LaTeXの区切り記号 `\(`, `\)`, `\[` や `\]` は単一文字の *マクロ* であり、単一の `$` と二重の `$` 文字の周りに一種の「保護ラッパー」を提供します。これらの区切り記号（マクロ）のLaTeX定義には実際に `不正な数式環境区切り記号`が含まれていますが、追加のコードによっていくつかのテスト／チェックが実行されます。また、LaTeXのエラーメッセージも生成されます。これらの区切り記号（マクロ）を使うことには、特別な効果を得るために、たとえば一時的に再定義できるなど、追加の利点もあります。


---

# 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/latexer/03-display-math-should-end-with.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.
