A Short Introduction to Making Documents using LaTeX

Ver 1.2 (last updated: Sep 24, 2008)

by Timothy Choi (t c h o i @ m a t h . u c i . e d u)

DISCLAIMER: This tutorial is only meant to be benefitted by math grads of UCI since the content contains numerous instructions specific to UCI math grads.

OBJECTIVES: The scribers from mathematical communities occasionally create documents with technical contents, such as formulas, matrices, or graphs. Although many commercial and freely available word processors are capable of making documents with technical contents, the documents created with LaTeX are by far the best in my personal view. This tutorial is prepared for the graduate students of the department of mathematics in order to introduce making simple documents using LaTeX.

First of all, let us compare a mathematical expression manifested by three different ways: Microsoft Word, Mathematica, LaTeX.

Microsoft Word Mathematica LaTeX

In MS Word to create the image above, one has to click few math symbols in the Equation Editor, and sometimes it can be frustrated since we don't have much control in terms of margins and spacings. Mathematica also limits us with spacing issues. If you compare the expression created by LaTeX with the first two, it looks more stylish and above all RIGHT! The following line is the actual entry in the LaTeX file to create the expression:

"\iiint_V \frac{\sin x}{\cos^2 y} + \sqrt[3]{z} \,\, dxdydz".

Yes, it looks cryptic. After making few documents, you wouldn't really find the expression cryptic any longer.

EXAMPLE 1: Here we make our first LaTeX document with the tex file named "HelloWorld.tex". We will refer a LaTeX document file as either a tex file or a latex file. Technically they are not the same thing, but I tend to ignore. Either we mean tex files or latex files, '.tex' will be used for the file extension.

\documentclass[letterpaper]{article}

\begin{document}

\noindent
Hello, World!

\end{document}

The content inside the box is all we need in the tex file named "HelloWorld.tex". A tex file is saved as a 'text' file, so you may use any text editor of your choice to create a tex file. Later we will explain in details, but for now just accept that the tex files can be processed through the LaTeX program to create popular document formats such as DVI, PS, or PDF. We created the PDF file that is produced from the tex file "HelloWorld.tex". Click here to see the PDF file ("HelloWorld.pdf"). Now let us give a quick overview of the document "HelloWorld.tex". Whatever appears between \begin{document} and \end{document} is the actual content of the document. In the example, the text "Hello, World!" is the only thing that appears in the PDF documnet although we also have \noindent, which doesn't appear in the content. It is a LaTeX command which ignores the default indentation for a paragraph. Whatever comes between \documentclass[letterpaper]{article} and \begin{document} are special instructions for the LaTeX document such as margins, fonts, packages, and etc. For this example, there is no special instruction has been specified.

DOCUMENT CREATION: Before we go on with more technical aspectes of preparation of LaTeX documents, let us describe ways of making DVI, PS, or PDF documents from tex files. If you are a UCI math grad, then you will have an account (i.e. login name and password) for the math server with the host math.uci.edu. Note that your login name could be possibly different from your UCInetID. We will refer math.uci.edu account as the math account. Make sure that you have both math account login name and password before your move on. Now if you have them ready, then here is the overview:

1. Using a SSH client, log in to the math server math.uci.edu.
2. Create a tex file using one of available text editors (such as Pico, Emacs, Vi(m), and etc.).
3. Run a LaTeX program to process the tex file to produce a DVI, PS, or PDF document file.

STEP 1: You wouldn't be able to connect to the math account using a unsecured telnet. You can only connect to the math account using the SSH (Secure SHell) telnet client. If you are using Windows, you can try freely available SSH clients such as PuTTY (google "putty ssh"). If you are using Mac, you can try MacSSH (google "MacSSH"). However, if you have fairly new Mac, then no need to use 3rd party SSH client as the Mac OS is already equipped with OpenSSH in its kernel as in Linux. If you are using Linux, you may use the OpenSSH (just type "ssh"). Using the OpenSSH in the terminal, here is a typical way to login:

ssh -l[math account login name] math.uci.edu

• Type pico .cshrc and press the Enter key. A text editor called pico will open the file named ".cshrc". In UNIX the file name that starts with the period (or the dot) indicates that the file is a hidden file.
• Using the arrow keys, move the cursor to the bottom of the text. Press the Enter key (if necessary) to start a new line.
• Type set prompt="%n@%~] " and press the Enter key. Note that there is an extra space between the right square bracket and the second double quotation mark.
• Press the Control key together with the alphabet letter 'o' (i.e. 'o' as in orchid), and press the Enter key. In pico this simultaneous combination of two keys saves the file.
• Press the Control key together with the alphabet letter 'x'. In pico this combination of two keys exits pico.
• Type exit and press the Enter key to log out from the shell.
• Log back in to the math account again.
If you have done everything correctly, upon loging in you will notice that the prompt is changed to '{your math account user id}@~]' from 'math%'. The prompt indicates that the user is at the directory '~'. Now if you cruise over directories, the prompt will keep track of the directory you are in. We will see this later.

STEP 2: Here we will create a tex file using the text editor pico we used in the STEP 1. Before that, we first make a directory named 'latex' in your home directory so that we can create all these tex files in that directory. The portion '@~' of the prompt means that you are currently at the home directory. The tilde '~' is used to represent your home directory, so from now on '~' is referred as the home directory. Now let us create a directory called 'latex' using the UNIX command 'mkdir' from "make directory". Just follow the procedure:

• Type mkdir latex and press the Enter key. A directory called 'latex' has just been created under the home directory '~'.
Now let us verify if the directory was actually created correctly. We can verify that by trying to change the current directory which is '~' to the directory named 'latex'. We will change the current directory, i.e. '~', to the new directory we created using the command 'cd' from "change directory". There are at least three ways of doing that. Just follow only one of the following procedures:
• Type cd latex and press the Enter key.
• Type cd ~/latex and press the Enter key.
• Type cd ./latex and press the Enter key.
The first and the third would work only at the directory '~', but the second would work no matter where you are. The difference is that '~/latex' is the absolute path for the directory we want while the rest are relative path. The first and the third ways wouldn't work unless the current directory has 'latex' as its direct child directory. In the third, the period '.' indicates the current directory whatever the current directory may be, so './latex' indicates the direct child directory of the current directory. If you tried one of three suggestions, then you should be in the directory 'latex'. Please note the change of the prompt from 'username@~]' to 'username@~/latex]' which indicates that the current directory is '~/latex'. The prompt will keep track of the directory you land on. Now as an exercise, in the directory 'latex' let us make two more directories: 'romulus' and 'remus' by mkdir romulus and mkdir remus. Change the directory to 'romulus' by cd romulus and create a child directory named 'rome' by mkdir rome. Change the directory again to 'rome' by cd rome. Here is the diagram of the directory structure so far:
Now let us change the directory to 'remus' from where we are, i.e. 'rome'. We can achieve this by one of the following procedures:
• Type cd ../../remus and press the Enter key.
• Type cd ~/latex/remus and press the Enter key.
• Type cd ./../../remus and press the Enter key.
The first and the third would work only at the current directory, i.e. 'rome', but the second would work no matter where you are. The difference is that '~/latex/remus' is an absolute path while the rest are not. In the first and the third ways double dots '..' indicates the direct mother directory of the current directory. Thus, '..' is referring to the directory 'romulus' in this case. Hence, '../..' would refer to the directory 'latex'. Once again, in the third way the single dot '.' indicates the current directory. Hence, './../..' would refer to the directory 'latex'. Now './../../remus' refers to the directory 'remus' as desired. Please note the change in the prompt as you cruise over directories. From 'remus' let us go back to 'latex' by cd .. (or there are two other ways you should be able to figure out now), and we want to remove the directory 'remus' using the command 'rmdir' from "remove directory". We remove the directory 'remus' by one of the following procedures:
• Type rmdir remus and press the Enter key.
• Type rmdir ~/latex/remus and press the Enter key.
• Type rmdir ./remus and press the Enter key.
Once again, the second way would work wherever you are, but the first and the third would only work in the direct mother directory of 'remus'. Now we can verify that the directory is really gone by trying to change the directory to 'remus', and if you successfully removed 'remus', the shell will give the error message, "remus: No such file or directory". We have covered about a half of basic UNIX commands that we need to know. We will cover the rest later. Now let us come back to our original goal of this step, i.e. creating a tex file using a text editor. Since we have already used pico, why don't we stick to this editor? In fact, this is one of the simpler editors to use (hence not powerful), so it is a good editor to start with. From the directory 'rome' (by now you should be able to change to the directory to 'rome'). From the prompt type pico HelloWorld.tex and press the Enter key. You will see the following screen.

On the editor you would type like you would type in any other word processor. Let us type the following:

Editting in pico is not so fun at the beginning since the editor comes with only minimal set of features (although sufficient to create simple documents). At the bottom of the screen you should be able to see 12 commands you can invoke in pico. The wedge character '^' means pressing the Control key. To get the help we follow the first option "^G: Get Help" by pressing the Control key together with the alphabet letter 'g' (you don't need to use the capitalized letter 'G'). For now all we care is "^O: WriteOut", which saves the current document and "^X: Exit", which exits the pico. To finish editting the tex file, press '^O' and press Enter key when pico suggests for the file name to write. If we started pico without the argument "HelloWorld.tex", then we might have to provide the file name after pressing '^O'. However, in this example we provided the file name we want to use when we started the editor by passing the file name as the argument. After the file is saved, press '^X' to exit the program. We are finally done with creating the tex file "HelloWorld.tex".

STEP 3: We will make DVI, PS, and PDF document files from the tex file "HelloWorld.tex" that we created in STEP 2. Make sure that you are still in the directory where "HelloWorld.tex" was created, i.e. the directory called 'rome'. To create a DVI document, type latex HelloWorld.tex and press the Enter key. The program 'latex' will run in verbose mode, so you should be able to see what the program does. If you have created the tex file correctly, you should see the following line in the message that 'latex' printed: "Output written on HelloWorld.dvi (1 page, 232 bytes)". Congratulations! You have created your very first DVI document using LaTeX. As much as you want to see the document in a DVI viewer, we will deter that for now. However, we will verify that the DVI file has been created by listing the files in the directory 'rome' using the command 'ls' from "listing files and directories". To list the files in the current directory, type ls and press the Enter key. You will see four files in the directory, and one of them is the DVI file that we wanted to see. The other two files, "HelloWorld.log" and "HelloWorld.aux", are by-products of processing the tex file. Most likely we do not have to pay attention to these by-products. Now let us create a PS document file. We will not create a PS file from the tex file directly, but we will convert the DVI file "HelloWorld.dvi" to a PS file. To convert the DVI file in order to create a PS file, type dvips HelloWorld.dvi and press the Enter key. Now verify that the PS file has been created by listing the files in the directory. There is also a way of converting a PS file to a PDF file by typing ps2pdf HelloWorld.ps, but we will describe a way to create a PDF file from the tex file directly. To create a PDF document file from the tex file (which is what you most likely to do so), pdflatex HelloWorld.tex and press the Enter key. Either way you chose, you can verify that the PDF file "HelloWorld.pdf" has been created by listing the files in the directory. You could also create a PDF file using the DVI file by typing dvipdf HelloWorld.dvi and create a PS file using the PDF file by typing pdfps HelloWorld.pdf.

Let us make some remarks about the command 'ls'. One can also list not only the name of the files but also more information about the files such as the date when the file was modified, size, ownership, and etc. If we type ls -l, then we will first list the files in one column and get more information about the files. We added '-l' after the command 'ls' to show file information, and is called an option of the command. There is one more useful option to know for 'ls'. If we type ls -a, then we can even see the hidden files which have the period as their first character in the file names. The directory 'rome' would not have any hidden files, so it is not a good place to check this option. Change the directory to '~', the home directory, and try to list the files using 'ls' first. Now try 'ls -a', and at least you will see the very first file we edited ".cshrc" when you use 'ls -a' but not when you use 'ls' since it is a hidden file. You can also combine two options to type ls -la.