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 two commands we saw in § 1.4 which identify the beginning and end of the actual document (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 extra setup specifications before it (where the blank line is in the example above: we’ll be using this soon). The reason for marking the end of your document text is to provide a place for LATEX to be programmed to do extra stuff automatically at the end of the document, like making an index.

A useful side-effect of marking the end of the document text is that you can store comments or temporary text underneath the \end{document} in the knowledge that LATEX will never see them and never try to typeset them (they don’t even need to be preceded by the % comment character), but they will remain in your document for you to see in your editor, or maybe to copy and paste 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.

Exercise 2: Add the document environment

  1. Add the document environment to your new file

  2. If you are using PDFLATEX (NOT if you are using XƎLATEX)…

    In between the Document Class Declaration and the \begin{document}, add the two lines we saw in § 1.8 which allow the use of UTF-8 in PDFLATEX:

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

  4. Save the file and typeset it; you should get some output like this: