2. How to Organize a Document with Multiple Files Other Than TeX

As your LaTeX document gets longer, putting all the content into a single file can become cumbersome. In this post, we’ll introduce how to manage your document by splitting it into multiple files, along with the key commands you’ll need. Let’s explore some practical tips that help you keep your structure clean and make your workflow more efficient!
김준희's avatar
Oct 16, 2025
2. How to Organize a Document with Multiple Files Other Than TeX

Organizing Documents Efficiently by Splitting Files

LaTeX provides various commands that allow you to include different types of files depending on their purpose.
Today, we’ll break them down into three main categories:

  1. TeX files

  2. Code/Text files

  3. Image/PDF files

1. TeX Files

TeX files are source files in LaTeX that contain the main content of a document.
Any file with the .tex extension is considered a TeX file.

In LaTeX, it’s common to structure a document with one central main.tex file,
which in turn pulls in and completes the document by including several other TeX files.
This main.tex becomes the target for compilation and must include the preamble.

Now, if this important main.tex file contains everything—from the preamble to the introduction and conclusion—
it can become too long, making collaboration and editing harder due to lower readability.

In such cases, you can split your document into separate files like section1.tex, section2.tex, etc.
This allows you to manage the document much more efficiently.

Command

Description

Package

\input{filename}

Inserts the contents of the specified file at that location

-

\include{filename}

Inserts the file, separating it by page (suitable for larger units)

-

\includeonly{A, B…}

Used with \include to selectively compile only certain included files

-

\subfile{filename}

Allows documents to be split into modules so each unit can be compiled independently

subfiles

The \input command inserts the contents of the specified file directly at the position where it is called.
Therefore, it’s suitable for inserting relatively short parts of the document.

In contrast, the \include command adds content starting on a new page (along with \clearpage),
so it's more appropriate for managing content by chapters or sections.
Also, using \includeonly, you can limit which files get compiled, allowing partial compilation.

While both \input and \include work by loading other files into the main main.tex,
the \subfile command allows each file to be compiled independently as well.

⚠️ One Important Caution!

When working with TeX files using the \subfile command,
you must explicitly state that the file uses the main document and the subfiles package
via the \documentclass declaration.

Doing so allows each file to be compiled independently

\documentclass[Main document used as the basis for compilation]{subfiles}

💡

Try writing by referring to the code examples for each environment.

\input{intro.tex}
\input{intro} % 확장자 생략 가능
\include{intro.tex}
\include{intro} % 확장자 생략 가능
\includeonly{section1, section2, section3, ...}
\subfile{intro.tex}
% intro.tex

\documentclass[main.tex]{subfiles}

\begin{document}
...
\end{document}

Difference Between \input and \include

The most noticeable difference between \input and \include is whether the content is separated by pages.

\include automatically adds the \clearpage command at the beginning, which separates the content onto a new page. Therefore, it always starts on a new page. On the other hand, \input inserts the content exactly where the command is called, without adding a page break.

The two commands also differ in how they function internally, with several unique characteristics.

  • Auxiliary file management:
    \include creates a separate .aux auxiliary file for each included file. This allows you to use the \includeonly command to compile only specific parts of the document, making it very efficient for working with long documents such as theses or books. In contrast, \input works like simple copy-pasting of content, so it doesn't support partial compilation.

  • Usage location restriction:
    \input can be used anywhere in the preamble or body of the document. You can even use it within a file that’s already been included using \input, enabling nested inputs. In contrast, \include can only be used within the document environment (not in the preamble), and it doesn't allow nested usage.

In short, \input is lightweight and flexible, suitable for small-scale modular writing. Meanwhile, \include is ideal for managing large units of files and structuring documents with clear page separations. Think of it as a “high-level structuring command” for document management.

2. Code / Text Files

Sometimes in research papers or reports, it's more effective to show the actual source code than to simply describe the text in several lines. Here’s a list of commands and packages you can use in such cases:

Command

Description

Package

\lstinputlisting[options]{filename}

A command that loads a code file and inserts it into the document

listings

\inputminted{language}{filename}

A command that inserts a syntax-highlighted program code file into the document

minted

\verbatiminput{filename}

A command that inserts the raw text from the specified file into the document

verbatim

\VerbatimInput[options]{filename}

A command that inserts the raw text from the specified file into the document

fancyvrb

💡

Try writing by referring to the code examples for each environment.

\includegraphics{sample.jpg}

% Specify image width
\includegraphics[width=0.5]{sample.jpg}
% Insert entire PDF
\includepdf[pages=-]{document.pdf}

% Insert specific page(s)
\includepdf[pages=3]{document.pdf}

% Insert multiple pages
\includepdf[pages={2,4,6}]{document.pdf}

\includegraphics VS figure Environment

“I heard in a previous blog post that there's an environment for inserting images—what was that again?”

In LaTeX, there are many things that may look similar but behave differently depending on the situation.
One good example is the difference between the figure environment and the \includegraphics command.

\includegraphics

figure Environment

Notes

Do you need a package?

graphicx

Can you specify the position?

h, t, b, p options

Can you add a caption?

Use \caption{}


Today, we’ve looked into how to organize documents into multiple files in LaTeX and the commands used for that.

Isn’t the world of LaTeX, full of separation and extension, endlessly fascinating? 😜

Once you get used to properly utilizing the basic commands, you’ll find it much easier to manage large-scale documents efficiently.
You’ll also experience greater readability and productivity, which is especially helpful for collaborative work.

Even if you've divided your document well, it becomes harder to remember all file paths and contents as the project grows.
It gets even more difficult when collaborating with others.

👉 To reduce this inconvenience, MurfY provides an auto-complete feature.

When using commands that require referencing file names, it automatically shows the list of available .tex files or image files for selection,
allowing you to insert files easily without worrying about path errors!

The appearance of file list autocompletion in Murfy

We hope you continue exploring various LaTeX features by practicing directly in Murfy and creating cleaner, more structured documents.

In the next post, we’ll cover reference management—an essential part of academic writing.

We'll walk through how to create .bib files and how to use commands like \cite and \ref step by step, so stay tuned! 🚀
 

Share article

Best Online LaTeX Editor, Murfy