TEX - math.la.asu.edu

14
my MAT420 Lecturenotes 7 L A T E X It is important for a scientist to present results clearly and convincingly. L A T E X is a document preparation system which helps with this process. It is widely used in the scientific commu- nity and delivers professional-looking documents (especially when typesetting mathematical symbols and equations). It allows complete control over the publishing process (and was used to produce these notes). 7.1 Overview A complete L A T E X implementation includes: •AL A T E X editor: commands and text are written in the file saved with extension *.tex. A popular (and free) editor is LyX, available on the Linux, Mac, and Windows plat- forms. Kile (free, Unix-like platforms) also has many interesting features. See also the comparison of current editors on Wikipedia. • A specific L A T E X implementation: includes all macros and environments used in the *.tex file, as well as the compiler for processing the *.tex file. Two widely used implementations are T E X Live (Linux, Mac OS X) and MiKTeX (Windows). An implementation also includes many packages to do special tasks (such as pstricks to do pictures). The number of included packages depends on the level of implementation (basic, full, custom,...) • A converter to PostScript *.ps or PDF *.pdf format, using GhostScript (to create fonts), dvips (similar to Acrobat™Distiller™), ps2pdf (to get a *.pdf file). • Viewers for *.dvi, *.ps, *.pdf files, such as InstantPreview (LyX), ViewDVI (Kile), ViewPS, GSView, Okular, Okular (Linux), Acrobat Reader™, ... There are two ways to process a *.tex file and transform it into a *.pdf file: 1. using L A T E X to produce a device independent file (*.dvi), which is then converted to PDF format using dvipdf or, explicitly, in two steps dvips and ps2pdf. Either way the file may contain encapsulated PostScript pictures *.eps. 7.1

Transcript of TEX - math.la.asu.edu

my MAT420 Lecturenotes 7LATEX

It is important for a scientist to present results clearly and convincingly. LATEX is a documentpreparation system which helps with this process. It is widely used in the scientific commu-nity and delivers professional-looking documents (especially when typesetting mathematicalsymbols and equations). It allows complete control over the publishing process (and wasused to produce these notes).

7.1 OverviewA complete LATEX implementation includes:

• A LATEX editor: commands and text are written in the file saved with extension *.tex.A popular (and free) editor is LyX, available on the Linux, Mac, and Windows plat-forms. Kile (free, Unix-like platforms) also has many interesting features. See also thecomparison of current editors on Wikipedia.

• A specific LATEX implementation: includes all macros and environments used in the*.tex file, as well as the compiler for processing the *.tex file. Two widely usedimplementations are TEX Live (Linux, Mac OS X) and MiKTeX (Windows). Animplementation also includes many packages to do special tasks (such as pstricks todo pictures). The number of included packages depends on the level of implementation(basic, full, custom,...)

• A converter to PostScript *.ps or PDF *.pdf format, using GhostScript (to createfonts), dvips (similar to Acrobat™Distiller™), ps2pdf (to get a *.pdf file).

• Viewers for *.dvi, *.ps, *.pdf files, such as InstantPreview (LyX), ViewDVI (Kile),ViewPS, GSView, Okular, Okular (Linux), Acrobat Reader™, . . .

There are two ways to process a *.tex file and transform it into a *.pdf file:

1. using LATEX to produce a device independent file (*.dvi), which is then converted toPDF format using dvipdf or, explicitly, in two steps dvips and ps2pdf. Either waythe file may contain encapsulated PostScript pictures *.eps.

7.1

page 7.2 §7.2. A SAMPLE FILE

2. using pdflatex to produce a PDF file directly. pdflatex cannot handle PostScriptfiles, and pictures must be in PDF, *.jpg, or *.png formats.See also how to import graphics in LATEX in the wikibook on LATEX).

% *.texLyXKile

LATEX *.dviInstantPreview

ViewDVI

dvips *.psGhostScript

GSview

ps2pdf *.pdfOkularAcrobat

%

pdflatex

dvipdf

Figure 7.1: A customized Kile window featuring QuickBuild, ViewPDF, and LaTeX buttons

7.2 A sample fileHere is a sample LATEX script, script.tex, illustrating the standard LATEX syntax and severalcommon environments encountered in mathematical typewriting:

script.tex

©BDW Draft September 16, 2019

§7.2. A SAMPLE FILE page 7.3

1 \documentclass[12pt]{article}2 \usepackage{amsmath,amssymb,hyperref,graphicx}3 \textheight 7.5in4 \textwidth 6.5in5 \evensidemargin 0pt6 \oddsidemargin 0pt7 \author{Moi}8 \title{My first \LaTeX\ file}

9 \begin{document}10 \maketitle11 This is my first \LaTeX\ file.12 \section{A quadratic equation}13 \label{section1}14 The quadratic equation15 \[ x^2 - 4x+3 = 0 \]16 has roots $x=1,3$. To show this write17 \begin{align*} % this environment is defined in the package amsmath18 & x^2-4x+3 = 0 \\19 & \Leftrightarrow (x-2)^2-4+3=0 \\20 & \Leftrightarrow (x-2)^2=1 \\21 & \Leftrightarrow x-2=\pm 1 \\22 & \Leftrightarrow x=3,1 \quad \checkmark23 \end{align*}

24 \section{Another quadratic equation}25 \label{section2}

26 Consider the equation27 \begin{equation}\label{equation1}28 x^2-4x+4=0.29 \end{equation}30 Equation (\ref{equation1}) has one double root. The situation is different from Section \ref{section1}.

31 \section{An equation with matrices}32 If $c^2+s^2=1$ it is easy to verify the identity33 \[ \begin{bmatrix} c & -s \\ s & c \end{bmatrix}\begin{bmatrix} c & s \\ -s & c \end{bmatrix}34 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}. \]

35 \subsection{A table}

36 \begin{tabular}{|c|c|c|}\hline37 \textbf{Equation} & $x^2-4x+3=0$ & $x^2-4x+4=0$ \\ \hline38 \textbf{Roots} & $x=1,3$ & $x=2,2$ \\ \hline39 \end{tabular}

40 \subsection{A figure}

41 \begin{figure}[h]42 \centering43 \includegraphics[width=.25\textwidth]{dog.eps} % in package graphicx44 \caption{A dog.}45 \end{figure}

46 \section*{Resources}

47 \begin{itemize}48 \item \href{http://en.wikipedia.org/wiki/LaTeX}{\LaTeX\ (Wikipedia)} % in package hyperref49 \item \href{http://www.latex-project.org/}{The {\LaTeX\ project site}50 \item See also the reference \cite{BDW12}51 \end{itemize}

52 \bibliographystyle{plain}53 \bibliography{local}

54 \end{document}

©BDW Draft September 16, 2019

page 7.4 §7.2. A SAMPLE FILE

• The preamble (before \begin{document}) defines the type of document (article), loadsseveral packages used in this document, and sets the dimensions of the page. It alsodefines the title and author of the article.

• The environment \begin{document} . . . \end{document} is required and contains thearticle itself. This article features 4 sections (including the unnumbered Resourcessection) and 2 subsections.

• script.tex contains an encapsulated PostScript picture dog.eps on line 43.

• Line 53 invokes the bibliography file local.bib, which defines all citations appearingin script.tex. The only citation in script.tex is BDW12 on line 50:

local.bib

@Article{BDW12,author = {B.~Welfert and myself and moi},title = {{MAT420 Introduction to \LaTeX}},journal = {My Journal},year = {2012},volume = {1},pages = {16.1--16.10}}

• To process script.tex and local.bib from the Unix line command type$ latex script.tex (creates .aux, .dvi, .log, and .out files)$ bibtex script.aux (creates .bbl and .blg files for citations using BibTeX)$ latex script.tex (second pass to resolve citations)$ latex script.tex (third pass to resolve all dependencies)$ dvips script.dvi (creates PostScript file)$ ps2pdf script.ps (creates PDF file script.pdf)These steps can be individually performed in LATEX editors such as Kile or WinEdt, orassembled into a single “macro” (e.g. in Kile). Alternately, last two stepscan be combined into$ dvipdf script.dvi (creates PDF file script.pdf)

• The document script.tex can be processed directly with pdfLATEX provided dog.epsis converted to *.pdf. The line command$ epspdf dog.epscreates a picture dog.pdf. Conversion between formats can also be done using GIMP(Linux) or MS Paint™ (Windows). After replacing dog.eps by dog.pdf on line 43 thefile script.tex can then be processed directly with$ pdflatex script.texwhich directly produces a PDF file.

©BDW Draft September 16, 2019

§7.2. A SAMPLE FILE page 7.5

MyfirstLATEXfile

Moi

Octob

er16,2012

ThisismyfirstLATEX

file.

1A

quadraticequation

Thequad

raticequation

x2−

4x+3=

0

has

rootsx=

1,3.

Toshow

thiswrite

x2−

4x+3=

0

⇔(x

−2)

2−4+3=

0

⇔(x

−2)

2=

1

⇔x−2=

±1

⇔x=

3,1

X

2Anoth

erquadraticequation

Con

sider

theequation

x2−4x

+4=

0.(1)

Equation(1)has

onedou

ble

root.Thesituationisdifferentfrom

Section

1.

1

3Anequationwithmatrices

Ifc2+s2=

1itiseasy

toverify

theidentity

[

c−s

sc

][

cs

−s

c

]

=

[

10

01]

.

3.1

Atable

Equation

x2−

4x+3=

0x2−

4x+4=

0Roots

x=

1,3

x=

2,2

3.2

Afigure

Figure

1:A

dog.

Reso

urces

•LATEX

(Wikipedia)

•TheLATEX

project

site

•See

also

thereference

[1]

References

[1]B.Welfert,myself,an

dmoi.MAT420Introductionto

LATEX.MyJournal,1:16.1–16.10,

2012.

2

Fig

ure

7.2:

PDF

file

obta

ined

from

the

LA TEX

scri

pton

page

7.2

©BDW Draft September 16, 2019

page 7.6 §7.3. BEAMER PRESENTATION

7.3 Beamer presentationBeamer allows you to create PowerPoint-like presentations using your existing LATEX notes.It enables overlays and dynamic effects, with automatic TOC creation. The layout, colorand font schemes can selected from available themes or customized. By default Beamer usespdfLATEX, i.e., the output is directly a PDF file. Here is a sample presentation:

MAT421syllabus.tex

1 \documentclass[11pt,compress]{beamer} %[handout] for distributing slides (no overlays)

2 \usetheme{Frankfurt}3 \usecolortheme{crane}4 \usefonttheme{structurebold}5 \setbeamerfont{frametitle}{size=\normalsize} % font size for slide titles6 \setbeamertemplate{background canvas}[vertical shading][bottom=gray!10,top=orange!30!yellow!40] % bg color

7 \useoutertheme{SoMaSS} % gray footline with ASU logo

8 \usepackage[english]{babel} % needed by Beamer9 \usepackage{times} % desired font family10 \usepackage{alltt} % verbatim-like environment11 \usepackage{pstricks} % for using the \pspicture environment12 \usepackage{multimedia} % for the \sound and \movie commands

13 \title[MAT421 in a nutshell]{MAT421 in a nutshell}14 \author[B. Welfert]{Bruno D. Welfert}15 \date[10/18/12]{10/18/12}16 \institute[Mathematics and Statistics]{\includegraphics[height=.85cm]{ASUlogo.pdf}% logo17 {\color{purple} \textbf{School of Mathematical \& Statistical Sciences}}}

18 \begin{document}

19 \begin{frame}[plain] % title frame20 \titlepage21 \end{frame}

22 \begin{frame}[plain] % outline frame (optional), determined by \section and \subsection commands23 \frametitle{Outline}24 \tableofcontents[pausesections]25 \end{frame}

insert frames here, see below

94 \end{document}

• The options 11pt on line 1 sets the normal font size to 11 points (1 inch = 72 pts). Theoption compress reduces the size of navigation bars. The option handout for removingoverlays is also useful to print complete slides only.

• Lines 2-4 set the themes of the presentation. Available themes are

\usetheme{...} AnnArbor, Antibes, Bergen, Berkeley, Berlin, Boadilla, boxes, CambridgeUS, Copen-hagen, Darmstadt, default, Dresden, Frankfurt, Goettingen, Hannover, Ilmenau, JuanLe-sPins, Luebeck, Madrid, Malmoe, Marburg, Montpellier, PaloAlto, Pittsburg, Rochester,Singapore, Szeged, Warsaw, classic

\usecolortheme{...} albatross, beaver, beetle, crane, default, dolphin, dov, fly, lily, orchid, rose, seagull, sea-horse, sidebartab, structure, whale, wolverine

\usefonttheme{...} default, professionalfonts, serif, structurebold, structureitalicserif, structuresmallcapsserif

©BDW Draft September 16, 2019

§7.3. BEAMER PRESENTATION page 7.7

Check the Beamer manual for sample views of these schemes. Lines 5-6 adjust some ofthe themes settings.

• Line 7 calls an external file beamerouterthemeSoMaSS.sty shown below. This file cre-ates a footline with the short author’s name (defined by [...] on line 10), a shortpresentation title (defined by [...] on line 11), affiliation and frame (slide) number:beamerouterthemeSoMaSS.sty

1 \ProvidesPackageRCS $Header: beamerouterthemeSoMaSS.sty,v 1 10/14/12 BDW $

2 \setbeamercolor*{bottom}{bg=gray!30}3 \definecolor{ASU}{rgb}{0.6,0.0,0.2}4 \setbeamercolor{normal text}{ASU}5 \defbeamertemplate*{footline}{xxx}6 {\leavevmode7 \hbox{%8 \begin{beamercolorbox}[wd=.6\paperwidth,ht=8pt,dp=3pt,left]{bottom}9 {\color{ASU} \quad \insertshortauthor\ @10 School of Mathematical \& Statistical Sciences \quad11 \raisebox{-.5pt} {\includegraphics[height=6pt]{asu.pdf}}}12 \end{beamercolorbox}%13 \begin{beamercolorbox}[wd=.3\paperwidth,ht=8pt,dp=3pt,center]{bottom}14 {\color{ASU} \insertshorttitle}15 \end{beamercolorbox}%16 \begin{beamercolorbox}[wd=.1\paperwidth,ht=8pt,dp=3pt,right]{bottom}17 {\color{ASU} \insertframenumber{}/\inserttotalframenumber \quad}18 \end{beamercolorbox}%19 }20 }

Three beamercolorboxes are created with a given width (wd), height (ht) and depth(dp) and proper justification for the text they contain.

! The % at the end of lines 7, 12, 15, 18 prevent extra space being inserted before/-between/after the boxes.

• Lines 8-12 load the appropriate packages

• Lines 13-17 define title, author(s), date, affiliation. Note that each comes with a shortversion, some of them used in beamerouterthemeSoMaSS.sty.

• The first two frames in the presentation, lines 19-25, are the title, and the outline. Thelatter is created automatically by Beamer, and is in fact a sequence of as many slidesas \sections in MAT421syllabus.tex:

Frame 1

©BDW Draft September 16, 2019

page 7.8 §7.3. BEAMER PRESENTATION

Frame 2

· · ·

• The presentation is simply compiled using$ pdflatex MAT421syllabus.tex(creates .aux, .log, .nav, .out, .pdf, .snm, .toc, and .vrb files)$ pdflatex MAT421syllabus.tex (second pass to resolve dependencies)

• Additional frames may contain several overlays (or slides) which are displayed incre-mentally. A major advantage of overlays over manually creating multiple slides withminor differences is that it preserves the formatting of the frame, thus yields smoothertransitions between slides (and smaller *.tex files!):

Frame 3

26 \section{Systems of equations}

27 \begin{frame}\frametitle{Systems of equations}28 \begin{itemize}29 \item<1-> Matrix Factorizations ...30 \item<2-> Iterative Methods ...31 \end{itemize}32 \end{frame}

* <..> on lines 29-30 are overlays. Herethere are two overlays (slides)

* <1-> on line 29 means item appears onslides 1 and 2

* <2-> on line 30 means item appears onslide 2 only (after Enter )

©BDW Draft September 16, 2019

§7.3. BEAMER PRESENTATION page 7.9

Frame 4

· · ·

33 \section{Data approximation}

34 \begin{frame}\frametitle{Data approximation}35 \setbeamercolor{alerted text}{fg=red,bg=}36 \begin{itemize}[<1-|alert@+>]37 \item Least-Squares, linear regression

...38 \item B\'ezier curves39 \end{itemize}40 \end{frame}

* <alert@+> on line 36 applies to all\items

* Frame has as many slides as items; +increments with the item counter, i.e.,each item goes in turn into alert mode

* When an item is alerted its color turnsred as set by line 35

Frame 5

41 \section{Derivatives \& Integrals}

42 \begin{frame}\frametitle{Derivatives \& Integrals}43 \setbeamercolor{alerted text}{fg=purple,bg=}44 \setbeamercovered{transparent}45 \begin{itemize}46 \item<1|alert@1> Numerical differentiation ...47 \item<2|alert@2> Numerical integration ...48 \end{itemize}49 \end{frame}

* As in Frame 4 except non-alerteditems are set to transparent

* Each item shown only when inalert mode, otherwise transparent

* Not equivalent to the option[<+|alert@+>] in the itemize ifcontains other itemized items

©BDW Draft September 16, 2019

page 7.10 §7.3. BEAMER PRESENTATION

Frame 6

50 \section{Differential Equations}

51 \transboxout52 \setbeamercolor{alerted text}{fg=purple,bg=}53 \setbeamercovered{transparent}54 \begin{frame}\frametitle{Differential Equations}55 \begin{itemize}56 \item<1|alert@1> Ordinary Differential Equations (ODEs) ...57 \psset{unit=\paperwidth}58 \begin{pspicture}(0,-.04)(0,.04)59 \uput[0](.36,0){\includegraphics<1>[height=.05\paperwidth,width=1.01\paperwidth]{ode1.pdf}}60 \uput[0](.36,0){\includegraphics<2>[height=.05\paperwidth,width=1.01\paperwidth]{ode2.pdf}}61 \end{pspicture}62 \item<2|alert@2> Partial Differential Equations (PDEs) ...63 \end{itemize}64 \end{frame}

* An example of the use of \includegraphics with overlays: ode1.eps is shownwith slide 1 and ode2.eps with slide 2 in this frame, giving the impressionthat the change is in the picture itself.

* A transition effect is added on line 51. Other effects include

\transblindshorizontal

\transblindsvertical

\transboxin

\transcover

\transdissolve

\transfade

\transglitter

\transhorizontalin

\transhorizontalout

\transpush

\transslipverticalin

\transslipverticalout

\transuncover

\transwipe

The command \transduration{2} can be used to set the duration.

©BDW Draft September 16, 2019

§7.3. BEAMER PRESENTATION page 7.11

Frame 7

· · ·

65 \section{Summary}

66 \begin{frame}[fragile,shrink=5]\frametitle{Summary}67 \begin{itemize}68 \item<1-> ...69 \item<2-> ...70 \item<3-> ...71 \item<4>72 \begin{alltt}73 \textbf{\color{red}{Spring 2013}}74 \textbf{\color{blue}{TTH 1:30-2:45pm, ECA221}}75 \textbf{\color{purple}{LN#10752}}76 \end{alltt}77 \end{itemize}78 \end{frame}

* An illustration of the use of thealltt environment and \colorcommand. A verbatim-like en-vironment requires the optionfragile on line 66. Note also theuse of negative shrinking percent-age factor (i.e. a magnification) ofthe whole frame.

* Note that \item[] nullifies the de-fault item symbol (•)

• Finally, here is an example of frame which includes both videos and sound using thecommands \movie and \sound from the multimedia package:

Frame 8

©BDW Draft September 16, 2019

page 7.12 §7.4. RESOURCES

79 \renewcommand{\insertshorttitle}{Beamer + movies \& sounds}

80 \begin{frame}\frametitle{Movies \& Sound...}81 \begin{center}82 \begin{tabular}{lcl}83 \hyperlinkmovie{vid1}{\beamerbutton{A FFT plot}}&&\hyperlinkmovie{vid2}{\beamerbutton{A surface plot}}\\84 \movie[label=vid1,width=.33\textwidth,height=.4\textwidth]{}{video1.avi}&85 \sound[label=applause,inlinesound]{\includegraphics[width=.15\textwidth]{applause.pdf}}{applause.mp3}&86 \movie[label=vid2,width=.33\textwidth,height=.4\textwidth]{}{video2.avi}\\87 \hyperlinkmovie[pause]{vid1}{\beamerbutton{pause}}\;\hyperlinkmovie[resume]{vid1}{\beamerbutton{resume}}&88 \hyperlinksound[loop]{applause}{\beamerbutton{Applause (loop)}}&89 \hyperlinkmovie[pause]{vid2}{\beamerbutton{pause}}\;\hyperlinkmovie[resume]{vid2}{\beamerbutton{resume}}\\90 &\hyperlinkmute{\beamerbutton{mute}}91 \end{tabular}92 \end{center}

93 \end{frame}

* Line 79 resets the short title to be used in the footline.

* Buttons can be created with the \beamerbutton command.

* The commands \hyperlinkmovie and \hyperlinksound create hyperlink to the moviesand sound files from the \movie and \sound commands using labels. Options includepause and resume.

* The sound file applause.mp3 is imbedded in the PDF file using the inlinesound optionon 85 (must use pdflatex).

* Videos files cannot be embedded in the *.tex file. Hyperlink for videos may not workunder all platforms. The type of video playable files also depends on the platform (try.avi, .mp4, or .qt). It may be possible to play videos from other sources (internet)using the externalviewer option on lines 84 and 86.

* The videos video1.avi and video2.avi were created using the following Matlabscripts:

video1.avi

1 close all2 myvideo = VideoWriter('video1.avi');3 myvideo.FrameRate = 4;4 open(myvideo);5 plot(fft(eye(17)))6 axis square tight off7 set(gca,'nextplot','replacechildren');8 for k = 1:169 plot(fft(eye(k+16)));10 writeVideo(myvideo,getframe);11 end12 close(myvideo);

video2.avi

1 close all2 myvideo = VideoWriter('video2.avi');3 myvideo.FrameRate = 10;4 open(myvideo);5 Z = peaks; surf(Z);6 shading interp7 axis tight8 set(gca,'nextplot','replacechildren');9 for k = 1:8010 surf(sin(2*pi*k/20)*Z,Z)11 shading interp12 writeVideo(myvideo,getframe);13 end14 close(myvideo);

7.4 Resources• General LATEX information and packages

©BDW Draft September 16, 2019

§7.4. RESOURCES page 7.13

1. Wikipedia on LATEX. See in particular the LATEX wikibook for a good guide forboth beginners and experts.

2. www.latex-project.org3. (Wikipedia, see also Comprehensive TeX Archive Network)4.5. The Beamer class to create slides for presentations6. The PSTricks package enables the user to draw graphs and complicated figures,

including 2D and 3D objects (see also the pstricks-add package under Packages)

• Distributions:

1. TeX Live for all platforms (Wikipedia, see also www.tug.org/texlive/). IncludesTeXworks editor for Windows & Mac (use Kile on Linux)

2. for Windows (Wikipedia, see also www.miktex.org). Includes *.dvipreviewer Yap

3. ProTeXt for Windows (Wikipedia, see also www.tug.org/protext/)

• LATEX editors:

1. for all platforms (Wikipedia, see also www.lyx.org)2. for Linux (Wikipedia, see also kile.sourceforge.net)3. for Mac OS X (Wikipedia, see also http://www.uoregon.edu/ koch/-

texshop)4. TEXnicCenter for Windows (Wikipedia, see also www.texniccenter.org)5. WinShell (Wikipedia for Windows, see also http://www.winshell.de/)6. for Windows (Wikipedia, see also http://www.winedt.com)7. LATEXon the web: overleaf: free plan that allows one collaborator, version control,

etc

ProblemsP7.4.1 Duplicate the LATEX Script on page 7.2, inserting your name, “LATEX exercise” as a title,and using your own picture instead of dog.eps. You may want to use a picture converted fromanother format. Turn in a printout of your LATEX file and PDF output.

P7.4.2 Write a LATEX file including a theorem (use \begin{theorem} . . . \end{theorem}) anda proof about the identity cosh2 x− sinh2 x = 1. Turn in your LATEX file and PDF output.

P7.4.3 Find out what the following packages are about:

©BDW Draft September 16, 2019

page 7.14 §7.4. RESOURCES

1. float 2. array 3. color 4. pstricks 5. stackrel 6. multicol

©BDW Draft September 16, 2019