\chapter{Basics}\label{sec:basics}

Keep \citetitle{lshort} handy; as mentioned previously, it is in the
launcher menu under \menupath{Documentation}, or search for `lshort' in the
documentation list, see section \ref{sec:doclist}.

Start a new \LaTeX{} document as described in section~\ref{sec:first}, with
content
\exa
\begin{verbatim}
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
\end{verbatim}
\exb
Hello, world!
\exc
\nextblock
You may already have guessed that macros start with
\texttt{\textbackslash} and that a parameter can be enclosed in
braces \texttt{\{ \}}.  A construct
\benv{something}...\eenv{something} is called an \emph{environment}.

Now try out some of the syntax below on your new \LaTeX{} document.

\section{Paragraphs}

You need to separate paragraphs with empty lines in the input file;
a single linebreak is equivalent to a space.

\exa
\begin{verbatim}
A linebreak in the source
creates a space in the pdf output.

An empty line in the source ends a paragraph.
\end{verbatim}
\exb
\parindent=1.5em\parskip=0pt
\makeatletter\@rightskip=0pt\rightskip=\@rightskip\makeatother
A linebreak in the source
creates a space in the pdf output.

An empty line in the source ends a paragraph.
\exc

\section{Comments}

The percent character, \texttt{\%}, is the comment character;
\LaTeX{} ignores it and everything following it on the same line,
including the linebreak itself.

\exa
\begin{verbatim}
one
%ignore
tw%
o
\end{verbatim}
\exb
one
%ignore
tw%
o
\exc

\section{Control sequences and -characters}

\LaTeX{} commands often take the form of a backslash followed by a
series of letters, \emph{e.g.},
\exa
\begin{verbatim}
\LaTeX
\end{verbatim}
\exb
\LaTeX
\exc

\nextblock
A control sequence swallows succeeding spaces,
so you sometimes have to follow it with \verb|{}| or \verb|~|:
\exa
\begin{verbatim}
\LaTeX code

\LaTeX~code, \LaTeX{} code, \LaTeX.
\end{verbatim}
\exb
\LaTeX code

\LaTeX~code, \LaTeX{} code, \LaTeX.
\exc

\nextblock
Rendering control characters literally:

\nextblock
\begin{tabular}{@{}lll@{}}
%\baselineskip=1.2
& \textit{function} & \textit{render literally with} \\
\texttt{\%} & comment character & \texttt{\bsl \%} \\
\texttt{\{ \}} & parameter; grouping & \texttt{\bsl\{ \bsl\}} \\
\texttt{\bsl} & starts control sequence & \texttt{\bsl textbackslash} \\
\texttt{\bsl\bsl} & newline (!)
\end{tabular}

\section{Grouping}

A pair of braces can also localize the effect of a command:
\exa
\begin{verbatim}
x z {\footnotesize x z} x z
\end{verbatim}
\exb
x z {\footnotesize x z} x z
\exc

\section{Text formatting}

The classfile and stylefiles will take care of many changes in text
attributes, \emph{e.g.}, in section heads and in
bibliographies. \emph{Do not style these items manually.}
Appendix~\ref{sec:appearance} contains some simple recipes for
global changes in appearance.

Below, we describe the more common commands for styling text.

\subsection{Bold and italic}
These commands work on all subsequent text within
the current block:

\exa
\begin{verbatim}
normal \itshape italic \bfseries bolditalic
\upshape bold \mdseries normal
\end{verbatim}
\exb
text \itshape italic \bfseries bolditalic
\upshape bold \mdseries normal
\exc

\nextblock
Argument form:

\exa
\begin{verbatim}
normal \textit{italic} \textbf{bold}
\end{verbatim}
\exb
normal \textit{italic} \textbf{bold}
\exc

\nextblock
These are the basic text formatting commands:

\nextblock
\begin{tabular}{@{}lll@{}}
\hline
& \textit{`from now on'} & \textit{argument form} \\
\hline
\textit{italic} & \cmd{itshape} & \cmd{textit\{...\}} \\
\textup{upright} & \cmd{upshape} & \cmd{textup\{...\}} \\[6pt]
\textbf{bold} & \cmd{bfseries} & \cmd{textbf\{...\}} \\
\textmd{medium} & \cmd{mdseries} & \cmd{textmd\{...\}} \\[6pt]
\texttt{monospaced} & \cmd{ttfamily} & \cmd{texttt\{...\}} \\
\hline
\end{tabular}

\nextblock
Some people recommend replacing \cmd{textit} with \cmd{emph}, which is
short for \emph{emphasized}, as being more in line with structural
markup.

\TS{} has buttons for bold \button{button_bold} and italic
\button{button_italic} on the inner vertical toolbar.

\subsection{Text sizes}

Predefined text sizes; note that some may come out the
same:

\nextblock
\begin{minipage}[b]{0.2\linewidth}
  {\tiny \cmd{tiny}\par}
  {\scriptsize \cmd{scriptsize}\par}
  {\footnotesize \cmd{footnotesize}\par}
  {\small \cmd{small}}
\end{minipage}
\begin{minipage}[b]{0.2\linewidth}
  {\normalsize \cmd{normalsize}\par}
  {\large \cmd{large}\par}
  {\Large \cmd{Large}}
\end{minipage}
\begin{minipage}[b]{0.2\linewidth}
  {\LARGE \cmd{LARGE}\par}
  {\huge \cmd{huge}}
\end{minipage}

\section{Special characters}

Here a short list of typographic characters and how you can create
them in \LaTeX{}, even if you use only typewriter characters in your
input:

\nextblock
\begin{tabular}{@{}llll@{}}
& \textit{output} & \textit{code} \\
Single quotes & ` ' & \texttt{\textasciigrave \textquotesingle} \\
Double quotes & `` '' & \texttt{\textasciigrave \textasciigrave
 \textquotesingle \textquotesingle} \\
Non-breaking space && \texttt{\textasciitilde} \\
Hyphen & - & \texttt{-} \\
En-dash & -- & \texttt{-{}-} \\
Em-dash & --- & \texttt{-{}-{}-} \\
Accented characters
  & \'e & \texttt{\bsl\textquotesingle e} \\
  & \"\i & \texttt{\bsl"\bsl i}
\end{tabular}

\nextblock Using accented \emph{input} characters requires loading
the \package{inputenc} package in the
preamble:\footnote{\texttt{latin1} (ISO-8859-1) and \texttt{cp1252}
  (Windows-1252) are alternatives to \texttt{utf8}, but if we go
  beyond ASCII input at all, utf8 (Unicode) is the more rational
  choice.}
\exa
\begin{verbatim}
\usepackage[utf8]{inputenc}
...
“ ä ï © « ” and `` \"a \"\i{} \textcopyright{} << ''
\end{verbatim}
\exb
“ ä ï © « ” and `` \"a \"\i{} \textcopyright{} << ''
\exc
\nextblock
This method does not cover all unicode characters, and if you type a
lot of code then you may prefer control codes anyway.

For full unicode support, you should use the \XeTeX{} or \LuaTeX{}
engines; see appendix sections \ref{sec:systemfonts} and
\ref{sec:nonwestern}.

\subsection{Hyphens and dashes}

Please be aware that not every horizontal dash is the same. A few
examples of proper use:

\nextblock
\emph{En-dashes} for ranges: \verb|7--9| for `7--9', or to set off -- part
of -- a sentence.

\nextblock
\emph{Em-dashes} also for setting off---part of---a sentence, but now
without surrounding spaces\footnote{Or, better with thin
  spaces \texttt{\textbackslash,}}.

\nextblock
A plain \emph{hyphen} `\texttt{-}' is appropriate for hyphenation and
for compound words such as `cross-referencing'.

\section{Lists: itemize, enumerate and description}

Itemize (unnumbered list):

\exa
\begin{verbatim}
\begin{itemize}
\item camel
\item rabbit
\end{itemize}
\end{verbatim}
\exb
\begin{itemize}
\item[\textbullet] camel
\item[\textbullet] rabbit
\end{itemize}
\exc

\nextblock
Enumerate (numbered list):

\exa
\begin{verbatim}
\begin{enumerate}
\item soup
\item main course
\item dessert
\end{enumerate}
\end{verbatim}
\exb
\begin{enumerate}
\item soup
\item main course
\item dessert
\end{enumerate}
\exc

\nextblock Description lists:\enlargethispage*{26bp}

\exa
\begin{verbatim}
\begin{description}
\item[One] This is a short term.
\item[Quetzalqoatl] Mexican god, about whom we
  could tell a lot if only we had the time and
  inclination.
\end{description}
\end{verbatim}
\exb
\begin{description}
\item[One] This is a short term.
\item[Quetzalqoatl] Mexican god, about whom we could tell a lot if
  only we had the time and inclination.
\end{description}
\exc

\nextblock
Lists can be nested:

\exa
\begin{verbatim}
\begin{enumerate}
\item soup
\item main course
  \begin{itemize}
  \item tortilla filled with meat and vegetables
  \item[--] refried beans
  \end{itemize}
\item dessert
\end{enumerate}
\end{verbatim}
\exb
\begin{enumerate}
\item soup
\item main course
  \begin{itemize}
  \item tortilla filled with meat and vegetables
  \item[--] refried beans
  \end{itemize}
\item dessert
\end{enumerate}
\exc
\noindent
Here a bad example of an item parameter.\enlargethispage*{26bp}
Since the item tag is an optional parameter, it uses
square brackets [ and~] rather than curly braces \{ and \}.

\section{\LaTeX{} classes}\label{subsec:classes}

Each \LaTeX{} document starts with a \cmd{documentclass} line, which
selects a class file. Class files define available features and a
default look. Some important \LaTeX{} document classes:
\begin{itemize}
\item \texttt{article} (no chapters)
\item \texttt{report}
\item \texttt{book}
\end{itemize}

\nextblock
The above classes are very similar in the features they
support. You can add features or change the appearance by loading
packages:\footnote{%
  This preamble is generated by the \TS{} Quick Start wizard.}
\begin{verbatim}
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\end{verbatim}

\section{Sectioning commands}

The standard classes listed above have a predefined sectioning
hierarchy: parts, chapters (not for articles), sections,
subsections, subsubsections, paragraphs and subparagraphs.

All these commands have an optional and a required parameter,
\emph{e.g.}
\begin{verbatim}
\section[Short title]{A very long and impossibly involved title,
which will never fit in a page header}
\subsection{A short enough title}
\end{verbatim}

\nextblock
Sectioning titles may turn up in page headers or in an automatically
generated table of contents. If a title is not short and simple, you
should use an optional parameter which will not cause
trouble when it is reused in page headers or in a table of contents.

\subsection[Bookmarks and clickable cross-references with
hyperref]{Bookmarks and clickable cross-references with
  \package{hyperref}}

{\sloppy The \package{hyperref} package will create bookmarks from
  your sections, and also make all the cross-references in your pdf
  clickable. Add an option \texttt{colorlinks} if you do not like
  the boxes around links:
\begin{verbatim}
\usepackage[colorlinks]{hyperref}
\end{verbatim}
}

\section{Title}

Publications customarily start with some sort of title page or
-block. \LaTeX{} creates such a title with the \cmd{maketitle}
command. You should already have defined an author and title with
corresponding commands.

The \cmd{author}- and \cmd{title} commands can be placed either in
the preamble or in the body of the \LaTeX{} source. The
\cmd{maketitle} command belongs in the body.

Here is an example of an article with a \cmd{usepackage} command, a
title block, a table of contents and sections:\label{code:tocarticle}
\exa
\begin{verbatim}
\documentclass{article}
\usepackage{newpxtext,newpxmath} % palatino font
\begin{document}
\title{Title of article}
\author{My name}
\maketitle
\thispagestyle{empty}

\tableofcontents

\section{A section}\label{sec:ASection}

See section \ref{sec:ASection} on page
\pageref{sec:ASection}.

\subsection{A subsection}

That's all, folks!

\end{document}
\end{verbatim}
\exb
\includedetail{../samples/art_demo}
\exc

\nextblock
Notice the use of cross-referencing commands \cmd{label}, \cmd{ref} and
\cmd{pageref}.

\textit{Warning.} Cross-references usually require more than one
(pdf)\LaTeX{} run before they are correctly resolved. This is also
true for automatically generated text such as tables of
contents. After each \LaTeX{} run you should check the message pane
below the editing area for errors and warnings.

\section{Footnotes and `thanks'}

In the \LaTeX{} source footnotes are placed in the running
text. The \command{footnote} command generates both a mark in the
running text and the footnote itself at the bottom. As with
sectioning, footnotes are numbered automatically:

\exa
\begin{verbatim}
Here comes a footnote.\footnote{%
This is the footnote.}
And some more text.
\end{verbatim}
\exb
\includedetail{../samples/foot}
\exc

\newpage
\nextblock
A special case is a footnote attached to the title or author of an
article. Note that the footnote should be \emph{inside} the title-
or author parameter.

\exa
\begin{verbatim}
\title{Sample title\thanks{%
 Supported by a grant}}
\author{A.U. Thor\thanks{%
 And another grant}}
\maketitle

First line of regular text.\footnote{%
 With a regular footnote.} And some more text.
\end{verbatim}
\exb
\includedetail{../samples/thanks}
\exc

\section{Practice}\label{sec:basics_practice}

Start out with a new document as described in
section~\ref{sec:first}.  Use this document to try out the code
samples from this chapter.

If you feel ready to try bigger things, you can try to typeset some
real text. If you have nothing suitable of your own, you can turn to
Wikipedia articles such as
\url{http://en.wikipedia.org/wiki/Factors_of_production}. You can
copy-and-paste pieces of text from the web page to your own \LaTeX{}
document.

Try to recreate the structure, not the appearance, \emph{e.g.}, use
sectioning commands instead of manually making headings bold, and let
\LaTeX{} create the table of contents. Also pay attention to proper
quotes and typographic characters.

Consult \path{basics_sample.tex} from the practice zip (see
section~\ref{sec:zipfile}) as an example of a complete, structured
\LaTeX{} document.

\nocite{texbook}
\nocite{lamport}
\nocite{kopkadaly}
\nocite{rugtex}
\nocite{tug}
\nocite{texlive}
\nocite{gettingstarted}
\nocite{ctan}
\nocite{ctancat}
\nocite{faq}
\nocite{lshort}
\nocite{tsd}
