Try writing by referring to the code examples for each environment.
| |
---|---|
| |
| |
|
|
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:
TeX files
Code/Text files
Image/PDF 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 |
---|---|---|
| Inserts the contents of the specified file at that location | - |
| Inserts the file, separating it by page (suitable for larger units) | - |
| Used with | - |
| Allows documents to be split into modules so each unit can be compiled independently |
|
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.
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
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.
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 |
---|---|---|
| A command that loads a code file and inserts it into the document | listings |
| A command that inserts a syntax-highlighted program code file into the document | minted |
| A command that inserts the raw text from the specified file into the document | verbatim |
| 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.
|
---|
|
“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.
|
| Notes | |
---|---|---|---|
Do you need a package? | ✅ | ✅ |
|
Can you specify the position? | ❌ | ✅ |
|
Can you add a caption? | ❌ | ✅ | Use |
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!
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! 🚀
Best Online LaTeX Editor, Murfy