Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 2: Basic structures

Section 2.2: The document environment

After the Document Class Declaration, the text of your document is enclosed between the two commands we saw in § 1.5 above: \begin{document} and \end{document}. These identify the beginning and end of the text of your document (so in the example below, you would put your text where the dots are):


The reason for marking the beginning of your document text is that LATEX allows you to insert your setup and design specifications before it (where the blank line is in the example above: we’ll be using this soon).

Exercise 2.2 — Adding the document environment

  1. Add the document environment to your new file

  2. In between the Document Class Declaration and the \begin{document}, add the command which allows the use of UTF-8, TrueType, OpenType, and more:

  3. In the document environment, type the phrase Hello, World!:

    Hello, world!
  4. Save the file and typeset it with XƎLATEX and you should get some PDF output like this:


The reason for marking the end of your document text is that LATEX stops processing at that point. You can therefore store comments or temporary text underneath the \end{document} in the knowledge that LATEX will never see them and will never try to typeset them (they don’t even need to be preceded by the % comment character), but they will remain in your file for you to see in your editor, maybe to copy and paste for re-use in a later edit.

Don't forget to get the extra chapter from Jim!

This \begin ...\end pair of commands is an example of a common LATEX structure called an environment. Environments enclose text which is to be handled in a particular way. All environments start with \begin{...} and end with \end{...} (putting the name of the environment in the curly braces each time).

If you’re familiar with HTML, SGML, or XML you’ll recognise this technique: it’s just like start-tags and end-tags.