# Compile your first document in XeLaTeX

Now that you have installed the LaTeX distro and you know the basic concepts, we can start writing your first document. Open TeXworks in Windows or Mac and open Kile in Linux. This guide will explain how to write documents in TeXworks, but things will be similar in other front-end (check the specific documentation of your front-end if you wish to use a different one).

## Basic document

The minimum requirements for a document to compile in XeLaTeX is the following code.

\documentclass{article}
\begin{document}
\end{document}


Write this code inside the source window of the front-end, like in the picture below.

The first command, \documentclass, calls the class of the document you are writing. The class defines the basic format of the document. The main classes available in XeLaTeX are article, report, book and memoir. We will start using the article class. In order to tell XeLaTeX which class you wish to use, you just specify the name of the class inside the curly brackets: \documentclass{article}. The second and the third commands form what is called an environment: everything that is between a \begin and an \end command is an environment. In the code above we have set the most important environment of the document: the document environment. Remember that for every \begin command there must be an \end command, otherwise an error will be generated and the document won’t finish compiling. So, the document environment is simply set with \begin{document} and \end{document}. The document class and the document environment commands are necessary in a document, so don’t forget to put them first thing. Now we can add some text to our document. To do so, just write whatever you like inside the document environment (between \begin{document} and \end{document}, do not write anything outside it for now). You may want to write “This is my first document.”

Now we can compile the document, in other words, let the TeX engine read the source code we wrote in the source window and create a PDF with the content of our document. Before compiling, you have to save the document. Since the compilation will create several files that are necessary for the process, I suggest you to create a folder for your document and save it there so that the various files will stay organized. Once you saved the document, you have to set the engine to XeLaTeX.

To set XeLaTeX as the default engine, go to the Preferences, select the “Build” tab and set XeLaTeX as the default compiler. Now you can click the “Build & View” button to start the compilation of the document: this button has the shape of two green triangles and it is located in the top bar. Some running text will show up in the bottom of the window and, if everything is ok, the compiled PDF will show up on the right.

## Title, author and date

We can now add three other basic commands that set the \title of the document, the \author and the \date. These commands, like a lot of other commands, must be inserted between \documentclass and \begin{document}. Everything that comes before \begin{document} is called the preamble. Thus, right after the first line of the preamble, put the following code (adapt the content of the commands to what you need):

\title{Title of the document}
\author{Author of the document}
\date{Date of the document}


If you leave the date command empty, no date will be compiled. If you don’t put the command at all, the current date will be compiled. In order to compile the information you just set with the title, author and date command, you have to insert \maketitle right after \begin{document}. Then, press the green button for compiling.