LaTeX Input File (Preamble and Body)

Preparing a LaTeX input file involves creating a document with the necessary commands and content to produce the desired output. Let’s look at the basic structure of a LaTeX input file.

Structure of a LaTeX input file

The structure of a LaTeX input file can be divided into two components: preamble and body, as illustrated in the following figure.

The preamble, positioned at the beginning of an input file, encompasses global processing parameters for the entire document. These parameters include document type (or document class), page formatting, header, footer configurations, LaTeX packages to support additional instructions, and the definition of new commands.

The body of a LaTeX input file commences with \begin{document} and concludes with \end{document}. This body incorporates all the content intended for printing in the output. A LaTeX compiler disregards anything entered after \end{document}. It means that anything written after \end{document} will not be printed when the document is compiled.

What is a preamble in LaTeX?

In LaTeX, the preamble refers to the section at the beginning of a document (or before the \begin{document} command) where you can set up the document’s overall structure, formatting, and other options.

It is where you define the document class, load packages, set up margins, specify fonts, and configure various settings. The preamble helps ensure that your document is formatted correctly and that any required packages or styles are properly loaded before the main content begins. It is an essential part of any LaTeX document and allows you to customize it to meet your requirements.

Here’s the basic structure of a LaTeX document with a preamble:

% Preamble
\documentclass{article}  % Document class declaration

\usepackage{package1}     % Load additional packages
\usepackage{package2}
\newcommand{\mycommand}{Some custom command}

% Body
\begin{document}

Welcome to Latextutorial.net

\end{document}

In this example:

  • \documentclass{article} specifies the type of document (e.g., article, report, book).
  • \usepackage{package1} and \usepackage{package2} are used to include additional packages that provide extra functionality.
  • \newcommand{\mycommand}{Some custom command} defines a custom command. You can read how to use /newcommand in this guide.

The preamble is a crucial part of a LaTeX document as it helps you configure your document’s overall layout, style, and functionality before you start writing the content.

A LaTeX input file is typically named with the “.tex” extension, such as “myfirstexample.tex.” You can create it on any operating system using any general-purpose text editor that supports the “.tex” extension.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.