# Latex Tips

1. How do I get started in Latex? Use this template.

2. How do I get a "perpendicular" symbol in Latex? Put this before the \begin{document} command, to activate "\independent".
    \newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\setbox0\hbox{$#1#2$}%
\copy0\kern-\wd0\mkern4mu\box0}}

3. How do I use color in Latex? Before your \begin{document} command include these lines in your .tex file:
     \input colordvi
\def\Red#1{\Color{0 0.70 0.70 0.2}{#1}}
\def\Green#1{\Color{0.70 0 0.5 0.2}{#1}}
\def\Blue#1{\Color{0.70 0 0 0.2}{#1}}

Then, anywhere in your document, use e.g. Her eyes were \Green{hazel}.
You can create any colors you like by specifying the relative proportions of cyan, yellow, magenta, and black, as in the examples. Note that our xdvi previewer does not show the colors, but they will be in the postscript file and will be seen with both ghostview and on a color printer.

4. How do I get active web links in a pdf document? A sample tex file is pdfurl.tex. The pdf file produced is pdfurl.pdf.

5. Where are the sample files for the Latex users' manual? Look in /usr/statlocal/teTeX/share/texmf/tex/latex/localstyles/

6. How do I draw figures in Latex using the picture environment? The file DAG.tex shows an example of drawing a DAG.

7. How do I draw figures in Latex using metapost? Metapost is a powerful drawing/programming language that creates Latex compatable files. The manual is at http://www.tug.org/docs/metapost/mpman.pdf. A great set of examples is http://www.tlhiv.org/MetaPost/examples/examples.html. And an excellent tutorial is http://www.ursoswald.ch/metapost/tutorial.html. (An alternative to metapost is Asymptote.)

And here is a full example:

• First download VennTest.tex which is the LaTeX document that displays the pictures (and shows the LaTeX commands needed to do that).
• Then download ABVenn.mp which is metapost program. Run the program with the Linux command mpost ABVenn. If it worked, you will see that ABVenn.1 ... ABVenn.4 were created.
• Now run latex VennTest.
• IMPORTANT: xdvi won't show the labels, and may even give incorrect error messages.
• Run dvips -oVennTest.ps VennTest and ghostview VennTest.ps to see the full results, shown here as VennTest.pdf.

8. How do I use postscript files in my Latex documents? How do I get Greek or math for the embedded postscript files? To incorporate a postscript file, add the line \usepackage{graphicx} below your \documentclass line in your .tex file. Then use either of these forms in your document to incorporate myfile.ps:
  \begin{figure}[ht]
\begin{center}
\resizebox{6.5in}{5in}{\includegraphics[origin=c,angle=-90]{myfile.ps}}
\end{center}
\caption{\label{fig:xxx} The caption}
\end{figure}

\centerline{\resizebox{6.5in}{5in}{\includegraphics[origin=c,angle=-90]{myfile.ps}}}

You can change the width, height and angle as needed.

If you want to incorporate Latex math or greek into a postscript file, created in S or xfig, you can use "psfrag" to change codes, e.g. "xyz" or "frac0.5" into Latex expressions such as "\alpha+\beta=\gamma^2" or "\frac{1}{2}". (For R, use the plotmath() function.)

\psfrag{xyz}{\Large $\alpha+\beta=\gamma^2}$}
\psfrag{frac0.5}{$frac{1}{2}$}

to your latex file just above the \includegraphics line.

The "fragments" that are to be replaced (e.g. xyz or frac0.5) must be placed in the postscript file (e.g. myfile.ps) as separate items. For plots produced in S, this means a separate text("xyz") command. For figures produced with xfig, this means a separate use of the "text" command.

Now just run latex and dvips. The psfrag procedure doesn't work correctly on your .dvi file, but when you use dvips to create a .ps file, the substitutions will appear in the .ps file (when printed or when viewed with ghostview).

9. Is xdvi wasting time recreating fonts? Tom Nichols says:
With the new LaTeX (and maybe only with LaTeX 2.09 documents) if xdvi doesn't have a font it builds it (creating many screens full of crap) and tries to save it in /usr/statlocal somewhere. But unless you're on Tedium, /usr/statlocal is a read-only disk, so each time you run xdvi you get the same annoying crap... the solution of course is just to slogin to tedium, fire up xdvi the one time and then continue on your own machine.