Introduction to LaTeX -...

Post on 19-Apr-2020

16 views 0 download

transcript

IntroductiontoLaTeX

Slides adapted from Byungwon Woo

WhatisLaTeX?

• LaTeXispronounced“lay-tech”or“lah-tech,”not“la-teks.”

• LaTeXisadocumentpreparationsystemforhigh-qualitytypesetting.

• LaTeXismostoftenusedtoproducetechnicalorscientificdocuments,butitcanbeusedforalmostanyformofpublishing.

WhyUseLaTeX?• Designedbyacademicsandeasilyaccommodatesacademic

use.• Professionallycraftedpredefinedlayoutsmakeadocument

reallylookasif“printed.”• Mathematicalsymbolsandequationsareeasilyintegrated.• Evencomplexstructuressuchasfootnotes,references,table

ofcontents,andbibliographiescanbegeneratedeasily.• Forcesauthortofocusonlogicalinsteadofaestheticstructure

ofadocument.• Createsmorebeautifuldocuments.• Portable,compatible,flexible,versatile,andcheap(orfree)!

ImagesfromDarioTaraborelli’sBlog

InstallingLaTeX• InWindows (CTex,中文的)• MiKTeX

– MiKTeXisatypesettingsystemfortheWindows.– Downloadfromwww.miktex.org forfree– ItisgenerallyrecommendedtoinstallMiKTeXfirst,thenWinEdt.

• WinEdt– WinEdtisatexteditor.– WinEdtcreatesthesourcefile(.texandothers).– Downloadfromwww.winedt.com forfreefor30days.– WinEdtcosts$30.

InstallingLaTeX• Othertexteditors

– Thereareothertexteditors.– Winshellforfree(http://www.winshell.de/)– ScientificWorkplace

• CombinationofLaTeXandMathematicsprogram• Doesagoodjobofcalculatingandgraphing,veryuserfriendly,butexpensive

• InMac• TexShop+ TexMaker

– Downloadforfreehttp://www.uoregon.edu/~koch/texshop/

– Includeseverything!

DIY

BasicDocumentStructure

• Theformatofadocumentisprettysimple.– Inthepreamble

• Documentclass• Packages

– Inthefrontmatter• Title/author

– Inthebody• Contents

– Inthebackmatter• bibliography

InthePreamble

• Youspecifyyourdocumentclass.– Documentclasses:letter,article,report,book,slides(beamer,prosper)

• \documentclass[12pt]{article}• Backslash– atthebeginningoftextmarkupcommand

– Packages:numerouspackagesareavailable• \usepackage[margin=1in]{geometry}• \usepackage{setspace}• \usepackage{harvard}

IntheFrontMatter

• \begin{document}• \title{}• \author{}• \maketitle• \begin{abstract}• \end{abstract}• \pagebreak

IntheBody

• Tobeginanewsection• \section{}

– Similarly,\subsection{},\subsubsection{},\subsubsubsection{}

– LaTeX doesautomaticnumbering.Ifyoudon’tlikeit,usesection*{}

• \emph{},\textbf{}• \singlespacing,\doublespacing,\onehalfspacing• \centeringor\begin{centering}&\end{centering}

Footnotes/Quotes/Equations• \footnote{}• \begin{quote}&\end{quote}• `’,``’’forquatations• MathematicalEquations

– Mathalwaysinbetween$&$• Alternatively,\begin{equation}&\end{equation}

– $1+4=5$– \frac{}{},\sqrt{},\sum_{k=1}^{n}– ^{},_{}– \greekletters(e.g.\alphaor\Alpha)– WinEdtalsoprovidesclickandtypefunctions.

Citations

• \cite{bibtexkey},citeyear{bibtexkey}• Itismoreconvenienttocreateabibliographyfile,calledbibtexfile(.bib)anduseitasneeded.

• WinEdtiscapableofcreatingabibfile,buttherearemoreconvenienttoolsoutthere.

• JabRef(http://jabref.sourceforge.net/)

CreatingaTable• Addnumberedtable

– \begin{table}\caption{}• Creatingatable• Simpletablescanbeproducedby

– \begin{tabular}[pos]{tablespec}– Withinthe{tablespec}section,onedetailsthenumberofcolumns,

thealignment,andthenumberofverticallinesofthetable.• {lrc},{|l|r|c}

– Thentypeinfromlefttoright,thevaluesforeachcellwith&inbetween.

– Put“\\”attheendofeachrow,theninputanotherrowofvaluesifneeded.

– \hline– ForSTATAusers,afterdownloadingthe“outtex”packageonline,one

cansimplytype“outtex”afteranyestimationandSTATAwillspitoutLaTeXcodefortheresultstablepresented.

Creatinga4*3Table• \begin{table}[h]• \caption{SummaryofConclusionsfromDiagnosticTests}• \begin{tabular}{llll}• \hline• \hline• &Macropartisanship &ConsumerSentiment&Presidential

Approval\\• \hline• JointFtest&$d=1$&$d=1$&$d=0$\\• VRtest&$0<d\leq1$&$d=1$&$0<d\leq1$\\• \hline• \end{tabular}• \end{table}

IntheBackMatter

• Don’tforgetbibliography{filename}– Makesurethatthebibtexfileissavedinthesamelocationwherethemaintexfileissaved.

• Don’tforgetend{document}

SeeingtheDocument

Pressonthesmilingbeartoconvertto.dvi

PressonthePDF/LaTeXtoconvertto.pdf

PressonthePDF+happybeartoconvertto.pdfandopenit

CreatingLatexFiles

Your Latex File Your Bibtex File

Latex compile x3

Bibtex compile x2

Latex compile x3

Your Postscript File

dvips compile x1Device independentoutput .dvi

(a text file)

LatexFileStructure

• DocumentClassPredefinedFormats(article,report,book,..).

• PackagesusedAddedFunctionality(graphics,referencestyle,...).

• MainBodyTextandBibliographyReferences.

TheBasics• DocumentClass

\documentclass[options]{class}options=a4paper,11pt,12pt,10pt,twocolumn,landscape,...class=article,report,book,...

• Packages\usepackage{package name}epsfig = insert PS pictures into the documentfancyhdr = easy definition of footer and header

BodyofText• Startwith\begin{document}• Endwith\end{document}• TypesettingText

– \\ or\newline and\newpage– Quotations– Bold\textbf{……………} or \bf – Italics\emph{…………} or\textit{………} or\it– Underline\underline{…………} or \ul

BodyofTextcont…• IncludingMultipleFiles

– \input{filename.tex}

Format• Sections

– \section{…} =1.LatexisGreat– \subsection{…} =1.1WhyLatexisGreat– \subsubsection{…} =1.1.1ReasonOne– \appendix - changesnumberingscheme– \chapter{…} - Tobeusedwithbookandreportdocumentclasses

• Titles,Authorsandothers– \title{…} \author{…}– \footnote{…}

FormatContd.• \maketitle - DisplayTitleandAuthor• \tableofcontents - generatesTOC• \listoftables - generatesLOT• \listoffigures - generatesLOF• Labels

– \label{marker} - Markerindocument.– \pageref{marker} - Displayspageno.ofmarker.– \ref{marker} - Displayssectionlocationofmarker.

• Itemize– Useeitherenumerate,itemize ordescription.– seehandoutforexample.

Lists

• Source– \begin{itemize}– \item Apple– \item Orange– \end{itemize}

• Result– Apple– Orange

Lists

• Enumerate insteadofitemize givesanumberedlist

• Listscanberecursive

Environment

• Somethingbetween– \begin{name}– \end{name}

• Manycommand,forexample\bf affectthetextuntiltheendofenvironment

• Environmentscanberecursive• Examples:

– itemize, center, abstract

Group

• Groupissometextbetween{and}• Manycommandsworkuntiltheendofthegroup

• Code– put{oneword\bfinbold}here

• Result– putonewordinbold here

Alignment

• Environmentscenter, flushleft, flushright

• Example– \begin{flushright}– Right aligned– \end{flushright}

• ResultRight aligned

Fontsize

\tiny \scriptsize\footnotesize

\small \normalsize

\large \Large

\LARGE \huge\Huge

ExampleofLatexdocument

\documentclass{article}

\title{Simple Example}

\author{Andrei Gurtov}

\date{March 2000}

\begin{document}

\maketitle

Hello world!

\end{document}

Tabular• Columns– \begin{tabular}{|…|…|}– \end{tabular}

• Rows– & - Splittextintocolumns– \\ - Endarow– \hline - Drawlineunderrow– e.g.123123 & 34.00\\ \hline

Two Columns

l = automatically adjust size, left justify

r = automatically adjust size, right justify

p = set size e.g p{4.7cm}

c = centre text

Exampleoftable\begin{tabular}{|l|r|c|} \hline

Date & Price & Size \\ \hlineYesterday & 5 & big \\ \hline

Today & 3 & small \\ \hline\end{tabular}

Date Price Size Yesterday 5 Big

Today 3 Small

FloatingObjects• Floatingobjects canstopsplittingoftablesandimagesoverpages.\begin{figure}[options]

\end{figure}\begin{table}[options]

\end{table}

• Theywillnowappearinthe– ListofFigures(LOF) and– ListofTables(LOT). Options (recommendations)

h = place table heret = place at top of pageb = place at bottom of page

Exampleoffloatingfigure

• \begin{figure}[ht]• \centering\epsfig{file=uni.ps,width=5cm}• \caption{UniversityofHelsinki}• \label{uni}• \end{figure}

Figure~\ref{uni} shows...

Images• Useepsfigpackage• \usepackage{epsfig}

• Includingimagesinmainbody• \epsfig{file=filename.eps, width=10cm, height=9cm, angle=90}

• CreatingEPS- Usexvand/orxfig.• MSPowerPoint,saveasGIFandconverttoEPS.

Bibliographybyhand

\begin{thebibliography}{}\bibitem[Come95]{Come95}Comer,D.E.,{\itInternetworkingwithTCP/IP:Principles,ProtocolsandArchitecture},volume1,3rdedition.Prentice-Hall,1995.\end{thebibliography}

BibliographyusingBibtex

• Bibliographyinformationisstoredina*.bibfile,inBibtexformat.

• Includechicagopackage– \usepackage{chicago}

• Setreferencingstyle– \bibliographystyle{chicago}

• Createreferencesectionby– \bibliography{bibfilewithnoextension}

BibliographyusingBibtex

@book{Come95,author=“D.E.Comer”,title={InternetworkingwithTCP/IP:Principles,ProtocolsandArchitecture},

publisher=“Prentice-Hall”,year=1995,volume=1,edition=“Third”}

Bibliographycontd.• Citingreferencesintext

– \cite{cuc98} =(Cuce1998)– \citeN{cru98} =Crud(1998)– \shortcite{tom98} =(Tom,et.al.1998)

• CreatingBibtexFiles– UseEmacswithextensions.– orcopyBibtexentriesfrombibliographydatabase.

SomeMath\begin{center}{\large$$y=\frac{a^3+2c_{x}}{1+\sqrt{b_{x}}}$$\\\vspace{0.2in}$$

Q=\sum_{i=1}^{j}\int_{\mu}^{\infty}f(x_{j})dx$$\\

\vspace{0.2in}$$\Psi=\oint_{-

\infty}^{\infty}f_{xy}({\frac{\partialQx}{\partialQy}})^{\Im_{\pi}^\prime}$$\\ }

ToolsUNIXbasedsystems

– xdvi,ghostview,fixps,emacswithlatex/bibtexsupport.

Windows98/NT– Ghostview,AcrobatDistiller,AcrobatReader,ScientificWorkplace(notthebest),theBibtexviewerisgood.PaintShopPro,LatexandEmacs

Conclusions• Latexisoptimalformasterandphdthesis?• Mathematicalformulaeareeasy.• Usebibtexsearchengines• ConsiderconvertingPostscriptfilestoPDF(morewidespreadinWindowsworld)andtoconservespace.

CommonMistakes

• Oftentimes,youmakeamistakewhencreatingadocument.Youwillnoticethelogfilereportingaproblem.

• Therearesomecommonmistakes:– “end”doesn’tfollow“begin”– $doesn’tfollow$– Usingcommandsfrompackageslotdefinedinthepreamble

– Don’tforget“\”s.

OtherResources

• Books– LeslieLampert.1994.LaTeX:ADocumentPreparationSystem.

– HelmutKoptaandPatrickW.Daly.2004.GuidetoLaTex

– FrankMittelbachetal.2004.TheLaTeXCompanion• OnlineGuides

– http://en.wikibooks.org/wiki/LaTeX– http://tobi.oetiker.ch/lshort/lshort.pdf– CVanddissertationtemplatesareavailableonline