(click anywhere to close)

# [LaTeX] Basic Structure

category: Writing | course: LaTeX | difficulty:

Every document has a few required commands, put in a basic structure, you need to start from.

\documentclass[options]{documentType} packages \begin{document} everything \end{document}

The first part – everything that is before the document environment – is called the preamble. It is used to tell LaTeX to load everything we’re going to use in the document, and to determine the type of document. Only what’s inside the document environment is actually shown in the document.

\documentclass{article}
\usepackage[english]{babel}

%In the preamble...

\begin{document}
Inside the document...
\end{document}

After the document


After the \end{document} command you can place anything you like (comments, bits of text you have your doubts about), because it’s not going to show up in the document anyway.

## Packages

LaTeX wants to compile as quickly as possible, while keeping the file size low as well. Therefore, you need to manually include packages if you want more than very basic commands. The syntax is

\usepackage[optionalArgument]{packageName}

You can include as many as you like, or none at all. Most of these packages are already installed on your computer if you’ve installed a TeX distribution, but you can create or download your own custom packages if you’re into that sort of thing.

## Document Class

The document class decides the type of document you’re creating, which mostly influences which commands you’re able to use and how the finished product will look. Next chapter will tell you everything about it.

## Importing Files

If your project gets large, it might be useful to split it into multiple TeX files, which you can combine into one main TeX file. Fortunately, this is easy to do.

In the preamble, you can specify which files are going to be imported somewhere with \includeonly{filename, filename, …}.

Then, within the document itself, use \include{filename} to actually copy it there. Note that LaTeX starts an included document on a new page. If you don’t want that, you can use \input{filename} to just literally copy the contents from the other file at that exact spot.

\documentclass{article}
\includeonly{latex.tex}

\begin{document}
\input{latex.tex}
\end{document}

%The contents of latex.tex are...
This is everything that's inside latex.tex


You don’t necessarily have to tell LaTeX which files you’re planning on including in the preamble, but it’s best to do so, as it increases performance – LaTeX doesn’t need to search everywhere when you include a file, but knows what’s coming.

CONTINUE WITH THIS COURSE
Do you like my tutorials?
To keep this site running, donate some motivational food!
Crisps
(€2.00)
Chocolate Milk
(€3.50)
Pizza
(€5.00)