Setup and Tutorial
for Using LaTeX with TeXworks/MiKTeX
Introduction
LaTeX works like this:
· First, you use a text editor
(we'll be using TeXworks) to create a LaTeX document foo.tex (note:
"foo" is standing in for your file name).
· Then, you run a LaTeX compiler (we'll be using MiKTeX)
to turn the file foo.tex into foo.pdf.
· Finally, you need to use some kind
of viewer/previewer (we'll be using the one built into TeXworks)
to view or print the pretty formatted file foo.pdf.
You will do everything from TeXworks, which we
will set up to control MiKTeX. This document will
take you through the steps of downloading, installing, configuring, and working
with MiKTeX and TeXworks.
Be sure to follow ALL of the directions below, IN ORDER. Consider this the
first test of your logical thinking abilities!
I recommend that you print out this document so that you can refer to it
easily and check off steps as you do them. Don't be afraid to send me email or
stop by my office if you get really stuck. (Double-check that you have Actually
Followed The Directions before you do this!)
Downloading and
installing MiKTeX/TeXworks
- Go to http://www.miktex.org/download.
- Click the “Download Basic MiKTeX
2.9” button.
- Save the file (it should be called something like
“basic-miktex-2.9.3248.exe”) to a place where you can find it.
(The default is the folder “D:\Data\Documents\Downloads”.) If
you are using a wireless connection on campus, this might take up to 10
minutes to download. If you’re physically wired to the network it
will be much faster.
- After it finishes downloading, double-click on the file
to open it and select “Run” on the security warning. The Setup
Wizard will now open.
- Accept the license agreement and click
“Next” three times without changing anything. I mean it! Are
you changing something? Stop it!
- At the settings, choose “Letter” for preferred paper size and “Yes” for installing packages
on the fly. Click “Next” and then click “Start”.
- Wait for the computer to finish (~15 minutes) the
install and then click "Next" and “Close”.
- Throw away (put in the Recycle Bin) the installer
“basic-miktex-2.9.3248.exe” which is still located where you
downloaded it.
- Create a folder in your D:\ drive (NOT the C:\ Drive)
in which you will save all your future work.
- Please note that MiKTeX is a
shareware product. For a voluntary $15.00 donation they will provide
direct email support; see their registration
page.
Creating a simple
document using LaTeX
Now
we're finally ready to write a document in LaTeX. The
instructions below will take you through the process of creating a very simple
document.
- Open the TeXworks program.
This can probably be found in your Start Menu, Programs, MikTeX
2.9, TeXworks. You might want to make a shortcut
to this on the desktop.
- Write: In the TeXworks, type this:
\documentclass{article}
|
\begin{document}
|
Hello
universe! $2^2 = \sqrt{16}$
|
\end{document}
|
- Save: Save this file as "universe.tex" to whatever
directory you choose. Be sure the extension is "tex" and NOT
"txt”.
- Compile: Make sure the drop-down menu in your toolbar says
“pdfLatex”. Then either click the
compile button in the toolbar (looks like a green block with an arrow) or
press CTRL+T. If there are no compiling errors in your .tex file, then in
the same directory where you saved universe.tex should be three new files:
universe.aux, universe.log, and universe.pdf. These files will be updated
every time you run latex on universe.tex. Take a moment now to go to your
directory/folder and check.
POSSIBLE PROBLEM: If only the file universe.tex
is there then it is possible that your system does not know where MiKTeX is installed. If this happens, contact the
instructor for help.
- View: If there were no compiling errors in your .tex file,
then a copy of your document should have opened up in a separate window. If
nothing shows up, then see the section below about handling compiling
errors.
- Repeat: Now if you want to modify your file, go back and
repeat the steps above: Write, Save, Compile,
View.
Handling compiling
errors
LaTeX is a very picky typesetting program, and a lot of tiny
things can cause compiling errors. By following the instructions below you will
introduce an error into your universe.tex file and then see how to deal with
it.
- Change your universe.tex file so that it looks like
this:
\documentclass{article}
|
\begin{document}
|
Howdy
universe! $2^2 = \sqrt{16}$
|
The & is a special character.
|
\end{document}
|
- Save universe.tex and try to compile it (steps 2 and 3
above). Notice that the last line of the log file says that 1 error
occurred and that the & sign did not show up
in our output.
- Read the last few lines of information in the log
window. It should look something like this:
!
Misplaced alignment character &.
|
l.4
The &
|
is
a special character.
|
- In LaTeX, the
"&" character is used for tabbing (alignment) in certain
environments, but it is not a legal character on its own; that is what the
first line of the error message above is saying - that the character
"&" is being used somewhere it shouldn't. The
"l.4" at the beginning of the next line of the error message
tells you that the error is on line 4 (it says "lowercase ell dot
four" not "one dot four" at the beginning of the line).
Notice also that the line breaks where the compiler thinks your error
might be: at the "&" character.
- It's pretty clear that we need to get rid of or modify
that "&", but for the sake of this exercise, let's say you
don't understand the error message completely, but you do think that line
4 could be the culprit. One thing you can do is "comment out"
the line in question, by inserting a "%" symbol at the start of
the line. In LaTeX, the rest of the line
following a "%" symbol is ignored by the compiler. Do this, and
then compile again, and you should not get any errors.
- Of course, after the step above, you got rid of the
error, but you also didn't get the document to say what you wanted; let's
fix the error. In LaTeX, the character
"&" can be produced by typing "\&". Un-comment
line 4 (i.e. remove the "%" symbol) and put a backslash
"\" in front of the ampersand. Recompile and everything should
work.
Printing a finished
LaTeX document
If
you want to print right from the computer you are working on, it's easy; just
go to File à Print in the preview window.
If you want to print from a computer that does NOT have LaTeX
installed (or you want to send your file to someone who does not have LaTeX installed, but needs to see your beautiful typeset
file), in the same directory as you .tex file you should be find a .pdf file of
the same name and this can be viewed and printed by anyone, on any computer,
using Adobe
Acrobat PDF Reader.