LaTeX Tutorial Fiona Shearer May 11th, 2004 Disclaimer added Disclaimer: This is in no way a complete tutorial of LaTeX and WinEdt. It is only intended as an initial introduction. There are certainly many important concepts that are outside the scope of this presentation and are left for the audience to discover. No technical support is offered in conjunction with this presentation, although several key references are listed.
Presentation Overview What is LaTeX? Comparison: MS Word vs LaTeX Tutorial of LaTeX Commands Class files and Macro Packages Special Characters and LaTeX Commands Lots of Examples Software Downloads & Demo References Introduce Topics that will be covered in the presentation What is LaTeX, How does it compare to MS Word? Introduce some basic concepts that will allow you to start creating documents Provide a list of the software downloads that are required and a demo List of references May 11th, 2004 LaTeX Tutorial
What is LaTeX? Pronounced: “Lay-tech” S/W package that uses the TeX typesetting engine TeX: computer program released in 1982 by Donald E. Knuth and written for typesetting digital documents [1] For more info see [2] History Explain typesetting… text into type (fit it to the page) May 11th, 2004 LaTeX Tutorial
MS Word vs LaTeX What You See Is Get More Info in [3] May 11th, 2004 Microsoft Word documents are referred to as WYSIWYG documents, because … (Click) When you look at it on screen, you are seeing exactly what the final document will look like. Some problems, getting the figure numbers to align, references, cross references, margins A TeX document separates the content from the commands that will determine what the format of the document will look like Preparing a LaTeX document requires an extra step to format or typeset the document (.tex to .pdf) Advantages: consistent look, correct numbering, ease of organization More Info in [3] May 11th, 2004 LaTeX Tutorial
Example: Hello World Text & Commands Typeset Document hello_world.pdf LaTeX TeX Brief reference to class file amsart (telling which font to use, etc) Commands to start and end the document (tags like html) Winedt text editor (colours) Magic of Latex Pdf Note how the text is separated by lots of spaces, but in the typeset version it is not. -setup to produce pdf, but really dvi and postscript files produced as well. May 11th, 2004 LaTeX Tutorial
Overview of LaTeX Class Files Macro Packages Special Characters Commands Section Headings, Citations, Cross-References Figures, Tables, Equations Miscellaneous commands Many examples throughout In order to produce more complex document formats, you need to know how to structure a LaTeX document I will talk a bit about class files, macro packages, … I will also be showing several examples throughout the presentation This will be followed by a demonstration May 11th, 2004 LaTeX Tutorial
Class File Defines what your document will look like Selected by \documentclass command \documentclass[options]{class_name} Some examples: amsart.cls (included with basic download) \documentclass[]{amsart} IEEEtran.cls (download from [4]) Specify font size, number of columns, format, etc \documentclass[10pt,conference]{IEEEtran} Remember in the hello world example, the first line in the .tex file contained the documentclass command What this command does is select the file that will apply general formatting style to your document. The names in blue you can change depending on what class file you are using and what options are available Options are available to select any number of things, like font size, number of columns, etc. Multiple options can be selected by inserting a comma in between Amsart good for simple reports (see handouts). Included with basic download IEEEtran is the class file provided by the IEEE for journals and conferences… Download from the IEEE includes examples (Read file for options) Also documentstyle command (report, book, article, letter) May 11th, 2004 LaTeX Tutorial
Class Files - Examples May 11th, 2004 LaTeX Tutorial Amsart on the left. Paragraphs begin immediately after section headings, one column, 12pt IEEEtran on the right, two column, 10pt font, section headings capitalized and on their own line Note in both cases, LaTeX justifies the lines (adjusts the spaces between words to get the right margins to line up straight) May 11th, 2004 LaTeX Tutorial
Macro Packages Allow you to use special commands Packages are activated by: \usepackage[options]{package_name} Examples: cite.sty \usepackage{cite} graphicx.sty \usepackage{graphicx} geometry.sty \usepackage[margin=1in]{geometry} url.sty \usepackage{url} Once you’ve selected your class file, you can add packages to your document to make more latex commands available Packages are activated by the command shown here (names in blue you can change depending on the package) These are just a few examples Cite – bibliographic referencing, allowing LaTeX to generate reference numbers automatically in the correct order (more on this later) Graphicx – Allows you to easily include figures within your document (more on this later) Geometry – Allows you specify things like margin width Url – Helps to properly typeset html addresses May 11th, 2004 LaTeX Tutorial
Special Characters The following symbols are reserved: # $ % & _ { } ^ ~ \ To include them in your text: \# \$ \% \& \_ \{ \} \^{} \~{} Note: you cannot just do \\ (which is a linebreak) , but instead: $\backslash$ Since certain characters are required within LateX to indicate commands, they are therefore reserved and can’t be used standalone within your document text, so to use them you’ll need to add a backslash in front of them. The exception to this rule is the backslash itself. Two backslashs indicate a forced line break. So if you really need a backslash use this command. # commands $ math environment % comment & columns and tables _ subscript in the math environment { } commands ^ superscript in the math environment ~ indicates a space that cannot be enlarged and prohibits a line break \ commands Special Characters: \’e May 11th, 2004 LaTeX Tutorial
A few more notes… Consecutive whitespace characters (blank or tab) are treated as one space. Paragraphs must be separated by at least one line in the .tex file. Comments can be added using the % character. Any text on a line after % will be ignored by the TeX compiler. “To get a straight right margin in the output, LATEX inserts varying amounts of space between the words. It inserts slightly more space at the end of a sentence, as this makes the text more readable.” [1] Note about %, the next line will still appear. There is a comment environment command that you can use for block comments May 11th, 2004 LaTeX Tutorial
A Quick Review LaTeX May 11th, 2004 LaTeX Tutorial TeX: Class file with options Packages (although not used) Begin document command Text: Note multiple whitespaces should be ignored Text: Exclamation marks are on the next line down, but not separated If at least one line separates text, a new paragraph should be formed. Comments indicated by % (GUI turns them gray) backslash indicates a special command (Latex- ready made string) Command to generate Backslash End document command Pdf note first line ignored the extra spaces and the one carriage return comments ignored special typesetting of LaTeX multiple lines ignored backslash May 11th, 2004 LaTeX Tutorial
Commands Used to help organize the document Section headings Labels and Cross-References Figures Tables Equations Listing Options Miscellaneous: newpage, pagestyle, include… Bibliographic Referencing For writing longer, more complex you need a way to help organize the documents. This is where the LaTeX commands are used to help define sections, cross-references, figures, tables,… May 11th, 2004 LaTeX Tutorial
Section Headings Use commands to define sections: \section{Section Name} \subsection{Sub-section Name} \subsubsection{Sub-sub-section Name} \tableofcontents \appendix OR using the appendix.sty package: \begin{appendices} … \end{appendices} Note: commands are case sensitive First, section headings Place the title of the section between the curly brackets. LaTeX will define the font size, capatilization, placement of the headings No end of section commands required, just insert where necessary (CASE SENSITIVE) You just have to write table of contents command, LaTeX does the rest (make crack about troubles with Word TOC) Several ways to configure appendices and we’ll see an example later… May 11th, 2004 LaTeX Tutorial
Labels and Cross-Referencing Tired of re-numbering your section or figure numbers in MS Word by hand? Solution: Each section, figure, table, equation, and so on can have its own label: \label{label_name} You can recall that label in the text: \ref{label_name} LaTeX assigns the correct section, figure, table and equation numbers to the labels when you compile the document. This IMHO is one of the best features of LaTeX. Rather than hand numbering your figures, tables, equations, sections, or trying to let MS Word handle it, you give them a label. When you run the TeX compiler the correct numbers are assigned in order. Cross references are easy because you just use the \ref command to indicate a specific label. (NEXT SLIDE EXAMPLE) If you happen to label two figures the same name, the TeX LOG file will let you know which label. In fact, any errors that occur are indicated in the LOG file along with the line of the TEX document where the error occurred. (see this in the demo time permitting) May 11th, 2004 LaTeX Tutorial
Label Example May 11th, 2004 LaTeX Tutorial TeX: Table of contents is added Three sections (two plus one in the appendix) Sections do not require labels (unless you want to reference them) Two cross references, one to the intro and one to the appendix PDF TOC automatically generated with page numbers Section numbers are assigned References are updated. If you compile the document, go back and re-order things you’ll just have to run the compiler again to renumber everything Sometimes you may need to run it twice, if you make a lot of changes. May 11th, 2004 LaTeX Tutorial
Figures Require graphicx.sty package Figure type: eps (encapsulated postscript) Sample code: \begin{figure}[options] \includegraphics[options]{figure_name.eps} \caption{Figure Caption would go here} \label{fig_label} \end{figure} There are probably a few ways to insert figures, but the one that I am familiar with requires the graphicx packages and requires figures that are in .eps format. I think you can also use jpeg, but you’ll have to check that out yourselves. Many programs are available to convert file formats into eps. Ex Ghostview (ps-eps) Insert this bit of Sample code into your tex document to insert a figure (the text in blue can be changed by the user) Figure Options – where the figure will be placed in the typeset document Graphics options - width, height, angle and scale May 11th, 2004 LaTeX Tutorial
Example TeX Graphicx Package required section and sub-section Cross reference to a figure (underscore) code to insert the figure (Begin and End commands) figure options: htbp (here, top, bottom, page) graphics options: height file name (File must exist in directory with the TeX file) Centerline centers the figure Caption label Warning: ind.eps must exist in the same file directory as the TeX file, unless \graphicspath{} command is used. May 11th, 2004 LaTeX Tutorial
Tables A little awkward to use, but they work: Sample Code: \begin{table}[options] \renewcommand{\arraystretch}{spacing_num} \caption{Table Caption would go here} \label{tab_label} \centering \begin{tabular}{column_scheme} row_info \end{tabular} \end{table} Options htbp Spacing_num single =1, double =2 Caption Label \centering More complicated Column_scheme – indicates number of columns, justification, and presence of vertical lines row_info – row text plus column indicators May 11th, 2004 LaTeX Tutorial
Tables- continued column_scheme row_info ‘c’, ‘l’, or ‘r’ represent centered, left-justified or right-justified columns ‘|’(vertical bar) represents a vertical column line Example: ‘|c|c|c|’ represents three centered columns row_info Text in the rows is entered with the‘&’character used to separate the columns ‘\\’ indicates a line break ‘\hline’ adds a horizontal line Example: ‘\hline A & B & C \\ \hline’ represents a row with three entries and lines above & below First we’re going to look at what to put in the column_scheme part of our table definition C,L,R | Example: change the first column to left justified, change first C to an L Next, what to put in the row info part Text separated by the ampersand Use \\ to indicate the end of a line If you want to add a horizontal line \hline Example May 11th, 2004 LaTeX Tutorial
Example Table line spacing Column Scheme: one left-justified and three centered columns. Note the double ‘||’ TeX cross reference to table options: htbp arraystretch 1.5 caption label column scheme row info PDF Cross-reference Note the full justification and hyphenation that LaTeX does double vertical bars formation of rows quotations Lead into equations… Notice use of ‘&’, ‘\\’ and ‘\hline’ to form the rows May 11th, 2004 LaTeX Tutorial
Equations Two ways to form equations Using ‘$’: $ equation syntax $ Using commands: \begin{equation} \label{equation_label} Insert equation syntax here \end{equation} Syntax can be generated with software packages like MathType orTeXaide TeXAide has a similar format like MS Equation Editor, so if you’re familiar with that software it’s not that hard From TeXAide you can cut and paste your equation into your TeX document within the dollar signs or the equation enviroment May 11th, 2004 LaTeX Tutorial
Example Makes Eq’n numbers appear on the right side of the page Reqno – right side equation numbers (default with this class file is left side) [1] is a really good reference for equation syntax. Not that hard to learn. Underscore, \name Syntax… refer to [1] May 11th, 2004 LaTeX Tutorial
Listing Options Lists: itemized, enumerated, descriptive Options for listing, lists can also be nested May 11th, 2004 LaTeX Tutorial
Miscellaneous Commands Newpage: \newpage Header/Footer: \pagestyle{style} style: plain, headings, OR empty Nested TeX files: \include{filename} \input{filename} Quotation Marks: Use `` and ’ ’, rather than “ and ” Header footer: placement of pagenumbers and headers Nested files (handy for long documents) include will create a new page with contents of nested tex file input will seamless add nested file Quotation marks: the one near the tilde key and the one near to the semicolon on most keyboards May 11th, 2004 LaTeX Tutorial
Bibliographic Referencing BIBTeX: manages bibliographic databases Database files have .bib extension Example of bibliographic entry: @book{RFICtext, author = "J. Rogers and C. Plett", title = "Radio Frequency Integrated Circuit Design", publisher = "Artech House, Inc", address = "Boston, MA", year = "2003" }; Style files (.bst) are used to format the entries IEEEtran.bst [5] This part of TeX handles bibliographic referencing. Database files keep track of any reference that you might use in your document Only the ones you actually use will be included in your reference list Database files have a .bib extension and contain lists of reference entries like this one Example (make note of marker) Different formats (book, journal, conference, online) exist as well Examples are given by the IEEE in [5] for .bib files Style files are used to format the references properly Example download from the IEEE Summary: .bib file contains list of entries, each entry has a marker to distinguish it from the other entries .bib in same directory as tex file May 11th, 2004 LaTeX Tutorial
Referencing - continued Entries can be referenced from the TeX file: \cite{RFICtext} The cite package will have to be included Example: When you want to reference something from within your TeX document you use the cite package and the cite command Cite command uses the marker name (in this case RFICtext) to identify which reference to use Example So as you’re researching you can keep your .bib file up to date and when you’re ready to start writing your document citing your references becomes very easy. Numbers are automatically assigned in the correct order IEEEtran.bst bibliography style file RFIC.bib must have an entry labeled RFICtext May 11th, 2004 LaTeX Tutorial
What you need to get started: Adobe Acrobat Reader http://www.adobe.com/products/acrobat/ MIKTEX: TeX for Windows www.miktex.org WinEdt: my GUI, but many others exist www.winedt.com (30-day trial download) TeXAide: for equation editing: http://www.dessci.com/en/products/texaide/ (Free download) Basic Essentials to get started… Graphics – CorelDraw to create eps files or something like Ghostview to convert from ps into eps May 11th, 2004 LaTeX Tutorial
WinEdt Compile Procedure GUI for editing and compiling LaTeX files Compile Procedure: Open .tex file and .bib file (if needed) Edit as required Click on “TeXify” button to compile Watch log file window to check for errors Click on dvi pdf button Click on the Adobe symbol Adobe should open with your new pdf file May 11th, 2004 LaTeX Tutorial
Demo May 11th, 2004 LaTeX Tutorial
References The best reference by far is Google Groups: References: Go to www.google.com and click on the Groups tab Type in some key words related to your question (include TeX) Click on the Google Search button and you should get some good hits References: [1] http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf?action=/starter/ [2] http://en.wikipedia.org/wiki/TeX [3] http://www.cs.cornell.edu/Info/Misc/LaTeX-Tutorial/Introduction.html [4] http://www.ieee.org/portal/cms_docs/pubs/transactions/IEEEtran.zip [5] http://www.ieee.org/portal/cms_docs/pubs/transactions/IEEEtranBST.zip May 11th, 2004 LaTeX Tutorial
Any Further Questions? Conference and JournalTemplates for the IEEEtran class file can be downloaded from [4]. LaTeX templates for the amsart class file are available upon request. May 11th, 2004 LaTeX Tutorial