Lecture Special L^{A}TEX Help Session

L^{A}TEX Help Session

• What is L^{A}TEX?

• Running L^{A}TEX

• Some commands

• Some examples

Note: L^{A}TEX is in /usr/local/tex3.14159/bin/

on departmental UNIX platforms.

The following material was adapted from the information online at

http://ei.cs.vt.edu/~cs5014/courseNotes/
2.ComputerTools/LaTeX/abrams379.html

Why Use L^{A}TEX?

LaTeX is a system to markup the conceptual structure (sections, lists, mathematics, ...) of documents. Listed below are some of its advantages over other systems to compose typeset documents, such as WYSIWYG (what-you-see-is-what-you-get) word processors.

1. Supports top-down writing style

2. Built on a programming language – therefore it’s extensible

3. Supports mathematics – not just equations. Supports uniform style (such as fonts) on all equations.

4. Allows a document style, designed by a publisher, to be easily superimposed on a L^{A}TEX file. For example, it’s easy to change

1. Introduction

to

I. Introduction

throughout an entire document.

5. Permits easy document interchange: L^{A}TEX files are plain text files

6. Facilities for internal cross references and indexing

7. Many journals - especially those with mathematical bent - accept final manuscripts in L^{A}TEX.

8. Journals and conferences can provide style files that make your document look exactly like other papers in the publication 9. Follows proper typographical rules in

deciding on line and page breaks. Will ask author to rewrite sentence, rather than using improper spacing. Will not put a heading at bottom of page.

10. Automatically extracts reference list from citation database

A Simple L^{A}TEX Document

— A Homework Assignment

%Simple \LaTeX\ Paper
% Following line makes document look like an article
\documentclass{article}
\begin{document}
\begin{center}
{\Huge \bf Homework 1}
\\
by Richard Turing
\end{center}
\section*{Problem 1}
{\em Question: How many sides does a triangle have?}
Answer:  3
\section*{Problem 2}
{\em What is $\sum_1^{10} i$?}
Answer:  $1+2+3+4+5+6+7+8+9+10 = \frac{n(n+1)}{2}$
\end{document}

A More Complex L^{A}TEX

Document — A Paper

% Following line is for emacs to set mode to latex
% -*- Mode: \LaTeX\ -*-
% Following line makes document look like an article
\documentclass[double]{article}
% Following line omits page numbers
\pagestyle{empty}
% Following reset margins and text size
\setlength{\topmargin}{0in} % head to top of body
\addtolength{\textwidth}{1.5in}
\addtolength{\oddsidemargin}{-0.75in}
\addtolength{\evensidemargin}{-0.75in}
\addtolength{\marginparwidth}{-0.5in}
\addtolength{\textheight}{1in}
\renewcommand{\floatpagefraction}{0.8}
\begin{document}
% Following creates the title page
\title{\Large title}
\author{Albert Einstein
\\
Richard Feynman
\\

TR 95-23, \today
\\
Virginia Polytechnic Institute and State University
\\
Department of Computer Science
\\
Blacksburg, VA  24061-0106
}
\date{}
\maketitle
\begin{abstract}
This paper is about nothing.
\end{abstract}
\clearpage
\tableofcontents % print a table of contents page
\clearpage
% Begin using page numbers and a header
\pagestyle{myheadings}
\markboth{Draft:  \today}{Draft:  \today}
\setcounter{page}{1} % reset page number to 1
\section{Introduction}
\label{s:introduction}
This is the world's shortest paper.
It exemplifies a math formula:  $e=mc^2$.
The formula is {\em completely} unrelated

to the text by Aho and Hopcroft~\cite{ahu}.
\subsection{Motivation}
This paper has no motivation.
\section*{Acknowledgements}
The authors would like to thank
the anonymous reviewer
for suggestions that improved the manuscript,
particularly in \S\ref{s:introduction}
on page~\pageref{s:introduction}.
% Lines below illustrate two alternate bibliography
% forms
\addcontentsline{toc}{section}{References}
\bibliographystyle{abbrv}
\bibliography{sampleBib}
%\begin{thebibliography}{99}
%
%\bibitem{adm}
%M. Abrams, N. Doraswamy, and A. Mathur,
{\em Chitra}, TR 92-24.
%
%\end{thebibliography}
\appendix

\addcontentsline{toc}{section}{Appendix A: abc}
\section*{Appendix A:  abc}
\label{s:appA}
\end{document}

Do Use L^{A}TEX Sectioning

Commands

The sectioning commands are:

\section{}
\subsection{}
\subsubsection{}
\paragraph{}

By using these commands, L^{A}TEX will:

1. apply a common style to all occurrences (e.g., put all in bold in the same font size)

2. list them in the table of contents

In particular, do not use {\bf ...} or

\textbf{} in preference to \paragraph{..}

Advanced L^{A}TEX

• How to insert an encapsulated postscript (eps) file into a L^{A}TEX document

• Tables

• Examples of Mathematics

– Example 1: Display vs. in-line equations

– Example 2: Fractions

– Example 3: Arrays

• Defining New L^{A}TEX Commands

How to Insert an eps File into a L^{A}TEX Document

First add in the preamble of the L^{A}TEX document

\usepackage{epsfig}

Then simply use

\epsfig{file=filename.eps}

to insert an eps file. Here’s an example

\begin{center}
\epsfig{file=sin.eps,width=1.5in}
\end{center}

LaTeX Table Example

The first two talks
in the 1995-96 graduate seminar series
are these:
\begin{center}
\begin{tabular}{l|lp{2in}} \hline
{\em Date}  &  {\em Speaker} & {\em Talk Title}
\\ \hline
30 August & Bill Wake & SortTables:  A Browser for at
Digital Library
\\
6 September & Kim Langdorf & Lost in Space?  ---
Satellite Communications and Navigation
\\
\end{tabular}
\end{center}

The corresponding typeset result is shown below. The table puts cells in the third column into left and right justified text boxes that are two inches wide.

The first two talks in the 1995-96 graduate seminar series are these:

Date  Speaker  Talk Title
30 August  Bill Wake  SortTables:  A

Browser for at Digital Library

6 September Kim Langdorf Lost in Space? — Satellite Communications and Navigation

LaTeX Mathematics

Example 1: Display vs.

in-line equations

Shown below is an example comparing display and in-line equations.

The following sum is a display equation:

\begin{displaymath}
\int_{-\infty}^\infty u \cos{u} du =
\cos u + u \sin u
\end{displaymath}

∫_{−∞}^{∞} u cos udu = cos u + u sin u

The following is an in-line formula:

$\int_{-\infty}^\infty u \cos{u} du =

\cos u + u \sin u$, which typesets as ∫_{−∞}^{∞} u cos udu = cos u + u sin u.

LaTeX Mathematics

Example 2: Fractions

\begin{displaymath}
x = \frac {a+b+c/2} {\alpha_i}
\end{displaymath}

x = \frac{a + b + c/2}{α_{i}}

\begin{eqnarray*}
x & = & \frac {x^{2y}} {\log{x+y}}
\end{eqnarray*}

x = \frac{x^{2y}}{log x + y}

CS 5024  September 2, 1997  Slide 12

LaTeX Mathematics

Example 3: Arrays

\begin{eqnarray*}
f(x) & = & \left\{
  \begin{array}{ll}
    a & \mbox{if $x < 0$} \\
    c & \mbox{otherwise}
  \end{array} \right.
\end{eqnarray*}

f(x) = \{ \begin{matrix}a & if x < 0 \\ c & otherwise \end{matrix}

Defining New L^{A}TEX

Commands

You can define a macro as a shorthand for common notation used throughout your document.

General form:

\newcommand{\macroname}{{definition}}

Make ”macroname” descriptive. This makes it easy to change a construct and provides logical structure to the document.

\newcommand{\aij}{{\alpha^i_{j_1}}}
Isn't $\aij$ the most beautiful symbol
you've ever seen?

Isn’t α_{j_{1}}^{i} the most beautiful symbol you’ve ever seen?

A command may also take arguments. Here’s an example with four arguments:

\newcommand{\graph}[4]{$#1
\begin{array}{c}#2 \\
-\!\!\!-\!\!\!-\!\!\!\longrightarrow \\
#3?\end{array}#4$}
Consider \graph{i}{t}{c}{i \oplus 1}.

Typeset result:

Consider i \begin{matrix}t \\ ⟶ \\ c? \end{matrix} i ⊕ 1.