How to run LaTeX on the Math Network Larry Leemis & techie Fall 2008 1. Create a LaTeX file (must have .tex suffix on the filename) using your favorite editor. Emacs is highly recommended because it has a special TeX mode. One can run latex and view output using a menu in Emacs without exiting. You might want to put the following in your .emacs file: ;; TeX (setq tex-default-mode 'latex-mode) (setq tex-dvi-view-command "xdvi") (setq tex-dvi-print-command "dvips") (setq tex-alt-dvi-print-command "dvips -Ppdf -o emacs.ps") Two more lines in .emacs will give you syntax highlighting also: ;; Font lock (global-font-lock-mode t) (setq font-lock-maximum-decoration t) One could change these options through Emacs' customization menu too. Example: create the file named fn.tex The typical file set up for a LaTeX file is a preamble (first few lines), followed by a \begin{document} command, followed by the body of the document, followed by an \end{document} command. LaTeX commands start with backslash '\'. Example: \documentclass[12pt]{article} % The comments in TeX start with a percent sign. % There are hundreds of extra packages for added functionality. % They should be delared in the preamble as follows: \usepackage{graphicx} % The latest and best graphics package \usepackage[small,bf]{caption2} % Caption smaller than text, % Label in bold font % Add here to yours heart content. There are packages for % all sorts of things including Arabic or musical notes % typesetting. One could say \usepackage{first,second,...} % See "LaTeX Companion" and "LaTeX Graphics Companion" for more. \title{Influence of Gnus on Gnats} \author{John Doe \\ Department of Mathematics \\ College of William \& Mary} \date{\today} \begin{document} \maketitle % put the title we prepared in preamble \begin{abstract} Whatever... \end{abstract} \section{Introduction} Work similar to ours is shown in \cite{good1998}. \(E = m\cdot c^2\) blah, blah ... % One can enter the inline math mode as $...$ or \(...\) % For diplayed equations use \[...\] \subsection{Motivation} The details are shown in Figure \ref{myfig} and Table \ref{mytable}. \begin{figure} \centering \includegraphics[width=4in]{mypic} % file is mypic.eps \caption{This is a figure} \label{myfig} \end{figure} % the priority of placement of figures (here, top, bottom) % can be influenced with \begin{figure}[htb] ... \end{figure} % or forced with the explanation point \begin{figure}[hb!] ... \end{figure} % one can get (sub)sections without numbers with \section* \begin{table} \centering \begin{tabular}{|l|l|r|c|} \hline A & B & 23.45 & D \\ \hline E & F & 2.56 & G \\ \hline \end{tabular} \caption{This is a table} \label{mytable} \end{table} % One can create a bibliography file (*.bib) for citations % easily in Emacs. Again, Emacs has a special mode and % everything can be added through the menus. See the example % file fn.bib below. % Keeping your bibliography in a BibTeX database is highly % recommended. \bibliography{fn} \bibliographystyle{plain} % include a package for special styles \appendix Whatever... \end{document} Example bibliography file fn.bib: @Article{good1998, author = {Johny B. Good}, title = {Introduction to Gnome Land}, journal = {Journal of Very Important Research}, year = 1998, pages = {128--130}, month = {March} } Emacs will show some entries as optional (e.g. OPTmonth). Once the entry is ready one can choose Clear Entry from the BibTeX menu in Emacs and unfilled optional entries get removed, while those that are filled get OPT stripped off them. Emacs also offers you to enter a key that you will be using in LaTeX document to cite this reference (good1998 above). There are more details in any LaTeX book. There is good documentation on the Web too. Check out: http://www.tug.org/ (TeX Users Group) http://www.loria.fr/services/tex/ (A (La)TeX encyclopaedia) 2. Process the document using the LaTeX command at the shell prompt or using TeX menu in Emacs. Example: latex fn The program will let you know if there are any errors and refer to them by line. Numbers in brackets are page numbers. 3. Use the xdvi command on the file to preview the output. In Emacs menu option TeX->TeX View will run xdvi for you. A window will open that allows you to see the LaTeX output. If xdvi is run in the background, changes in the file may be run through latex again and viewed immediately. Simply click in an xdvi window again. Button Where Effect ----------- ----------- ----------------------- all buttons text window Reader's Digest version of file all buttons left scroll bar move up and down page all buttons top scroll bar move right and left on page Example: xdvi fn Alternative: kdvi fn (this shows the figures in the viewer) 4. Once the document looks the way you would like it, use the dvips command to print the document. In Emacs you can use TeX->TeX Print menu option. Examples: dvips fn (prints to the laser printer) dvips -f fn.ps (creates postscript file) dvips -o fn.ps fn (also creates postscript file) (see below how to use dvips to prepare a file for PDF distilling) Additional options on dvips -r reverses the order of the pages -f read input from a standard input (usefull for piping into dvips) -p n starts printing at page n -l m ends printing at page m -pp 23-25,36,41 print pages 23, 24, 25, 36, 41 -Php113 sends output to Jones 113 hp113 printer Type: man dvips from the shell prompt for more information 5. Producing PDF file is (almost) straightforward. We just need to tell dvips that we are preparing a Postscript file that will be distilled into PDF. Then dvips will enforce the use of Type1 fonts which look better in PDF. On any of the Jones 113 machines run dvips -Ppdf -o fn.ps fn ps2pdf fn.ps which can be shortened to dvipdf fn However, if you used any of the Postscript fonts instead of the default (e.g. you had \usepackage{times} in the preamble of your document) then run: dvips -Ppdf -G0 -o fn.ps fn ps2pdf fn.ps One can choose the PDF version used for the document (default is 1.2) To produce a document that uses PDF 1.3 use: ps2pdf13 fn.ps One can view and print a PDF file using acroread fn.pdf 6. pdfTeX is a new program that produces pdf files instead of dvi. The catch is that the LaTeX mark-up must be LaTeX2e compliant. The old style will not work. The example LaTeX file above IS compliant and can be translated with pdfTeX. The only exception is that a figure must be in PDF format also. One can translate EPS figure to PDF using: epstopdf mypic.eps Then run pdflatex fn This way you do not need to think about the fonts and other issues. However, once again, old style want work and figures must be PDF. 7. How to avoid learning so much LaTeX? Use LyX. It is a graphical front-end for LaTeX and SGML tools. It comes with extensive user documentation and uses LaTeX as a typesetting engine. Try it. Just type on any Jones 113 machine: lyx & You might want to set Zoom in Edit->Preferences to 140% to get better looking fonts on the screen, or switch off scalable fonts altogether. 8. For a LaTeX pre-processor that looks for LaTeX errors: lacheck fn.tex ********************************************************************** Announcement #1807 (was #1806) Date: Fri, 06 Aug 1999 10:49:16 -0400 From: Phil Kearns Subject: Producing Decent .pdf I have been asked several times over the summer about producing PDF that looks OK when viewed with Adobe Acroread. The following assumes that you want to start with LaTeX and end up with a PDF file: 1) Make sure NOT to use the Computer Modern fonts. Computer modern fonts are done as bitmaps in PDF, and Acroread does an awful job of displaying bitmap fonts. PostScript Type-1 fonts are well-supported by our implementation of LaTeX, and they display without problem under Acroread. Here's what I use to start a LaTeX document that I know will ultimately be PDF: \documentclass{article} \usepackage{times,mathptm} %PostScript text and math \usepackage{pifont} \renewcommand{\labelitemi}{\Pisymbol{psy}{183}} %Bullet in PostScript You're also well-advised to avoid fonts not supported in Type-1 PostScript. A prime example are the awful looking calligraphic letters in math mode. 2) LaTeX/BibTeX as usual: latex mydocument 3) Dvips to produce a PostScript file: dvips -o mydocument.ps mydocument 4) Then ps2pdf: ps2pdf mydocument.ps mydocument.pdf If you include encapsulted PostScript (.eps) graphics in your document, I have experienced buggy behavior using the epsfig package. The graphicx package worked fine. Phil **********************************************************************