TEX and LATEX Someday you will want to publish the results of your research. IGPP scientists typically use either Word of Latex for this purpose (some old timers still use troff, a UNIX precursor to LaTeX). Most of you probably already know how to use Word. It is very easy to use (WYSIWYG) and is the "standard" word processor of choice in many institutions. It is not, however, ideal for writing scientific articles. It has particular difficulty handling equations and specialized typesetting requirements. A far better choice is TeX or LaTeX. Advantages of LaTeX: (1) It is in the public domain so you are not supporting the Evil Empire. (2) You can run it on Macs, PCs or UNIX machines. (3) By using macros, it is a far more powerful and versatile system than all that pull down menu crap you find in most commercial word processors. (4) AGU uses LaTeX for its electronic submission of articles and abstracts. They provide macros to match the style of their journals so that preparing camera-ready copy is trivial. (5) You can produce beautiful looking equations much more easily than with programs like Word. LaTeX takes a little while to learn at first, but you will find it well worth your effort. ************************* LaTeX on the Macs ****************************** On the Suns, you can invoke LaTeX just by typing latex and the file name. This should also work on the Macs under X11 and is described below in the notes. However there exist LTteX interfaces for the Mac that make the typesetting process much more convenient. I have been using TeXShop, which is free and should be installed on the Macs in the Barnyard. There is at least one other free version of LaTeX for the Macs but I don't have any experience with it yet. You can get TeXShop for your own machine via fink but this is rather complicated--you might want to ask NetOps for help in doing this. I believe Tetex also has to be installed; Kris Walker's Mac OSX web site has some details on this. IMPORTANT: When you first use TeXShop, go to Preferences/Engine and set both "Path settings" to /sw/bin With TeXShop you can just hit the typeset button and see the typeset version side-by-side with your LaTeX source code. The program automatically generates a PDF file of your output. ************************************************************************** A SIMPLE EXAMPLE Use your favorite text editor to create the file samp1.tex: (samp1.tex) \documentclass{article} \begin{document} Today (\today) the rate of exchange between the British pound and the American dollar is \pounds 1 = \$1.63, an increase of 1\% over yesterday. \end{document} This is an example that I got from my Latex book (Kopka and Daly, A Guide to Latex2e) The document must first define a document class. Options are book, report, article, or letter. The guts of the document are then enclosed between the \begin{document} and \end{document} commands. This example highlights some of the special characters and macros in Latex. The following characters are normally interpreted as Latex commands: $ & % # _ { } To print these out in your text, you must precede them with a backslash, i.e., \$ \& \% \# \_ \{ \} In this example, \today invokes a macro to print today's date and \pound will print the British pound symbol. From this example you can see that Latex is not WYSIWYG! To typeset this document, enter: latex samp1 Assuming you have no errors in the input file, this will generate the file samp1.dvi. To preview this file, enter: xdvi samp1 To convert the file to a Postscript file, enter: dvips samp1 -o samp1.ps Notice that Latex automatically indented the first line of the paragraph. To avoid this, use the \noindent command for the target paragraph: \documentclass{article} \begin{document} \noindent Today (\today) the rate of exchange between the British pound and the American dollar is \pounds 1 = \$1.63, an increase of 1\% over yesterday. \end{document} To globally change the paragraph indenting, you can change the default for this directly: (samp2.tex) \documentclass{article} \begin{document} \setlength{\parindent}{0.5in} Today (\today) the rate of exchange between the British pound and the American dollar is \pounds 1 = \$1.63, an increase of 1\% over yesterday. \end{document} This will now indent all paragraphs by 0.5 inches. To remove paragraph indenting, just set this parameter to zero. Latex ignores the carraige returns at the ends of each line in the input file. It also ignores extra blanks; it only considers the first blank. New paragraphs are defined by adding a blank line between blocks of text. EXAMPLE WITH EQUATIONS (samp3.tex) \documentclass{article} \begin{document} \setlength{\parindent}{0.0in} The function $X(p)$ is more nicely behaved than $T(X)$ since it does not cross itself (there is a single value of $X$ for each value of $p$), but the inverse function $p(x)$ is multi valued. An even nicer function is the combination \begin{equation} \tau(p) = T(p) - pX(p), \end{equation} where $\tau$ is called the {\it delay time}. It can be calculated very simply: \begin{equation} \tau(p) = 2 \int_0^{z_p} \left[ {u^2 \over {(u^2-p^2)^{1/2}}} - {p^2 \over {(u^2-p^2)^{1/2}}} \right] \, dz \end{equation} or \begin{eqnarray} \tau(p) &=& 2 \int_0^{z_p} (u^2-p^2)^{1/2} \, dz \\ &=& 2 \int_0^{z_p} \eta(z) \, dz \end{eqnarray} where $\eta$ is the vertical slowness. \end{document} Note that equations within the text are enclosed with $ signs. \begin{equation} and \end{equation} are used to put the equation on a separate line. Variables within the equations are automatically put into italics. Greek letters are defined as \tau, \eta, etc. Equations are automatically numbered (this can be changed if desired). Subscripts are defined with the underscore (_), superscripts with the carat (^). Fractions are written as, for example, {x \over y}. \int is for the integral symbol; note how the limits are written. Curly brackets are used to separate things--they do not appear in the typeset version. The \begin{eqnarray} section is used to align the = signs in the two lines of equations. Note that &=& is used to define what it is that is being aligned. Every line except the last line has a carraige return (\\). Although TeX generally does an excellent job of spacing equations, sometimes some fine tuning will help. In this case \, is used to place a tiny amount of space before the dz. CHANGING THE DEFAULT PARAMETERS FONT SIZE There is a standard font size declared for each document class. In most cases this is Roman 10 pt. One easy way to change the size is with the following commands, arranged in increasing order of size: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge FONT ATTRIBUTES \itshape = switch to italics \slshape = switch to slanted font \upshape = switch to upright (normal) font \bfseries = switch to bold \mdseries = switch (back) to regular weight These commands can be invoked in several different ways to put "in situ" in italics and then return to normal font: \itshape in situ \upshape OR {\itshape in situ} OR \begin{itshape} in situ \end{itshape} These different options also apply to the font sizes listed above. Here is an example of how these options can be used: (samp4.tex) \documentclass{article} \begin{document} Let's test different ways to say \itshape in situ \upshape in italics. There are several different ways to say {\itshape in situ} in italics; indeed \begin{itshape} in situ \end{itshape} can be written in italics in at least three different ways. Next let's experiment with {\large large}, {\Large Large}, and {\LARGE LARGE} type, as well as {\small small}, {\footnotesize footnotesize}, and {\scriptsize scriptsize} type. \end{document} LINE SPACING There is a default line spacing created whenever a new font is selected. Here are examples of two different ways that this can be changed: \setlength{\baselineskip}{10pt} Change line spacing to 10 point (single spacing for 10pt font). \renewcommand{\baselinestretch}{2} Change normal (single) line spacing by a factor of 2. This will result in double spacing. This must be called before \begindocument or before a new font declaration. Here is an example: (samp5.tex) \documentclass{article} \begin{document} \setlength{\baselineskip}{20pt} Today (\today) the rate of exchange between the British pound and the American dollar is \pounds 1 = \$1.63, an increase of 1\% over yesterday. Let's write one more line here so that we get up to three lines and can see the spacing better. \end{document} INCLUDING GRAPHICS There are some differences in the way different versions of LaTeX handle graphics. Many versions permit you to embed EPS files but TeXShop requires PDF files, at least in the standard version. Fortunately, there are many ways to convert files to PDF, including an option within the Mac print command. Here is an example of including a pdf file: (samp6.tex) \documentclass{article} \usepackage{graphicx} \begin{document} \setlength{\baselineskip}{20pt} We are now going to show how to embed a Postscript file into a LaTex document. This is an example plot that can be windowed and positioned using the "viewport" option within the includegraphics commmand. This specifies (x1,y1,x2,y2) exactly what part of the page will be windowed and displayed. (NOTE: For Sun LaTeX, replace "viewport" with "bb" for bounding box) \begin{figure}[h] \begin{center} \includegraphics[viewport=2in 2.4in 7in 7.5in, scale=0.7]{plot1.pdf} \end{center} \caption{Here is the caption for this plot. This will be automatically positioned below the plot.} \end{figure} And then here is some more text to show where the next block of text will appear. Blah, blah, blah... \end{document} Note that the graphicx package is loaded with the \usepackage{graphicx} command at the start of the file. The \begin{figure} macro has various options for where the figure will be positioned, including at the present location in the text, or at the top or bottom of the page. The plot is windowed using the viewport= option and scaled to 0.7 times its original size. Figures are automatically numbered; users have control over the starting figure number. WANT TO KNOW MORE? Check out David McMillan's great Latex example file, ex.tex, which you can find on the class web site or on the Suns in ~shearer/CLASS/COMP/LATEX or via anonymous ftp to mahi.ucsd.edu in the pub/239 directory. The accompanying files psfig.tex, hobbes.ps, and gnufig.tex are also included there. NOTE: This file was designed for Sun LaTeX; not all of the figures will appear on the Mac unless some of the graphics input commands are changed to the TeXShop standard. A good Latex reference book is: Kopka, H., and P.W. Daly, A Guide to Latex 2e, Addison-Wesley, New York, 1995.