This is a short worked example on how to write and build a LaTeX document. Note that this is not a primer on the language! You should get hold of the Not so short Introduction to Latex for a more complete introduction.
Because this is just a trivial example on how to use LaTeX, not on how to actually write LaTeX documents, my example .tex file won't contain a lot. LaTeX can do plenty more than I'm demonstrating below -- make sure you read the better references mentioned above.
\documentclass[12pt,a4paper]{report} \pagenumbering{roman} \title{Latex Example} \author{Daniel Lawson} \date{\today} \begin{document} \maketitle \begin{abstract} \end{abstract} \tableofcontents \newpage \section{Introduction} This is a quick introduction to using Latex. \subsection{Example} Here is a subsection. \section{Conclusion} In conclusion, this example doesn't show a lot. Go read the Not So Short Introduction to \LaTeX for more information. \end{document}
Seeing as we're not doing anything complicated with LaTeX, we only need to parse the file once. If you were doing more complicated things, such as including a bibliography, you'd need to run a few more programs. See LatexMakefiles on more tips for that.
Run latex example.tex in the directory you saved your example.tex in earlier.
$ latex example.tex This is TeX, Version 3.14159 (Web2C 7.3.7) (./example.tex LaTeX2e <2001/06/01> Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, n ohyphenation, loaded. (/usr/share/texmf/tex/latex/base/report.cls Document Class: report 2001/04/21 v1.4e Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size12.clo)) No file example.aux. [1] [1] No file example.toc. [1] [2] (./example.aux) ) Output written on example.dvi (4 pages, 1180 bytes). Transcript written on example.log.
This completed successfully, outputting some extra files created by LaTeX on the way -- the .aux and .toc files are used for internal references. The .dvi file is the first output file.
You can view this with a program called xdvi:
xdvi example.dvi
DVI is a Device Independent format, which in theory makes it really useful. However, it tends to be harder to view in Certain OperatingSystems. Instead, you should convert your .dvi to a PostScript or PDF file:
$ dvips example.dvi -o example.ps This is dvips(k) 5.86e Copyright 2001 Radical Eye Software (www.radicaleye.com) ' TeX output 2004.12.16:1220' -> example.ps $ dvipdf example.dvi example.pdf $ ls *ps *pdf example.pdf example.ps <texc.pro>. [1] [1] [1] [2]
You can now view these with a PostScript or PDF viewer, such as GhostView or AcrobatReader.
One page links to LatexExample: