CS 473: Latex Tutorial
- This is supposed to be a very basic latex tutorial that gives you enough knowledge to typeset your CS473 homeworks.
- First you should install Latex on your computer.
You could use one of these distributions:
TeXShop for Mac OS X,
TeX Live for Linux (already included in many distributions),
and MiKTeX for Windows.
Another option is to use the installed Latex on EWS terminal server, you should
connect to linux.ews.illinois.edu via SSH.
- Assume you want to write the solution to problem 1 of hw0.
Create a directory with name hw0-problem1 somewhere in your machine.
- Download this file, template.tex, change its name to hw0-prob1.tex, and put it inside that diretory.
- Open a command prompt ("command shell" or "terminal" in linux and mac) and cd to the directory hw0-problem1.
- Run this command to compile the template: pdflatex hw0-prob1.tex. This should produce a pdf file with name hw0-prob1.pdf.
- View the pdf file with a pdf viewer. It should look like this pdf file.
- Close the pdf viewer (with some viewer you may not need to do this step).
- Open your tex file, hw0-prob1.tex in a text editor (notepad, emacs, vi, ...).
- Look for the line that says "Homework x, problem y". Edit it into "Homework 0, problem 1" (since we are writing
the solution to problem 1 of homework 0).
- Look for the line that says "sariel, im3, zamani". Edit it into netids of your group members, for example
edit it into "mynetid, yournetid, hisnetid".
- Now look for the lines that say "%START OF YOUR SOLUTION" and "%END OF YOUR SOLUTION".
(Note that every thing on a line following percent symbol is being considered as a comment by the Latex compiler.)
You should edit the text between these two lines into your solution. For example edit the first occurence of "This is our solution"
into "Something else". Save the file using your text editor.
- Compile your tex file (run pdflatex hw0-prob1.tex). Then open the pdf and watch. You should see your group netids and
the hw/problem number updated at the top of the file, and the first line of solution should be "Something else".
- Note that the pdf file shows you three paragraphs. Look at the tex file to see these paragraphs are generated
just by putting some empty lines in the text. Note that there is more space between second and third paragraph,
if you look into the tex file, you can see this Latex command: \bigskip that produces extra space
between two paragraphs. The very first two lines of the pdf file (problem number and netids) are inside the same paragraph
but somehow we have managed to finish the first line before we fill it completely, if you look into the tex file
you can see the Latex command \newline that makes Latex to start a new line.
- To tell latex to behave an expression as a mathematical formula, we can enclose it with two dollar signs.
For example if Latex sees $a+b$ it will typeset it in its mathematical mode.
- Look into the tex file now to see $\alpha / \beta = \gamma$. This is the tex expression that produces the
formula you saw in the pdf file. Latex commands \alpha, \beta and \gamma produce the greek letters (they should be used
inside the math environment, for example enclosed between dollar signs).
So you need a way to figure out which command produces the symbol that you need. Most of the time you can do this
by googling to find a list of symbols. For example this
is a list of math symbols. This
is a more comprehensive list. Detexify
is a cool tool that allows you to draw a symbol and suggets a list of possible commands that you are looking for.
- To produce a2 the command is $a_2$ and to produce a2 you should type $a^2$.
You can use brackets to group terms in Latex, for example to produce (a+b)c+d you can type
$(a+b)^{c+d}$.
- We recommend you to read this
short introduction to math in Latex.
- Depending on what Latex compiler you are using, the variaty of image formats that you can include may change.
With miktex you can include bmp and jpg images while with some other compilers these things can't be included directly.
A pdf image is always guaranteed to work with pdflatex.
- First you should draw your image. Use a drawing tool that let's you save image as a pdf.
You might want to use Inkscape or IPE.
If you are lazy to draw a pdf image right now, we have one here for you to continue the tutorial.
- Download tree.pdf and put it in our directory hw0-problem1.
Open the tex file (i.e. hw0-prob1.tex) in your text editor and somewhere between
the lines "%START OF YOUR SOLUTION" and "%END OF YOUR SOLUTION" insert this command:
\includegraphics[width=2in]{tree.pdf}
Leave an empty line before and after this command (since we want this picture to have a paragraph for itself).
- Compile the tex file and see the output pdf. As you see the image is scaled such that its width is now 2 inches.