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
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
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).
• 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.
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:
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*}
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}. \]
• 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.
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
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
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:
• 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!):
* 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.
* 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:
* 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
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: