--
VolkanSevim - 15 Oct 2007
Using LaTeX
LaTeX is a document preparation system developed by Leslie Lamport in 1985. It is based on a typesetting language called Tex created by D. Knuth. LaTeX lets you focus on the content of your document rather than working on the layout.
Typical LaTeX File Layout
A LaTeX file has to follow a certain structure. Every input file must begin with the command
\documentclass{}, which determines the type of the document you intend to generate. The body of the text should begin with
\begin{document} and end with
\end{document}. As you might have noticed, the characters
\ and
{} have special meanings in LaTeX. We will see their usage later.
A simple example:
\documentclass{article}
\begin{document}
Hello world!
\end{document}
Let us call name this file
test.tex. In order the generate a document, we need to compile this file with
pdflatex test.tex. LaTeX compiler will generate a pdf file if the compile has been successful. The file
test.pdf should look like
Commands and Typesetting
LaTeX commands start with a backslash
\. Some commands need an argument which is given enclosed between curly braces
{}. For example
Hello \textbf{world}! generates (we omit class declarations etc.)
Here,
\textbf command changes its argument's font to boldface.
Special Characters and Symbols
- Comments are given using a
% character. When LaTeX encounters a % sign it ignores the rest of the line.
- Quotation marks should be used in the form
``text'' or `text' form (grave accent and vertical quote).
Double quotes
"text" will look like
- For ellipsis
... there is a special command, \ldots:
- LaTeX supports accents and special characters:
\c C, \u G, \i, \. I, \" O \c S, \"U
- LaTeX changes the amount of space between words to get a straight margin. you need to insert a tilde
~ if you need a protected space: Figure~5(a) shows the agreement between the theory and simulations.. Here, the space between "Figure" and "5(a)" is protected.
Sectioning the text
LaTeX support several sectioning commands such as
\section, \subsection, \subsubsection. It can also create a table of contents out of these. The command
\tableofcontents inserts a TOC at the place where it is used. You might need to compile your latex file twice to get the TOC right. If you use an asterisk after the sectioning command (
\section*{Some section}) that section does not show up in the TOC. If the section name is too long for the TOC, you can specify a shorter alternative as an optional argument:
\section[Short version]{Original very long version of the section name}
You can generate a title by
\maketitle command. You need to specify the contents of the title before
\maketitle command:
\title{SCS LaTeX Workshop},
\author{Volkan Sevim} ,
\date{17/10/2007}. Here is an example:
\documentclass{article}
\title{SCS LaTeX Workshop}
\date{17/10/2007}
\author{Volkan Sevim}
\begin{document}
\maketitle
\section{Introduction}
This is the intro.
\section{Another Section}
Here is another section.
\subsection{A Subsection}
This is a subsection.
\subsubsection{A Subsubsection}
Can even have a subsubsection.
\section{Conclusion}
The last section
\end{document}
LaTeX also supports cross-referencing to the sections. In order to cross-reference a section (or a subsection, etc.) you need to label it using
\label{sec:nameofthesection}. A
\ref{} command is used to get the number of a section and
\pageref{} command is used to page number of a section. For example:
\begin{document}
\section{Introduction}
\label{sec:intro}
This is the intro, which is section~\ref{sec:intro}.
\subsection{A Subection}
\label{sec:thesubsec}
This is Sec~\ref{sec:thesubsec}. Also see Sec.~\ref{sec:intro} on page~\pageref{sec:intro}.
\end{document}
Creating lists
itemize and
enumarate environments are used to create lists.
To-do list:
\begin{enumerate}
\item Stop by at the store
\item Wash the dishes
\item Pay the bills
\end{enumerate}
Enumerate environment:
\begin{itemize}
\item An item
\item Another one
\item The last one
\end{itemize}
Math Mode
LaTeX has a very powerful engine for mathematical typesetting. In LaTeX, mathematical formulae is either inserted inline or set apart from the rest of the paragraph. In the inline mode, the mathematical expression is simply given between two
$ signs. for example,
$y=3x^2+b displays as
If you want to display the equation separately, you can use
displaymath environment:
Here is a formula
\begin{displaymath}
F=ma \
\end{displaymath}
and another
\begin{displaymath}
F=k\frac{m_1 m_2}{r^2}.
\end{displaymath}
For numbered equations, you should use
equation environment. Referring to equations is similar to referring to sections:
Here is a formula
\begin{equation}
\label{eq:newton}
F=ma.
\end{equation}
This formula is Eq.~(\ref{eq:newton}).
Important commands for mathematical typesetting
- Lowercase Greek letters are given as
$\alpha, \beta$:
. Uppercase Greek letters are given as $\Alpha, \Beta$.
- Exponents and subscripts are specified using caret (
^) and underscore (_) symbols: $v^2=v_0^2 + 2ax$ displays as
- Square root has a special command:
$\sqrt{x+y}$ displays as
, and $\sqrt[3]{27}=3$ displays as
- Vertical quote
' gives a prime, \vec gives a vector arrow, \dot gives a dot operator: $c' = \vec a \cdot \vec b$ displays as
- Function names are typeset in roman fonts. Some important functions are already defined as commands in LaTeX:
$\sin^2 x + \cos^2 x = 1$
- Fractions:
$\frac{a}{b} = \frac{c}{d}$
- Stacking symbols:
$ x \stackrel{?}{=} y+b$
- Summation, product and integral symbols:
\begin{displaymath}
\sum_{i=1}^{N}x_i + \prod_{j=1}z_i + \int_{0}^{\pi}\cos(x) dx
\end{displaymath}
- Sizes of delimiters can be adjusted automatically using
\left and \right commands:
\begin{displaymath}
\left( \left( (x+1)^2 + 1 \right)^2 +1 \right)^2
\end{displaymath}
Figures and Captions: Including Graphics
In order to include graphics in a LaTeX file, we need to load the proper package in the input file. This package is called
graphicx. We also need to specify what kind of graphics files we will be using. If no options are specified, input files are assumed to be encapsulated postscript (eps). For pdf files, we use
pdftex option:
\usepackage[pdftex]{graphicx}
figure environment is used to create figures. You can include graphics and specify a figure caption in this environment as in the example below.
\documentclass{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[angle=10, width=0.5\textwidth]{psds-corr}
\caption{ Power-spectral densities}
\label{fig:psdfigure}
\end{figure}
\end{document}
Here, we created a figure from "psds-corr.pdf" rotated by 10 degrees counterclockwise with half the text width and a caption "Power-spectral densities".
\centering command centers the whole figure.
Bibliography
\thebibliography environment is used to create a bibliography. You can cite a reference using
\cite command in the text.
\documentclass{article}
\begin{document}
Citing a reference \cite{Nakamura:2004}.
\begin{thebibliography}{10}
\bibitem{Nakamura:2004} I.~Nakamura, Eur.\ Phys.\ J.\ B \textbf{40}, 217 (2004).
\end{thebibliography}
\end{document}
If you have lots of references, you can use the BibTeX package to create bibliographic databases. BibTeX package allows automatic numbering and formatting of bibliographies according to journal styles and can save a lot of time.
!LaTeX Editors
There are several freeware LaTeX editors, such as Kile and TexMaker. These editors provide necessary tools to develop a LaTeX document. There is also a LaTeX GUI called Lyx. Lyx is a LaTeX document preparation system that lets you work in a graphical environment, in which you can see and manipulate figures or equations as in MSWord, with the power of LaTeX. You can also import bibliographic databases, create lists and matrices, and do everything else you can do with LaTeX, but in a graphical environment.
References:
1) The Not So Short Introduction to LaTeX2e
http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
2) Using Imported Graphics in LaTeX and pdfLaTeX
ftp://ftp.tex.ac.uk/tex-archive/info/epslatex.pdf