CS 141
Intro to Artificial Intelligence
Greenwald

Lab 1

Contents

    1  Introduction

    2  How to use LATEX

    3  Headers and Templates

    4  Basic LATEX
        4.1  Environments

    5  Simple commands

    6  Sections

    7  Lab Work

    8  Resources

1  Introduction

LATEX (pronounced lah-tech) is a typesetting system for creating high-quality documents. It allows you to create complex-looking output from a simple text file.

Why should you learn LATEX?

As CS 141 is a paperless class, we will be requiring electronic documents (.pdfs preferred) to be handed in. Some CS 141 assignments may include mathematical formulas, which will be easier to typset using LATEX documents. The purpose of this lab is for you to become familiar with LATEX ahead of time, but you don’t need to feel like you’ve mastered it. TAs on hours will always be happy to help you use LATEX.

You’ll notice that there are no specified tasks in this lab. The idea is for you to experiment on your own. You can spend as much or as little time working as you like.

2  How to use LATEX

Unlike Microsoft Word (but similar to HTML), LATEX is not “what you see is what you get” (WYSIWYG). You type your document in a text editor using a special notation, and then LATEX reads your document and produces a PDF.

The easiest way to create LATEX documents is by using a program called Kile. Kile is a text editor with a number of features that make working on LATEX documents simpler. It also includes a “Quick Build” feature, which will automatically process the document you’re working on and display the output.

For CS 141, we recommend that you use Kile, but LATEX does not require any particular text editor. The rubber program will convert a text file into “DVI” format, and the dvipdf program will convert the DVI file into a PDF. For example:

vim foo.tex
rubber foo.tex
dvipdf foo.dvi

3  Headers and Templates

A LATEX document needs to contain a header which tells LATEX how to process it. Luckily, the template we give you already comes with correct headers, so all you need to do is enter your name, login, and the assignment name/number, and you’re good to go.

A template is available at /course/cs141/templates/hw.tex. When you are writing documents for CS 141, you can always start from this template.

Copy the template to your home directory, open it in Kile, and work along, trying out the examples as we go. Make sure you can open it in Kile and use the quick build function (it’s the icon in the upper-right portion of the screen that has a page, a blue gear, and a lightning bolt). If you have trouble, ask a TA for help.

4  Basic LATEX

This is a typical boring and repetitive introduction. This is a typical boring and repetitive introduction. This is a typical boring and repetitive introduction. This is a typical boring and repetitive introduction. This is a typical boring and repetitive introduction. This is a typical boring and repetitive introduction. Note how nicely the lines wrap.

A new paragraph is generated each time you leave a blank line in the source file.

There are a few special characters in LATEX:

# $ & ~ _ ^ \ { } %

Any other character that you type will appear literally in the output file.

Other than literal text, there are two kinds of expressions in LATEX. The main type of expression looks like this:

\command{arg1}{arg2}...

These commands can take arguments using {} and []. You will see some examples of this type of expression later on.

The other type of expression looks like this:

$1+2+3+4$

and is used for typing math.

4.1  Environments

Sometimes, you want to format a whole region of text in a specific way. To do this, you use something called an environment. You begin an environment by typing \begin{name-of-environment}, and end it with \end{name-of-environment}. Everything in between is part of the environment.

5  Simple commands

The \emph command prints a region of text with emphasis. For example:

\emph{This is really important.}


This is really important.


You can also use explicit formatting. For example:

You can make text

\textbf{bold},

\textit{italic},

\texttt{typewriter-y}.


You can make text

bold,

italic,

typewriter-y.


A basic principle of writing good LATEX documents is that you should say what a region means, rather than how it should be formatted. A “style” file then explains how to convert the “what” to the “how” throughout the document to get a uniform style.

LATEX doesn’t force you to follow this rule. For example, you could say “I want italics” instead of “this needs emphasis”. But then, when you decided to use boldface or small-caps instead of italics to mean emphasis, you’d need to change things all over your source file. That’s bad.

The \footnote command makes a footnote. For example:

\footnote{Look! I can make a footnote, too!}


1


6  Sections

You can create sections, i.e. logical divisions in your document, using the \section{...}, \subsection{...}, and similar commands.

  \section{Why \LaTeX\ is great}
  \subsection{Coolness Factor}
  ...
    \section{\LaTeX\ Web Sites}
  ...


1  Why LATEX is great

1.1  Coolness Factor

...

2  LATEX Web Sites

...


7  Lab Work

First take a look at the example file in "/course/cs141/templates/example". Here you'll see a few LATEX formatting examples - lists, matrices, etc.

Now grab a copy of the "hw.tex" template in the same directory, and copy it into your home directory. In order to get a little practice with this template, try:

  1. Writing a paragraph that makes use of boldface, italics, and typewriter-y text.
  2. Use math mode - write out the quadratic equation, making sure the fractions align:

  3. Using the newalg package, writeout a simple algorithm (bubble sort, for instance). You may want to take a look at the newalg pdf below.

Make sure you use sections to order the problems.

8  Resources

Some LATEX resources: