> 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/narejjibsu/127-set-main-document.md).

# メイン文書を設定

Overleaf のメインドキュメントは、LaTeX に最初にコンパイルするよう指示されるファイルです。これはプロジェクトのメインファイルであり、他のすべての部分（クラス、パッケージ、章など）が入力される先です。これが手動で設定されていない場合、Overleaf はプロジェクト内で次の **`\documentclass[...]{...}`** コマンド。したがって、プリアンブル用に別ファイルがある場合は、その **`\documentclass[...]{...}`** コマンドをプリアンブルファイルに含めるのではなく、メイン文書の先頭に置く方がよいです。そうしないと、プリアンブルだけがコンパイルされます。プロジェクトのメイン文書を設定するには、左上隅のメニューをクリックして、

![Lefthandmenu.PNG](/files/2f79d3a86b719c1c9c3288eef53c25fc81fb4797)

そして **メイン文書**:

![Maindocument.PNG](/files/a44e4e86ef9aa8893bed42418cf888f33970c985)

参照 [こちら](/latex/ja/wen-shu-gou-zao/07-management-in-a-large-project.md) LaTeX で大規模プロジェクトを管理する方法の詳細については、

## 同じプロジェクト内で複数の文書をコンパイルする

同じプロジェクト内の異なる文書をすばやくコンパイルできるように、Overleaf は、エディタで開いているファイルが次の **`\documentclass[...]{...}`** コマンドを含むと、そのファイルをメイン文書としてコンパイルします。これは、 [**`subfiles`** パッケージ](/latex/ja/wen-shu-gou-zao/08-multi-file-latex-projects.md#the-subfiles-package).

## メインファイルの選択に関する問題

メインファイルは常にルートディレクトリ（どのフォルダの外側）に置くべきです。そうすることで、すべてのコンパイル手順が正しいディレクトリで実行され、必要な補助ファイルが利用可能であることを確実にできます。たとえば、 [索引を追加する](/latex/ja/wen-shu-gou-zao/04-indices.md)。Overleaf でコンパイルするためにプロジェクトを再構成するためのヒントをいくつかご覧ください [こちら](/latex/ja/to-2/77-my-main-file-is-in-a-subfolder-but-this-is-not-allowed-on-overleaf.-but-i-don-t-want-to-change-my.md).

選択したメインファイルがフォルダ内にあり、ルートディレクトリに同じ名前のファイルがある場合は、選択したファイルではなく、ルートディレクトリ内のその名前のファイルがコンパイルされます。たとえば、 `version1/main.tex` がメインファイルとして設定されているが `main.tex` もプロジェクト内にある場合、 `main.tex` がコンパイルされます。この問題は、Overleaf で Latexmk が実行される方法に起因します。これによる問題を避けるには、Overleaf でコンパイルしたいファイルには一意の名前を付けてください。


---

# 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/narejjibsu/127-set-main-document.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.
