2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LaTeXで長い文章を書く

Last updated at Posted at 2025-06-02

長い文章を効率的に書くコツ

  • ファイルが大きくなる → 章ごとにファイルを分割
  • コンパイル時間が長い → 一部分だけコンパイル

LaTeXを使って数十ページを超える長いドキュメントを作成しようとすると、

  • ファイルが長くなってしまう
  • コンパイル時間が長くなる
    などの問題が発生します。

これらの問題を解決するためにいろいろ工夫する羽目になったので参考までに。

lualatexを使っていることを仮定しているので処理系によっては読み替える必要があります

ファイルを分割する

プロジェクト構造は

.
├─ preamble
|  ├─ page.tex
|  ├─ figures.tex
|  └─ ...
├─ main.tex
├─ part1
|  ├─ figures
|  |  ├─ figure1.png
|  |  └─ ...
|  ├─ chapter1.tex
|  ├─ chapter2.tex
|  ├─ chapter3.tex
|  └─ ...
├─ part2
└─ ...

のようにchapterごとに分けることが望ましです。
sectionが長くなるようであればsectionごとに分けるもの良いです。

実際にpart1chapter1.texなどのファイル名をつけてしまうと、章の順番の入れ替えが煩雑になる。内容に即したファイル名にするべし

importパッケージを使うと、どのファイルでエラーが発生したかがわかりやすいのでこれを使います。(ただし、どのファイルで発生したかはわからないエラーもある模様)

main.tex
\documentclass{ltjsbook}

\usepackage{import}
\import{preamble}{preamble}

\begin{document}
\tableofcontents
\part{part1}
\subincludefrom{part1}{chapter1}
\subincludefrom{part1}{chapter2}
\subincludefrom{part1}{chapter3}
...

importパッケージを使うと、各texファイルからの相対パスで画像などの外部ファイルを指定できるようになります。

chapter1.tex
\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/figure1.png}
    \caption{figure1}\label{fig:fig1}
\end{figure}

一部のファイルのみをコンパイルする

main.texのプリアンブル部分に

main.tex
\includeonly{part1/chapter4}

のように書くと、そのファイルのみがコンパイルされます。
参照の番号は全体をコンパイルする場合と変わりません。

この場合、chapter4.texのみを編集しながらコンパイルをし、書き終わったらこの行を削除して全体をコンパイルすれば良いわけです(ただし最後のコンパイルする際には時間がかかる)。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?