Top Banner
LaTeX Short Course Blake Larson, instructor [email protected]
33

LaTeX Short Course Blake Larson, instructor [email protected].

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

LaTeX Short Course

Blake Larson, instructor

[email protected]

Page 2: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Acknowledgements

• Short course information by Rich Kaszeta on MENET website (heavily pilfered)

• Various other web sources (there are many!)

Page 3: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Schedule

• Day 1:– Basic LaTeX Introduction– Editors on MENET Machines– Running LaTeX, Previewing, and Printing– Basic LaTeX Classes and Environments– Math

Page 4: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Schedule, cont.

• Day 2– Macros– Large Documents– Figures and Tables– Bibliographies– The thesis-me class– Add-ins, helpers, and other setups

Page 5: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

LaTeX Advantages• LATEX provides an easy-to-use method for producing high-quality typeset

math.• LATEX provides very high quality typeset output which pays attention to fine

typographical details such as math typesetting, ligatures (i.e. ` ’ instead of `fi'), advanced font handling (with both slanted and italics text, which are slightly different), and hyphenation that are often handled poorly in WYSIWYG programs.

• The LATEX markup language lends itself to writing well-structured documents that are easy to modify.

• The user only needs to learn a few easy commands, and generally does not need to tinker with the actual layout of the document.

• Even complicated structures such as footnotes, cross-references, indices, tables of contents, and bibliographies are easily generated.

• The basic functionality of LATEX can be enhanced by using free add-on packages that provide features such as graphics, endnotes, etc.

• LATEX is freely available for almost every computer platform in existence.

Page 6: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

LaTeX Disadvantages

• LATEX is not WYSIWYG – you have to run latex on your file before you can see your changes.

• If you are trying to produce a document for which there is no pre-defined layout, it requires a fair bit of knowledge to design a new layout.

• You cannot easily exchange LATEX files with colleagues that are unfamiliar with it.

Page 7: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Getting Started

• Make a new directory– cd ~– mkdir latexcourse

• Open your favorite web browser to– http://www.menet.umn.edu/~blake/latexcourse/

• Download all those files into your latexcourse directory

Page 8: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Official Process

• Create a simple text file with a .tex extension

• Run latex on the command line to get a .dvi file

• Print or preview the .dvi file

Page 9: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

The approach for this course

• Create the text file as before, with a .tex extension

• Run pdflatex on the .tex file to create a standard .pdf file

• View the .pdf file using acroread

• This approach produces documents that we are more comfortable working with

Page 10: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Text Editors

• Choose your favorite editor to make your .tex file:– pico– emacs– vi– nedit– Notepad/Wordpad (Windows)– others…

Page 11: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Our First Document

• Open the sample file example1.tex in your favorite editor

• Note the basic parts:– \documentclass declaration– \begin{document}– \author, \title, and \maketitle– Document contents– \end{document}

• Run pdflatex example1• Run acroread example1.pdf

Page 12: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Basic Text Formatting

• Lines and Paragraphs– You can force new lines with \\– You can force new pages with \newpage

• Hyphenation– You can enforce a hyphenation pattern with \hyphenation{}

– You can keep hyphenation from occurring with \mbox{}

• Quotes and Dashes– Quotes are entered with `, ‘, ``, ’’ (not “)– Dashes are entered with -, --, and ---

Page 13: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Other Characters

• Accents (dots, tildes, etc.)

• Symbols (daggers, copyright, etc.)

(see Basic LaTex Skills handout for details)

Page 14: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Sectioning Commands

– \part{}– \chapter{}– \section{}– \subsection{}– \subsubsection{}– \paragraph{}– \subparagraph{}

• Each of the above has an unnumbered “starred” form (i.e. \section*{})

Page 15: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Labels and References

• At almost any point in the document you can place a “label” using \label{key}, where the argument is a “key”, a short one word description of the location.

• You can refer to this label by section and page number using \ref{key} and \pageref{key}, respectively.

• Advanced: you can use \autoref{key} to automatically place the proper label (i.e. Section 2.1 or Table 1.1 instead of just 2.1 or 1.1). Must include the hyperref package.

Page 16: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Sizes

\tiny \scriptsize \footnotesize \small \

normalsize \large \Large \

LARGE \huge \Huge• Note these are declarations, so the proper

syntax is {\Large Text}

Page 17: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Environments

• For special purpose text such as lists, quotations, poetry verse, and aligned text, LATEX provides environments.

• To use an environment, you use \begin{} and \end{}:

\begin{environment}\end{environment}

• where environment is the name of the particular environment.

Page 18: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Lists

• Two of the simplest environments are list environments. The first is the itemize environment. Each item starts with \item:

\begin{itemize}\item First item.\item Another item.\item Yet another item.\end{itemize}

• The enumerate environment does the same thing, but numbers the entries.

Page 19: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Alignment Environments

• The next simplest environments are the alignment environments center, flushleft, and flushright, which align the text accordingly. For example, the center environment centers the text:

\begin{center}

Centered Text

\end{center}

Centered Text

Page 20: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Math

• LATEX provides two basic methods of typesetting math, “inline” which occursinside of a sentence: a = b + c , and “displayed”, which occurs centered between paragraphs:

a = b +c• To typeset material in inline mode,

surround it with dollar signs: $...$. Thus,• $A=bh$ yields A = bh.

Page 21: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Displayed Equations

• To type displayed math, use \[ and \] instead. So \[A=bh\] yields

A = bh• If instead you use the equation environment

instead of \[ and \], you get the same results, but with an equation number:

A = bh (1)• Note that if you put a \label in here, you can

refer to that equation number elsewhere in the text.

Page 22: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Differences from Text Mode

• Spaces in math mode are ignored.

• No empty lines are allowed.

• Letters are italicizes

• All letters are typed as single variables, not words. So $effective$ (e f f ective) typsets much differently from “effective”

Blake Larson
Page 23: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Basic Math Building Blocks

• Sub/superscripts are produced with _ and ^. For example, $p_2$ gives p2 and

• $x^y$ gives xy. Note these only work on a single character - to sub – or superscript an expression surround it with curly braces.

• Fractions are produced using \frac, which takes two arguments, one for the

• numerator and one for the denominator. $\frac{5}{8}$ yields a ⅝ .

Page 24: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

More Basic Math

• Radicals are produced using \sqrt, with $\sqrt{x}$ yielding the square root of x and $\sqrt[3]{2}$ yielding the cube root of 2

• Lowercase Greek Letters are given by simply spelling out the letter as a macro, $\delta$ yielding δ, etc.

• Uppercase Greek letters are the same, except the macro name is capitalized,

• $\Omega$ yielding Ω, etc.

Page 25: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Math Exercises

• How would you typeset:

Page 26: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Answers to Exercises

1. $y=\sqrt[z]{x^2+w_2^2}$

2. $\sigma=\frac{\Omega^{x}+y_2}{\sqrt{x}}$

3. $\sqrt[n+1]{a}$

4. $\tau_{xy}''$

Page 27: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Spacing

• Sometimes you may wish to “tweak” the spacing in math mode. The followingmacros are provided for this purpose:

\, thin space

\: medium space

\! negative thin space

\; thick space

Page 28: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Integrals and Summations

• To do integrals and summations, simply put in a \int. For example, \[\int x\,dx\](note the spacing factor)

• To add limits, simply sub and superscript the integral, \[\int_0^\infty x\,dx\],

• To do summations, simply do the same thing with \sum.

Page 29: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Parentheses, Braces, etc.

• To use parentheses and braces, simple type the character for them. For curly braces, you have to type \{ and \} since { and } are reserved for defining groups.

• However, if you want to type large expressions containing symbols such as integrals and fractions, it is nice to have larger versions of these delimiters. If you preface the delimiters with \left and \right, you get larger symbols that are (usually) the right size.

• Example: \[\left(\frac{\int_0^l x\,dx}{\Delta x}\right)\] gives

• a

Page 30: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

More Math Exercises

• Typeset the following:

Page 31: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Answers to More Examples

1. $1+\left(\frac{1}{1-x^2}\right)^3$

2. $\pi(n)=\sum_{k=2}^{n}\left[\frac{\phi(k)}{k-1}\right]$

3. $\Delta x=x_{\mathrm{max}}-x_{\mathrm{min}}$

4. $A=\int_0^\pi r^2\,dr$

Page 32: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Common Mistakes

• Sometimes LATEX will give you errors when you try to run it because of problems with your input le. As mentioned earlier, sometimes the location of the error that LATEX reports may not be correct, so it is useful to know what usually causes these problems. Usual sources of error include:– Misspelled command or environment names– Missing or improperly nested \end statements.– Improperly matched { and }. They should always come in pairs.– Missing command arguments.– A missing $.– Using one of the special LATEX characters such as #.

Page 33: LaTeX Short Course Blake Larson, instructor blake@me.umn.edu.

Thursday’s Schedule

• Day 2– Macros– Large Documents– Figures and Tables– Bibliographies– The thesis-me class– Add-ins, helpers, and other setups