Grabbed from:
http://www.astro.rug.nl/~kuijken/latex.html [20001211]
Some changes have been made by me, for me. [zrajm]
The best use of LaTeX is for long, complicated documents with lots of formulas and few pictures. Trust me on this one...
It does a good job for documents that *need* structure, allowing you the flexibility to easily modify the text, without worrying about how it's going to turn out.
LaTeX is actually a set of macros on top of the TeX document preparation system. This describes only the formats of LaTeX.
The format of a document is pretty simple:
\documentstyle{There are, as implied by the comment above, many different 'styles' of documents. The ones that I know of (I haven't bothered to actually create any styles of my own :) are:} ... this is called the preamble .... \begin{document} ... nice text and actual work here .... ... this is called the body ... \end{document}
style: letter article report book slides
There are several nice formatting tricks that LaTeX does, depending upon which format you use.
The following characters are illegal TeX input (except if you know how to use them, of course):
# $ % & ~ _ ^ \ { }DON'T use these unless you know what you're doing! In order to get what you expect, type a '\' in front of them:
\# \$ \% \& \~ \_ \^ \\ \{ \}Notice that the comment character in LaTeX is the '%' character. Comments start from the comment character until the endofline.
LaTeX also allows freeform text input. This means that it doesn't matter how many tabs, spaces you have, LaTeX has its own idea of what your document will look like. It is important to note that a single newline is NOT enough to make different paragraphs. There has to be at least two of them to separate the paragraphs.
\documentstyle{article} % define a macro \def\texpsfig#1#2#3{\vbox{\kern #3\hbox{\special{psfile=#1}\kern #2}}\typeout{(#1)}} \input epsf % load the epsf library \begin{document} % Insert the graphic and put a border around it \centerline{\texpsfig{test.eps}{4.563in}{3.813in}} \makebox[4.563in]{\rule{0in}{3.813in}} \end{document}For more information on this (at your own risk), see dvips(1).
\renewcommand{\baselinestretch}{2}For other spacing (ie triple) just change the 2. Now doesn't that just seem intuitively obvious? :)
\begin{tabular}{|l|r|c|} Person & Money Owing & Silly Comment \\ \hline Mr. Cairo & $1943.12 & pay him again, Sam \\ \hline Mr. Pink & \$55.55 & what robbery? \\ \hline Mr. Scaramanga & \$666.00 & the golden rule \\ \hline Mr. Capone & \$300.51 & bad accountants \\ \hline \end{tabular}Things to notice:
This ought to fix it:
\special{landscape}Note however, that xdvi(1) currently barfs all over the virtual rugscape, as it does not understand the landscape option.
A voice from the Netherland wilderness yells: "No wait! There is a way":
xdvi -paper a4r filename(Thanks to Peter@infolab8@kub.nl for this suggestion)
Alternatively, use dvips to do it:
dvips -t landscapeSee dvips(1) for more information and other options.
\documentstyle[options]{style} style: article report book slides options: 11pt 12pt twoside twocolumn titlepage leqn openbib fleqn \pagestyle{style} style: plain empty headings myheadings \pagenumbering{style} style: arabic roman alph Roman Alph
\maketitle \begin{titlepage} ... \end{titlepage} \begin{abstract} ... \end{abstract}
\label{key} assign current counter value to key \ref{key} print value assigned to key
\bibliography{...} \begin{thebibliography}{label} ... \end{...} make bibliography; lable is the widest entry label \bibitem[label]{key} begin bibliography entry for citation key with label as its label \cite[note]{keys} cite reference(s) keys with added note
\input{file} read the file \include{file} read the file unless not in \includeonly{} \includeonly{filelist} exclude any file not in filelist
$ ... $ or \( ... \) intext formulas \[ .. \] displayed formulas \begin{equation} ... \end{equation} a numbered equation \begin{eqnarray} ... \end{eqnarray} numbered equations, like 3 column array enviroment \nonumber omits one equation number, eqnarray* omits all _{ ... } subscript. NB: don't need the braces for one character ^{ ... } superscript. NB: don't need the braces for one character ' prime \frac{n}{d} print the numerator over the denominator \sqrt[n]{arg} the nth root of the argument arg ellipsis \ldots ... \cdots ... \vdots ... Greek letters \alpha ... \omega and \Alpha ... \Omega delimiters \left or \right followed by delimiters \overline{expression} print a rule over the expression space thin \. medium \: thick \; negative thin \!
\begin{quote} ... \end{quote} short displayed quotation \begin{quotation} ... \end{quotation} long displayed quotation \begin{flushleft} ... \end{flushleft} left flush lines, separated by \\ \begin{center} ... \end{center} centered lines, separated by \\ \begin{flushright} ... \end{flushright} right flush lines, separated by \\ \begin{verse} ... \end{verse} \\ between lines, blank line between stanzas \begin{verbatim} ... \end{verbatim} in fixedlength, typewriter face exactly as formated - use any characters you like!
\begin{itemize} ... \end{itemize} a 'bulleted' list \begin{enumerate} ... \end{enumerate} a numbered list \begin{description} ... \end{description} a list of labelled items
quotes single ` ... ' and double `` ... '' (separate with small space \, if double quote is followed by aphostrope or vice versa, if you literaly want two aphostropes place empty brackets between '{}') dashes intra-word: - number range: -- punctuation: --- emphasis {\em } unbreakable text \mbox{ ... } footnotes \footnote{ ... } date \today
\rm roman \em emphasis \bf boldface \it italic \sl slant \sf sans serif \sc small caps \tt monospace typewriter face \boldmath use bold math symbols
\tiny \small \large \huge \scriptsize \normalsize \Large \Huge \footnotesize \LARGE
\'{o} \`{o} \~{o} \v{o} \c{o} \={o} \H{o} \d{o} \^{o} \.{o} \t{o} \b{o} \"{o} \u{o} \dag \ddag \S \P \copyright \pounds
\part \section \paragraph \ chapter \subsection \subsubsection \subparagraph \appendix no output, but the next sectioning commands are in the appendices \tableofcontents create a table of contents
\linebreak[n] force [or encourage] a linebreak; 0 <= n <= 4 \nolinebreak[n] forbid [or discourage] a linebreak; 0 <= n <= 4 \\[len] start new line and leave len vertical space [[doesn't align the right margin of the broken line]] \- permit hyphenation \begin{sloppypar} ... \end{sloppypar} Don't complain about lines that are a bit too long or too short
\pagebreak[n] force [or encourage] a page break; 0 <= n <= 4 \nopagebreak[n] forbid [or discourage] a page break. 0 <= n <= 4. \samepage Only break pages in between paragraphs \newpage Begin a new page \clearpage Prints all figures and tables on the page and begins a new page
\mbox{...} \makebox[wd][pos]{...} make box of width wd; pos puts text at (l)eft, (r)ight, or center pos defaults to center \fbox{text} \framebox[wd][pos]{text} Same as \mbox or \makebox except draws a box around the box \newsavebox{cmd} defines cmd as a "bin" for saving boxes into \sbox{cmd}{text} \savebox{cmd}[wd][pos]{text} same as \mbox or \makebox but saves the box in bin cmd \usebox{cmd} Print the box saved in bin cmd \begin{minipage}[pos]{wd} ... \end{minipage} make a parbox of width wd, aligned by pos at (t)op, (b)ottom, or center line. center is the default \parbox[pos]{wd}{...} same as minipage for small amounts of text, no displayed environments.
units: cm, em, ex, in, pc, pt, mm cm Centimetres em The width of the letter M in the current font ex The height of the letter x in the current font in Inches pc Picas (1pc = 12pt) pt Points (1in = 72.27pt) mm Millimetres \newlength{cmd} define cmd to be a length \setlength{cmd}{len} set length of cmd to be len \addtolength{cmd}{len} add len to length cmd \settowidth{cmd}{txt} set cmd to width of txt
\baselinestretch A decimal value for the spacing. Example: To set doublespacing on your document, use the command: \renewcommand{\baselinestretch}{2} \textwidth The normal width of the text on the page Example: To change this, use the command: \setlength{\textwidth}{x} where x is a length. NOTE: If you change the textwidth, you will almost certainly want to change the evenside and oddsidemargin \textheight The normal height of the body of a page. \oddsidemargin One inch less than the distance from the left edge of the paper to the left margin of the text on righthand pages \evensidemargin The same as \oddsidemargin except for lefthand pages \marginparwidth The width of marginal notes \marginparsep The amount of horiz. space between the outer margin and a marginal note \topmargin One inch less than the distance from the top edge of the paper to the top of the page's head \headheight The height of a box containing the header \headsep The amount of vertical space between the header and the body of a page \topskip The minimum distance from the top of the body to the bottom of the first line of text \footheight The height of a box containing the page's footer \footskip The distance from the bottom of the last line of text in the body to the bottom of the footer
\hspace{len} Make len horizontal space. NOTE: len can be negative \hfill \hrulefill Fills the current line with space. With \hrulefill, the space is underlined. Example: If you want to create a form that says Name: __________, where the underline is 3 inches long, use this: Name: \makebox[3in]{\hrulefill} \vspace{len} Leave len vertical space.
\begin{picture}(x,y)(x',y') ... \end{ ... } x by y picture with the lower left corner at (x',y') \put(x,y){ ... } put object at point (x,y) \multiput(x,y)(deltax,deltay){n}{ ... } make n copies of the picture with the first at (x,y) and others offset by (deltax,deltay) \makebox(x,y)[pos]{ ... } make x by y box; pos puts object at top (t), bottom (b), left (l), right (r), and / or centered (default); \framebox and \savebox have analogous forms \dashbox{d}(x,y)[pos]{ ... } like \makebox but puts dashed lines of length d around box \line(h,v){l} line of slope h by v and length l; 0 <= h, v <= 6 \vector{h,v}{l} same as \line but draws arrowhead; 0 <= h, v <= 4 \shortstack[pos]{ ... } like \begin{tabular[pos] ... \circle{d} draw circle of diameter d; * form draws solid disk \oval{x,y}[partial] draw x by y (partial) oval \frame{ ... } draw frame around object line thickness \thinlines or \thicklines
\begin{figure} ... \end{figure} make a floating figure \begin{table} ... \end{table} make a floating table \caption{ ... } make figure or table caption
Rows are separated by \\; columns determined by:\= set tab stop \> go to the next tab stop \kill throwaway line
\begin{array}[pos]{cols} ... \end{array} \begin{tabular}[pos]{cols} ... \end{tabular}Use array for fomulae; tabular for text. Items separated by '&' and rows by '\\'; pos aligns with top (t), bottom (b); cols entries format columns
l leftjustified column r rightjustified column c centered column | vertical rule @{ ... } text or space between columns *{n}{ ... } equivalent to n copies of ... \multicolumn{n}{col}{ ... } span next n columns with col format \hline draw horizontal rule between rows \cline{i-j} horizontal rule between columns i-j
\newcommand{cmd}[n]{ ... } define new command cmd with n arguments \newenvironment{name}[n]{beg}{end} define new environment name with n arguments \newtheorem{name}{caption} define a theoremlike environment name captioned by caption
\setcounter{ctr}{n} set counter ctr to n \addtocounter{ctr}{n} add n to counter ctr
The following is an example latex session of a document called 'final.tex'. You can see that latex usually complains a lot, for no good reason. Don't worry about it. That's what it does...
cab017% latex final.tex This is TeX, C Version 3.14t3 (final.tex LaTeX Version 2.09 <7 Dec 1989> (/usr/TeX/tex/macros/report.sty Document Style `report' <13 Nov 89>. (/usr/TeX/tex/macros/rep10.sty) (/usr/TeX/tex/macros/titlepage.sty)) (final.aux (budget-mechanical.aux) (budget-electrical.aux) (budget-motor.aux) (budget-sensor.aux)) [0] (final.toc [1]) [2] Chapter 1. [3] Chapter 2. [4] (budget-mechanical.tex Chapter 3. [5] [6] [7] [8]) [9] (budget-electrical.tex Chapter 4. [10] [11] Overfull \hbox (24.54887pt too wide) in paragraph at lines 107--120 [] [12] [13] [14] [15] Overfull \hbox (1.5408pt too wide) in paragraph at lines 356--364 [] [16]) [17] (budget-motor.tex Chapter 5. [18] [19] [20]) [21] (budget-sensor.tex Chapter 6. [22] [23] [24] [25] [26]) [27] [28] Chapter 7. (beam.tex [29] [30] [31] (final.aux (budget-mechanical.aux) (budget-electrical.aux) (budget-motor.aux) (budget-sensor.aux)) ) ) (see the transcript file for additional information) Output written on final.dvi (32 pages, 69940 bytes). Transcript written on final.log.You can view the document by running xdvi:
cab017% xdvi final.dvi &xdvi should be fairly selfexplanatory. Note that you can 'page' forward through xdvi with the space bar (or n), backward with p, and quit with q. Those are useful enough, if you find something else, tell somebody.
If you find that you like your document, you can pump out a PostScript file by using the command dvips, a la:
cab017% dvips final.dviThis creates a PostScript file in your current directory called 'final.ps'. You can print it to your local printer using lpr:
cab017% lpr -h -Pcab_sparc1 final.psCAVEAT: DO NOT PRINT THIS TO A DECWRITER!
A PostScript file typically contains about 40 pages of crap, then the actual document. You *really* don't want to kill the printer, your print quota and the eardrums of people in the room beside you, SO DON'T SEND IT TO A DECWRITER!!!!
ifthen Makes it possible to use \ifthenelse and \whiledo loops and ifs. calc Make arithmetics much simpler! vmargin A good package to make it easier to set the margins. babel Hyphenation patterns etc. for different languages. For Swedish use: \usepackage[T1]{fontenc} % add åäö \usepackage[swedish]{babel} avantgar A sanserif typeface (Avantgarde). charter A serif typeface (Charter). tipa International Phonetic Alphabet. (Not standard, download it somewhere.) cd-cover Use this to produce CDcovers and booklets. (Not standard, download it somewhere.)
There are two parts to the process:
...text that needs a reference to the Guide\cite{nopanic}(page 42)Simple enough, eh?
@where the document type is one of:{label,AUTHOR= "",TITLE= "", ... }
book unpublished article misc proceedingsand 'label' is how you want to refer to the entry.
Here is a sample bibliography file:
@book{booklabel, % Used when you \cite{this work} AUTHOR = "First Last Name", TITLE = "Name of the Book", VOLUME = 2, % The volume number -- not needed Publisher = {Publisher}, Address = {City, Province/State,Country}, Year = 1994} % The year the book was published @unpublished{unpublishedlabel, AUTHOR = "First Last Name", TITLE = "Name of the Work", Publisher = {Publisher}, Address = {City, Province/State,Country}, note= {Just to let you know that BibTeX is fairly flexible...}, Year = 1994} % The year the work was published @misc{misclabel, TITLE = "Title of whatever it is"} @article{articlelabel, AUTHOR = "First Last Name", JOURNAL = {The Harvard Journal of Really Stinky Things}, PAGES = {137 -- 142}, TITLE = "Spiritual Aspects of Locker Room Socks", VOLUME = 65, NUMBER = 5, YEAR = 1992} @proceedings{proceedingslabel, EDITOR = "Name of the Editors", TITLE = "Title of whatever it is"} Publisher = {Publisher}, Address = {City, Province/State,Country}, Year = 1994} % The year the proceedings was published
\documentstyle{article} \renewcommand{\baselinestretch}{1.5} \setlength{\topmargin}{0pt} \setlength{\textheight}{10in} \setlength{\parindent}{0pt} \setlength{\textwidth}{5.5in} \setlength{\topskip}{0in} \setlength{\headheight}{0in} \setlength{\headsep}{0in} \pagestyle{empty} \setlength{\oddsidemargin}{.5in} \begin{document} \begin{center} {\LARGE \bf UACS EXECUTIVE ELECTIONS NOMINATION FORM} \vspace{.25in} \begin{tabular}{ll} Position running for: & \makebox[2in]{\hrulefill}\\ Name of candidate: & \makebox[2in]{\hrulefill} \\ email: & \makebox[2in]{\hrulefill} \end{tabular} \end{center} \Vspace{.2in} \hspace{0.5in}I, \makebox[2in]{\hrulefill}\hspace{-2in}\makebox[2in]{\raisebox{-0.5em}{\tiny Name (please print)}} nominate \makebox[2in]{\hrulefill}\hspace{-2in}\makebox[2in]{\raisebox{-0.5em}{\tiny Name (please print)}} as\\ a candidate for the position of \makebox[2in]{\hrulefill}.\\ email: \makebox[2in]{\hrulefill}\hspace{.5in}Signature: \makebox[2in]{\hrulefill} \section*{Supporters:} \begin{tabular}{lrr} Name: & \makebox[2in]{\hrulefill} & Signature: \makebox[2in]{\hrulefill}\\ email: & \makebox[2in]{\hrulefill} & \\ \ \\ Name: & \makebox[2in]{\hrulefill} & Signature: \makebox[2in]{\hrulefill}\\ email: & \makebox[2in]{\hrulefill} & \\ \ \\ Name: & \makebox[2in]{\hrulefill} & Signature: \makebox[2in]{\hrulefill}\\ email: & \makebox[2in]{\hrulefill} & \\ \ \\ Name: & \makebox[2in]{\hrulefill} & Signature: \makebox[2in]{\hrulefill}\\ email: & \makebox[2in]{\hrulefill} & \\ \ \\ Name: & \makebox[2in]{\hrulefill} & Signature: \makebox[2in]{\hrulefill}\\ email: & \makebox[2in]{\hrulefill} &\\ \end{tabular} \section*{Candidate Information} \begin{tabular}{lll} Are you a UACS member? & Yes: $\bigcirc$ & No: $\bigcirc$ \\ Are you in the CS program? & Yes: $\bigcirc$ & No: $\bigcirc$ \\ If no: Are you applying for CS? & Yes: $\bigcirc$ & No: $\bigcirc$ \end{tabular} \vspace{.25in} Current Department: \makebox[1.5in]{\hrulefill}\hspace{.25in}Year: \makebox[.5in]{\hrulefill}\hspace{.25in}ID\#: \makebox[1in]{\hrulefill} \ \\ Date: \makebox[2in]{\hrulefill} \hspace{.5in} Signature: \makebox[2in]{\hrulefill} \end{document}
\documentstyle{letter} \begin{document} \address{Your name (Confused? Check your Student ID :) \\ address \\ postie code} \begin{letter}{ To whomever you're addressing/threatening \\ their address \\ their postie code} \opening{addressee} ... references to pets, burning, and other childhood activities... \signature{Your name (See above)} \closing{Yours untruthfully, and backstabbingly (love),} \end{letter} \end{document}
\documentstyle{article} \begin{document} \title{JFK Assasination: Who Dunnit?} \author{Who Me \and Not U \and Not Me Really} % Optional: LaTeX will put in current date if you don't % put in the \date command \date{November 22, 1963} \maketitle \pagebreak \section{Dallas, Texas Assisination of JFK} ... describe this conspiracy ... \subsection{The ``Magic Bullet'' Theory} ... an alternative physical modelling ... \subsubsection{The Warren Commission's Findings} ... blah, blah, blah .... \section{The Aftershocks} ... Yet Another Section ... \section{Who Gained From the Murder?} ... Even more indepth stuff ... \end{document}
Notice that this has a table of contents (toc). This means that you have to run latex over the file twice in order for the toc entries to come out correctly.
\documentstyle{book} \begin{document} \tableofcontents \pagebreak \chapter{The First Chapter} \include{number1} % So this chapter includes a file called 'number1.tex' % in the current directory \chapter{Now for the Second Chapter} \include{blah/number2} % So this chapter includes a file called 'number2.tex' % that is in the 'blah' directory \chapter{The One Worth Waiting For} This could have been an interesting bit\footnote{One of eight} except that it has been shown to be injurious to your health \cite{nothealthy}(page 666). \begin{quote} ``NO, YOU FOOL!!! Don't you know that process cheese is {\bf CONDUCTIVE}!!!'' \end{quote} \section{Well, Not Really} \subsection*{Umm, Just a Throwaway, Actually} \subsubsection*{It Only Fills Space Meaninglessly} % Note that when you put the asterisk '*' in front of % the text, that the section, subsection etc DOES NOT appear % in the table of contents \appendix \chapter{And now for the Technical Stuff} \include{appendicitis} \nocite{notseen} % Do this so that something you didn't % reference makes into your bibliography \pagebreak \bibliographystyle{plain} \bibliography{different} % references a file called % 'different.bib' \end{document}
setenv TEXEDIT "/usr/ucb/vi +%d %s"This sets the editor to be 'vi' and tells 'vi' to put the cursor at the '%d'th line of the file. For bash users, the variable can be set by:
export TEXEDIT="/usr/gnu/bin/emacs +%d %s"This will run the 'emacs' editor.
The line that LaTeX found the error on will then be displayed. At this point, you'll have to know what the error is or you can't compile the document. Sorry, you're on your own.
LaTeX is very good at documenting its work and puts a lot of information, including error messages, into a log file. For businessletter.latex, it will be called businessletter.log. Every error is described there as best as LaTeX can, together with a line number, which helps to quickly find the right place in a file.
Although the visual method of finding errors with the help of xdvi is probably best for a beginner, there is one category of bugs that requires a different approach - the famous Overfull box. LaTeX produces that message when it cannot properly break a line of text or hyphenate a word, which happens quite often when trying to print a long web page address.
The quickest way of finding those messages is by using grep:
grep Overfull businessletter.log | lessAfter issuing the above command in an Xterm window, you will see either an empty window (a good thing) or a list of lines where LaTeX has put the ominous word. Go back to Emacs, find the offending lines, then use xdvi to judge how to best fix your document.
Further note that the LaTeX book by Leslie Lamport was originally used (sigh) without permission to create the Commonly Used Commands section.
For some sample ideas and documents, we have to thank: Steve Charlton, Andrew Morris and lots of other people.
In the directory /usr/TeX/tex/macros you find the following files:
btxdoc.tex lablst.tex psfig.tex tb0cyr.tex btxhak.tex latex.tex rotate.tex tb0hyf.tex btxmac.tex lfonts.tex sample.tex testfont.tex epsf.tex logo.tex sfonts.tex testpage.tex hyphen.tex lplain.tex slides.tex tryfonts.tex idx.tex manmac.tex slitex.tex tubguide.tex idxmac-amstex.tex mftmac.tex slogofonts.tex tugbot.tex idxmac.tex nul.tex small.tex webmac.tex ind+.tex null.tex splain.tex ind-.tex plain.tex story.texYou can copy these and latex 'em, and read 'em. Won't you? :)