> 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/wen-shu-gou-zao/07-management-in-a-large-project.md).

# 大規模プロジェクトでの管理

## はじめに

本のような大規模なプロジェクトでは、文書の一部を複数の .tex ファイルに分けておくと、エラーの修正やさらなる変更が容易になります。短いファイルなら、特定の単語や要素を見つけるのも簡単です。そこでこの記事では、大きなプロジェクトを管理する方法を説明します。

## ファイルの入力と取り込み

LaTeX ファイルを別のファイルに挿入する標準的なツールは次のとおりです `\input` や `\include`.

**input コマンド**

\input{filename}

このコマンドは文書本体で使い、次の名前の別ファイルの内容を挿入します `filename.tex`; このファイルには LaTeX のプリアンブル用コードを含めないでください（つまり、 `\documentclass`, `\begin{document}` または `\end{document}` ）。LaTeX は、 `filename.tex`. `\input` 入れ子にできます `\input` コマンドを、ルートファイルによってすでに読み込まれているファイル内で。

**include コマンド**

\include{filename}

このコマンドは文書本体で使い、次の名前の別ファイルの内容を挿入します `filename.tex`; こちらもこのファイルには LaTeX のプリアンブルを含めないでください。LaTeX は、 `filename.tex`の拡張子を含めないようにしてください `.tex` をファイル名に含めないでください。これを含めるとファイルが読み込まれなくなります（拡張子は必要に応じて `入力` や `import`を付けてもかまいません）。 `include` 読み込まれた各ファイルには `\include`独自の .aux ファイルがあり、作成されたラベルや目次、図目録などの情報を保存します。次を使えます `\includeonly` を、コンマ区切りのファイル名リストとともに使用します（先頭や末尾に空白がないようにしてください）。これを行うと、LaTeX はそのリストに含まれるファイルだけを処理します。大きな文書のごく一部だけを作業している場合、コンパイル速度の向上に使えます。ただし、除外したファイルの .aux ファイルは引き続き処理されるため、ページ番号と相互参照はそのまま機能します。

[Overleaf で大規模プロジェクトの例を開く](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## 別ファイルに分けたプリアンブル

文書のプリアンブルに、多くのユーザー定義コマンドや [用語集](/latex/ja/wen-shu-gou-zao/05-glossaries.md)の定義がある場合は、別ファイルに入れることができます。正しい方法は、.sty 拡張子のカスタムパッケージを作成することです。例を見てみましょう：

```latex
\ProvidesPackage{example}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[latin1]{inputenc}
\usepackage[spanish, english]{babel}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{textcomp}
\usepackage{pgfplots}

\pgfplotsset{width=10cm,compat=1.9}

%ヘッダーのスタイル
\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\textbf{\textit{\nouppercase{\leftmark}}}}
\fancyhead[LO]{\textbf{\textit{\nouppercase{\rightmark}}}}
\fancypagestyle{plain}{ %
\fancyhf{} % すべて削除
\renewcommand{\headrulewidth}{0pt} % 線も削除
\renewcommand{\footrulewidth}{0pt}}

%\proof、\qedsymbol、\theoremstyle コマンドを利用可能にします
\usepackage{amsthm}

%ルーラー
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%補題の定義と補題カウンタ
\newtheorem{lemma}{Lemma}[section]

%定義カウンタ
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

%系のカウンタ
\newtheorem{corolary}{Corolary}[section]

%自然数、整数、位相、凸包、Ball、Disc、Dimension、境界などのためのコマンド
\newcommand{\E}{{\mathcal{E}}}
\newcommand{\F}{{\mathcal{F}}}
...

%例環境
\theoremstyle{remark}
\newtheorem{examle}{Example}

%例カウンタ
\newcommand{\reiniciar}{\setcounter{example}{0}}
```

このファイル内のすべてのコマンドはプリアンブルに置くこともできましたが、そうすると大量のコードのためにメインファイルが分かりにくくなり、しかもそのような大きなファイルの中で文書の実際の本文を見つけるのは面倒な作業になっていたでしょう。

このファイルは通常の .tex ファイルに置いて、コマンド `import` を使って取り込むこともできます（ [次のセクション](#importing-files)）。ただし、.sty ファイルにしておけば、ファイルが誤って複数回読み込まれた場合のエラーを防げます。

例の最初の行が

```latex
\ProvidesPackage{example}
```

これは、このパッケージを *example* としてメインファイルで読み込む必要があることを意味します。つまり、コマンド

```latex
\usepackage{example}
```

に示すように [導入](#introduction).

*注意：.sty ファイルははるかに柔軟で、自分のマクロを定義するために使えます。また、オプション引数を渡すこともできます。* [*独自のパッケージを書く*](/latex/ja/kurasufairu/03-writing-your-own-package.md).

[Overleaf で大規模プロジェクトの例を開く](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## import パッケージの使用

前述のとおり、LaTeX ファイルを別のファイルに挿入する標準的なツールは `\input` や `\include`ですが、ネストしたファイルの取り込みが必要な場合はエラーが起こりやすいです。このため、パッケージ **import**.

以下は、章とユーザー定義コマンドが別ファイルに格納され、各章の画像ファイルが、各章の .tex ファイルとともに別フォルダに格納されている本の例です。

```latex
\documentclass[a4paper,11pt]{book}
\usepackage{import}
\usepackage{example}

\usepackage{makeidx}
\makeindex

\begin{document}

\frontmatter
\import{./}{title.tex}

\clearpage
\thispagestyle{empty}

\tableofcontents

\mainmatter
\chapter{First chapter}
\import{sections/}{section1-1.tex}
\import{sections/}{section1-2.tex}

\chapter{Additional chapter}
\import{sections/}{section2-1.tex}

\chapter{Last chapter}
\import{sections/}{section3-1.tex}

\backmatter

\import{./}{bibliography.tex}

\end{document}
```

ご覧のとおり、この例は3つの章といくつかの節を持つ本で、最終文書を生成するために外部ファイルを取り込む整然としたメインファイルになっています。コマンド `\frontmatter` は book 文書クラスにおいて文書の最初のページに使われ、このコマンドによってページ番号のスタイルはローマ数字に設定されます。コマンド `\mainmatter` はページ番号をリセットし、スタイルをアラビア数字に変更します。 `\backmatter` は章番号付けを無効にします（参考文献や付録に適しています）。

```latex
\chapter{First chapter}
\import{sections/}{section1-1.tex}
\import{sections/}{section1-2.tex}
```

まず、文書のプリアンブルに次の行を追加してください：

```latex
\usepackage{import}
```

次に `\import{ }{ }`を使います。中括弧内の最初の引数はファイルが置かれているディレクトリで、現在の作業ディレクトリからの相対パスでも絶対パスでもかまいません。2つ目の引数は取り込むファイル名です

また、次のコマンドもあります `\subimport` 。こちらも構文は同じですが、メインファイルに取り込まれるファイルのいずれかで使う場合、パスはそのサブファイルを基準にした相対パスになります。たとえば、以下は前の例で取り込まれた "section1-1.tex" ファイルの内容です：

```latex
\section{最初の節}

以下はシンプルな3Dプロットです

\begin{figure}[h]
\centering
\subimport{img/}{plot1.tex}
\caption{Caption}
\label{fig:my_label}
\end{figure}

[...]
```

ご覧のとおり、このファイルは [pgf のプロット](/latex/ja/fen-ye-bie/08-pgfplots-package.md) ファイル "plot1.tex" を取り込み、3D プロットを作成しています。このファイルは

```latex
\subimport{img/}{plot1.tex}
```

"img" フォルダから取り込まれており、そのフォルダは "sections" フォルダ内にあります。

もし `\import` を使った場合は、パス *img/* は、"section1-1.tex" が保存されている "sections" フォルダではなく、メインファイルを基準にした相対パスになります。

[Overleaf で大規模プロジェクトの例を開く](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## さらに読む

詳しくは以下を参照してください：

* [複数ファイルの LaTeX プロジェクト](/latex/ja/wen-shu-gou-zao/08-multi-file-latex-projects.md)
* [節や数式の相互参照](/latex/ja/wen-shu-gou-zao/03-cross-referencing-sections-equations-and-floats.md)
* [索引](/latex/ja/wen-shu-gou-zao/04-indices.md)
* [用語集](/latex/ja/wen-shu-gou-zao/05-glossaries.md)
* [ハイパーリンク](/latex/ja/wen-shu-gou-zao/09-hyperlinks.md)
* [ページ番号](/latex/ja/shu-shi-she-ding/03-page-numbering.md)
* [片面印刷と両面印刷の文書](/latex/ja/shu-shi-she-ding/08-single-sided-and-double-sided-documents.md)
* [複数カラム](/latex/ja/shu-shi-she-ding/09-multiple-columns.md)
* [段落の書式設定](/latex/ja/shu-shi-she-ding/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [ページサイズと余白](/latex/ja/shu-shi-she-ding/07-page-size-and-margins.md)
* [カウンタ](/latex/ja/shu-shi-she-ding/10-counters.md)
* [欄外メモ](/latex/ja/shu-shi-she-ding/15-margin-notes.md)
* [太字、斜体、下線](/latex/ja/latexno/03-bold-italics-and-underlining.md)
* [フォントサイズ、ファミリー、スタイル](/latex/ja/fonto/01-font-sizes-families-and-styles.md)
* [フォントの書体](/latex/ja/fonto/02-font-typefaces.md)
* [XeLaTeXによる現代的なフォントのサポート](/latex/ja/fonto/03-xelatex.md)
* [国際言語サポート](/latex/ja/yan-yu/03-international-language-support.md)
* [フォントサイズ、ファミリー、スタイル](/latex/ja/fonto/01-font-sizes-families-and-styles.md)
* [独自のパッケージを書く](/latex/ja/kurasufairu/03-writing-your-own-package.md)
* [独自のクラスを書く](/latex/ja/kurasufairu/04-writing-your-own-class.md)
* [LaTeX2εへのそれほど短くない入門](http://www.ctan.org/tex-archive/info/lshort/)
* [`import` パッケージのドキュメント](ftp://sunsite.icm.edu.pl/pub/CTAN/macros/latex/contrib/import/import.pdf)


---

# 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/wen-shu-gou-zao/07-management-in-a-large-project.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.
