Introduction to LaTeX |
|---|
| Franz Kollmann, 2002-2007 |
| 1. Preface |
| 2. Document types |
| 3. Some Packages |
| 4. Titles |
| 5. Layout Settings |
| 6. Winfonts |
| 7. Lists and Enumerations |
| 8. Tables |
| 9. Formeln |
| 10. Graphiken |
| 11. Algorithms |
| 12. Code-Listings |
| 13. PDF Generation |
| 14. List of Abbreviations |
| 15. Index |
| 16. BibTex |
| 17. Beispiele |
1. Preface |
|
The aim of this section is to give a short introduction into LaTeX and
showing examples that can be easily copied and checked out.
For someone who has already used LaTeX knows:
LaTeX written documents look really professional!
And the best: it is for free! Automated numbering of pictures, tables, definitions, references to bibliography or any section in the text, homogenous layout, easy footnotes are just some highlights that make LaTeX so powerful. Nevertheless, proprietary features can take you a lot of time in practice. So, do not say I would not have warned you! ;-) Similar to HTML, LaTeX is a language for describing pages. This means that a latex document writer does not see the layout of the document during editing, i.e. no WYSIWIG ("What You See Is What You Get") like it is provided by MS Word or StarOffice. However, the professional layout compensate for all and once used you won't miss it any more. I personally use the LaTeX-environment mikTex and as an editor I use WinEdt. In the editor the documents are saved as tex files. The latex compiler (latex) generates dvi (device independent) files from the tex sources. Dvi files can be viewed by a dvi viewer (e.g Yap which come with the mikTeX environment). Now its time for our first exercise: Open your text editor and copy the following lines into it and save the file as example.tex
\documentclass{article}
\begin{document} My first LaTeX document! \end{document}
By typing "latex example.tex" into your shell, you will get "example.dvi",
which can be viewed and printed by the the dvi viewer (e.g. Yap).
The picture below should illustrate the processing of a LaTeX file
and should make clear the dependencies between the several file types. |
![]() |
If LaTeX is already installed (with the valid path settings to the following commands),
then type the following commands into your console:
latex example.tex starts the complier, yap example.dvi or xdvi example.dvi shows the result dvips -f example | lpr converts and prints the postscript document. In particular there are three formats of interest: .tex LaTeX source file .dvi formatted text file .ps printer file format |
2. Document Types | ||||||||||
\documentclass[optionen]{klasse}
specifies the document type | ||||||||||
| Vital document classes | ||||||||||
|
||||||||||
|
3. Some Packages | ||||||||||||||||||||||||
At the beginning of the tex file, packages are declared which can really make things easier.
Here only a small selection of possible packages is listed.
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
To include a package the command "\usepackage" should be used
\usepackage[latin1]{inputenc} % Allows to use German special characters (ä,ö,...)
\usepackage{ngerman} % German Spelling | ||||||||||||||||||||||||
|
In recent LaTeX environments, packages are installed automatically (when required).
In older environments, these packages had to be installed manually.
Here is an example that shows how to include the listings package manually (for a Linux/Unix OS): 1.) Create directory listings in the directory /usr/share/texmf/source/latex/ 2.) Copy files from the packages into the created directory 3.) Execute latex listings.ins in that directory. 4.) Create directory listings in /usr/share/texmf/tex/latex/ 5.) Move all sty and cfg files into /usr/share/texmf/tex/latex/ 6.) Execute texhash (root required) (Win: click Refresh in the MikTex options) |
4. Titles | ||||
\part{title}
\chapter{title} \section{title} \subsection{title} \subsubsection{title} \paragraph{title} \subparagraph{title} | ||||
|
5. Layout Settings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6. Winfonts |
Download http://www.ctan.org/tex-archive/fonts/winfonts/winfonts.zip
winfonts.zip (or here: winfonts.zip).
Install the downloaded package as described in README.
In winfonts-doc.pdf
a description of how to include the package is given.
The following fonts are supported:
|
| Note that ps and eps output formats of these fonts are not supported. To include them into the pdf result, they can only be used with latex2pdf. |
| Change font face (e.g. Verdana) |
|
\usepackage[T1]{fontenc}
\fontfamily{verdana}\selectfont |
| Example to include Winfonts, Webdings and Wingdings |
|
\documentclass{article} \usepackage[T1]{fontenc} \usepackage{pifont} \usepackage{winfonts} \usepackage{windingbats} \usepackage{winpifont} \begin{document} \section{Winfonts} \fontfamily{arial}\selectfont Arial \normalfont \\ \fontfamily{courier-ttf}\selectfont Courier New \normalfont \\ \fontfamily{comicsans}\selectfont Comic Sans \normalfont \\ \fontfamily{franklingothic}\selectfont Franklin Gothic \normalfont \\ \fontfamily{georgia}\selectfont Georgia \normalfont \\ \fontfamily{impact}\selectfont Impact \normalfont \\ \fontfamily{palatino-ttf}\selectfont Palatino \normalfont \\ \fontfamily{sylfaen}\selectfont Sylfaen \normalfont \\ \fontfamily{tahoma}\selectfont Tahoma \normalfont \\ \fontfamily{times-ttf}\selectfont Times New Roman \normalfont \\ \fontfamily{trebuchet}\selectfont Trebuchet \normalfont \\ \fontfamily{verdana}\selectfont Verdana \normalfont \\ \renewcommand{\ttdefault}{courier-ttf} {\tt ttsettings} Die Wingding-Symbole: \Pisymbol{wingding}{1} ... \Pisymbol{wingding}{255} Die DING-Symbole: \Pisymbol{ding}{1} ... \Pisymbol{ding}{255} Die PZD-Symbole: \Pisymbol{pzd}{1} ... \Pisymbol{pzd}{255} Die WEBDINGS-Symbole: \Pisymbol{webdings}{1} ... \Pisymbol{webdings}{255} Die PSY-Symbole: \Pisymbol{psy}{1} ... \Pisymbol{psy}{255} \end{document} |
7. Lists and Enumerations |
|
|
|
\begin{itemize}
\item blablabla \item blablabla \end{itemize} |
|
|
|
\begin{enumerate} \item blablabla \item blablabla \end{enumerate} |
|
|
| Choose a symbol and write it between the brackets "[]" below. |
|
\begin{description}
\item[+] blablabla \item[+] blablabla \end{description} |
8. Tables |
|
\begin{table}[h!]
\begin{center} \begin{tabular}{|l|c|c|}\hline 0,1 & 0,2 & 0,3\\ \hline 1,1 & 1,2 & 1,3 \\ 2,1 & 2,2 & 2,3 \\ 3,1 & 3,2 & 3,3 \\ \hline \end{tabular}\\ \end{center} \centering \caption{Description of the table} \label{tabref01} \end{table} |
[hbp] | Position of the table
|
h = here, t =top, b = bottom of page, p = page
(own page). The priority is given by the order. An exclamation mark (e.g.: [h!]) expresses an unconditional position (see in the example above). | |
{|l|c|c|} |
Structure and alignment of the table | In this example it has three columns; contents in the first are flushed left, the others are centered.
Each column is separated by a horizontal line (which is defined by a pipe "|") l = left, r = right, c = center (alignment within columns) |
\hline | horizontal line |
Trennzeichen der Datenfelder |
\usepackage{hhline} \usepackage{array} ... \begin{center} \begin{tabular}{l|*{11}{>{\centering}p{6mm}}|} \hhline{~|-*{9}{-}-|} Index & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \tabularnewline \hhline{~:=*{9}{=}=:} \rule[-2mm]{0mm}{7mm}Line 1 & a & b & c & d & e & [f & g & h & i & j & k]\tabularnewline\hhline{~|-*{9}{-}-|} \rule[-2mm]{0mm}{7mm}Line 2 & & & & & & & & & & & \tabularnewline\hhline{~|-*{9}{-}-|} \rule[-2mm]{0mm}{7mm}Line 3 & & & & & & & & & & & \tabularnewline\hhline{~|-*{9}{-}-|} \end{tabular} \end{center} |
\usepackage{hhline} \usepackage{array} \newcolumntype{I}{!{\vrule width 1.5pt}} ... \begin{center} \begin{tabular}{|*{10}{>{\centering}p{6mm}|}} \hline \rule[-2mm]{0mm}{7mm} 5 & 9 & 13 & 26 & \multicolumn{1}{c I}{7} & 16 & 3 & 10 & 8 & 20 \tabularnewline \hline \hline \rule[-2mm]{0mm}{7mm} & & & & & \multicolumn{1}{c I}{ } & & & & \tabularnewline \hline \rule[-2mm]{0mm}{7mm} & & & & & & \multicolumn{1}{c I}{ } & & & \tabularnewline \hline \rule[-2mm]{0mm}{7mm} & & & & & & & \multicolumn{1}{c I}{ } & & \tabularnewline \hline \rule[-2mm]{0mm}{7mm} & & & & & & & & \multicolumn{1}{c I}{ } & \tabularnewline \hline \rule[-2mm]{0mm}{7mm} & & & & & & & & & \multicolumn{1}{c I}{ } \tabularnewline \hline \end{tabular} \end{center} |
9. Formulae |
|
To display math formulae, the math environment must be set:
\begin{math}2+1\end{math} resp. \begin{displaymath}2+1\end{displaymath}
Hereby $ can be used as a short form for \begin{math} resp. \end{math}.
An example for a fraction would be:$\frac{1}{2}$ which is 1/2.
\mathbb{N} gives the symbol for the set of natural numbers (the package \usepackage{amsfonts} is required)
Here some further examples, just check it out: |
|
section{Formeln in \LaTeX} \vspace{1cm} Arithmetische Mittel einer Stichprobe: \begin{displaymath} \bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i \end{displaymath} Varianz einer Stichprobe: \begin{displaymath} s^2 = \frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x}) \end{displaymath} Standardabweichung: \begin{displaymath} s = \sqrt{s^2} = \sqrt{\frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x})^2} \end{displaymath} oder: \begin{displaymath} = \sqrt{\frac{ \sum_{i=1}^{n} (x_i - \bar{x})^2}{n-1}} \end{displaymath} Geometrisches Mittel: \begin{displaymath} G = \sqrt[n]{ \prod^n_{i=1} x_i} \end{displaymath} Binomialkoeffizient: \begin{displaymath} {n \choose k} = \frac{ n! }{ k! (n-k) !} \end{displaymath} Zeitunabhängige dreidimensionale Schrödingergleichung: \begin{displaymath} \frac{\partial^2 \psi}{\partial x ^2} + \frac{\partial^2 \psi}{\partial y ^2} + \frac{\partial^2 \psi}{\partial z ^2} = - \frac{2m}{\hbar^2}(E -U)\psi. \end{displaymath} Faradaysches Induktionsgesetz: \begin{displaymath} \oint \bf{E} \cdot ds = -\int \frac{\partial \mathcal{B}}{\partial t} \cdot \bf{A} \end{displaymath} |
10. Graphics | ||||||
|
||||||
\begin{figure}[htbp]
\begin{center} \includegraphics[width=0.6\textwidth,angle=0]{filename.jpg} \caption{Description} \label{graphik_1} \end{center} \end{figure} |
||||||
|
11. Algorithms |
The package algorithm and algorithmic makes algorithms to look nice. |
\usepackage{algorithm} \usepackage{algorithmic} ... \begin{algorithm} \caption{myAlgorithm} \label{alg_myAlgorithm} \begin{algorithmic}[1] \STATE{$S \leftarrow 0$} \STATE{$i:=0$} \FOR{$i=0$ to $10$} \STATE a[i]:=0 \ENDFOR \IF{$x>y$} \RETURN{true} \ELSE \RETURN{false} \ENDIF \end{algorithmic} \end{algorithm} |
\IF{} \ELSIF \ELSE \ENDIF \FOR{} \ENDFOR \FORALL{} \ENDFOR \WHILE{} \ENDWHILE \REPEAT \UNITIL{} \LOOP \ENDLOOP \REQUIRE \ENSURE |
12. Code-Listings |
The package listings
allows to include code listings.
Here is an example: |
\usepackage{listings} \lstlistoflistings \definecolor{darkgray}{rgb}{0.95,0.95,0.95} \lstset{language=C++} \lstset{backgroundcolor=\color{darkgray}} \lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt} \lstset{keywordstyle=\color{red}\bfseries\emph} \begin{lstlisting}[frame=tb] for(i = 0; i < 10; i++) { // increment the pointer *p++ = i; House h = new house(); int romms = h.getRooms(): } \end{lstlisting} |
Also external files can be included:
|
\usepackage{listings} \lstset{language=Java, backgroundcolor=\color{yellow}, basicstyle=\small, commentstyle=\color{green}} \lstset{linewidth=\textwidth, showstringspaces=false} \lstset{numbers=left, stepnumber=5, numbersep=10pt} \lstset{frame=trBL} \lstinputlisting[caption=Multi-Page Java Code,label=lst:java]{example.java} |
The following languages are supported: Algol, C, C++, Cobol, Delphi, Eiffel, Fortran, HTML (preliminary), IDL, Java, ksh, Lisp, Logo, make, Mathematica, Matlab, Mercury, Miranda, Modula-2, Oberon-2, Octave, Pascal, Perl, PHP, PL/I, Prolog, Python, R, S, SAS, Simula, SQL, tcl, TeX, VBScript, XML (preliminary) and others. |
13. PDF Generation |
|
To generate pdf files from tex files, I would recommend the converter pdflatex (Syntax: pdflatex myfile.tex).
To include pictures the package graphicx is probably the best choice.
Since with this package pdflatex supports also jpg files:
\includegraphics[width=\textwidth,angle=0]{graph1.jpg}
If pictures are included without file extensions
(e.g.:\includegraphics[width=\textwidth,angle=0]{graph1}),
the converter pdflatex expects a graph1.pdf file;
the latex converter expects an eps file.
For converting eps files to pdf files,
the converter epstopdf could be used (e.g.: epstopdf mygraphic.eps).
|
Tip:
Generally graphics should be given in the eps (encapsulated postscript) format.
This is the graphic format that the latex compiler can process.
For the creation of eps files, an arbitrary postscript printer (print to file option) can be used.
This can be achieved by installing a postscript printer as a file printer.
Then you are able to generate eps files from any format by simply printing on that printer and saving the output as eps file.
If pictures are given in eps as well as pdf files, it can be an advantage to reference the graphic files in the includegraphics command without the file extensions:
pdflatex converts the tex file into a pdf file by processing pdf pictures. latex converts tex file into dvi file by processing eps files. This would save the conversion task (epstopdf *.eps and changing file extensions in the tex file). The dvipdfm converter enables to create pdf files from dvi files (See converting of LaTeX files). |
14. List of Abbreviations | ||||||||||||
To include a list of abbreviations the following steps should be performed: | ||||||||||||
| ||||||||||||
15. Index | ||||||||||
For including an index directory, the following steps should be performed: | ||||||||||
| ||||||||||
16. BibTeX |
For creating and managing bibliographies, BibTeX is the right choice.
bibtex generates from a bib file a bbl file, which is later on imported when compiling with the latex command.
The bib file is a file where all the bibliography entries are stored.
The entries in that file look like: |
|
@book{Sch96:crypt,
key = {Sch96}, author = {Bruce Schneier}, title = {{Applied Cryptography}}, publisher = {Addison-Wesley}, address = {Bonn}, year = {1996} } @article{Swb02:win, key = {Swb02}, author = {Holger Schwichtenberg}, title = {{Mobiles Erlebnis}}, journal = {ix}, year = {2002}, volume = {Ausgabe Juni}, pages = {18} } @book{Has01:java, key = {Has01}, author = {Vesna Hassler and Mikhail Gordeev and Martin Manninger and Christoph Müller}, title = {{Java Card for E-Payment Applications}}, publisher = {Arctech House}, address = {Boston}, year = {2001} } |
|
In the tex file the book of Bruce Schneier is referenced by \cite{Sch96:crypt} bibtex (Syntax: bibtex [bib_file_without_file_extension]) would convert this entry into: |
|
\bibitem[Sch96]{Sch96:crypt} Schneier, Bruce: {\em Applied Cryptography\/}, Addison-Wesley, Bonn, 1996. |
|
After referencing the bibliography entries (inserting cite commands into your tex file) the following steps should be performed: 1.) Execute latex test.tex (creates among others the aux file) 2.) Execute bibtex [bib_file_without_file_extension] (creates bbl file) 3.) Execute latex test.tex twice (files are updated and included) The result is written into test.dvi Besides book and article there are further bibtex bibliography types:
booklet,proceedings,inproceedings,
incollection,inbook,phdthesis,
mastersthesis,techreport,manual,
unpublished, misc and others To include a URI, it is recommended to use the misc type with the \url command (requires \usepackage{url} in the tex file). |
|
@misc{Riv92b:sig, key = {Riv92b}, author = {Ron Rivest}, title = {The MD5 Message-Digest Algorithm}, howpublished = {\url{ftp://ftp.isi.edu/in-notes/rfc1321.txt}}, year = {1992} } |
|
Often BibTeX has problems to break/wrap long URI and inserts percent signs %.
To avoid this, the URI should be split in the bib file by a comma. There are several styles to format the bibliography; for example: plain, alpha, abbrv, unsrt, amsalpha, geralpha, gerapali. To include the style in the tex file, one should use: \bibliographystyle{plain}
For entries in german, it could be advantageously to include in the tex file:
\usepackage{bibgerm} I have stored my own bib style settings in maddog.bst , Besides other features, it prints out et al. for more than three authors. The entries are referenced as [Riv99] für Ron Rivest 1999. To try it out you can download the style into the tex file; include it with \bibliographystyle{maddog} in your tex file. Tip: For aligning the bibliography entries one could use \begin{thebibliography}{widest-label}
in the bbl file. Note that it does not matter what you write into the widest-label,
only the length of the characters are taken into consideration.
|
17. Examples |
|
\documentclass{article} \begin{document} Mein erstes \LaTeX\-generiertes Dokument! \end{document} |
|
|
|
%DIN-Letter (A4) \documentclass[a4paper]{dinbrief} \usepackage[latin1]{inputenc} \Absender{\small D. Knuth\\ \LaTeX\-Street 1 \\ 1111 Springfield \\} \signature{D. Knuth} \Betreff{Invitation to join the \LaTeX\ course} \begin{document} \begin{letter}{To \\ Henry Ford\\Flowerstreet 1\\ 1234 New York\\ \\ USA} \opening{Dear Mister Ford,} I would invite you to join my \LaTeX\ course next Saturday. Please let me know in advance whether you and your wife will come. \\ \closing{Best regards,} \end{letter} \end{document} |
|
|
%% -- by Franz Kollmann, Jan 2002 --
\documentclass[bibtotocnumbered, headsepline,normalheadings]{scrreprt} \usepackage{ngerman} \usepackage[latin1]{inputenc} \usepackage{epsfig} \newcommand{\N}{\mbox{$I\!\! N$}} % die natuerlichen Zahlen \newcommand{\Z}{\mbox{$Z\!\!\! Z\!$}} % die ganzen Zahlen \newcommand{\Q}{\mbox{$Q\!\!\!\! I$}} % die rationalen Zahlen \newcommand{\R}{\mbox{$I\!\! R$}} % die reellen Zahlen \newcommand{\C}{\mbox{$C\!\!\!\! I$}} % die komplexen Zahlen \newcommand{\F}{\mbox{$I\!\! F\!$}} % endliche Körper \begin{document} \setlength{\emergencystretch}{2em} \title{\Huge Mobile Security} \author { \emph{Franz Kollmann} \\ \textsf{maaaddog@gmx.at}\\ \\ \\ \\ \\ \\ MatrikelNr.: 123456 \\ \textsf{\LARGE \textbf{Seminararbeit}} \\ LV-Leiter: DI Dr. Dr. Max Mustermann \\ Universität Klagenfurt, Österreich\\ \\ } \date{\huge WS 2001/02} \maketitle \thanks{Danksagung} \begin{abstract} Hier eine Zusammenfassung Ihrer Arbeit geben! \end{abstract} \tableofcontents \listoffigures \chapter{1 Vorwort} \chapter{2 Einleitung} \chapter{3 Kapitel 1} \section{Sektion 3.1} \subsection{Unterpunkt 3.1.1} \subsection{Unterpunkt 3.1.2} \subsection{Unterpunkt 3.1.3} \section{Sektion 3.2} \subsection{Unterpunkt 3.2.1} \section{Sektion 3.3} \begin{thebibliography} \\ \bibitem[Sha98]{Sha95} Adi Shamir (1995): \textsl{RSA for Paranoids}, 2.Auflage Addison-Wesley, New York \end{thebibliography} \begin{appendix} \section{Appendix} \begin{verbatim} Verbatim kennzeichnet Textabschnitte die direkt (1:1) ins Dokument übernommen werden sollen. \end{verbatim} \end{appendix} \end{document} |
|
Anmerkung: Die "%"-Zeichen stehen am Anfang von Kommentaren. Gewünschten Source in einem beliebigen Editor eingeben und mit der Extension "tex" abspeichern. |
|
|
%% -- by Franz Kollmann, Mai 2002 -- %%-------------------------------------- \documentclass{scrreprt} \usepackage{ngerman} \usepackage[latin1]{inputenc} \usepackage{graphicx} %%-------------------------------------- \begin{document} \setlength{\emergencystretch}{2em} %%-------------------------------------- \title{ \begin{figure}[t] \begin{center} \includegraphics{logo_uni.jpg} \end{center} \end{figure} \Huge Digitales Signieren am PDA} \author{ \\ \\ \\ \\ \\ \\ \LARGE \textbf{Diplomarbeit} \\ \\ \\ \\ \\ \emph{Franz Kollmann} \\ \textsf{maaaddog@gmx.at} \\ MatrikelNr.: 1234567 \\ Betreuer: DDr. Max Mustermann\\ \\ \\ Universität Klagenfurt, Österreich\\ \\} %%-------------------------------------- \date{\huge 2002} \maketitle %%-------------------------------------- \thanks{Danksagung} %%-------------------------------------- \newpage {\LARGE \textsf{EHRENWÖRTLICHE ERKLÄRUNG} }\\ \\ \\ \\ \textsf{Ich erkläre ehrenwörtlich, dass ich die vorliegende Schrift verfasst und alle ihr vorausgehenden oder Sie begleitenden Arbeiten durchgeführt habe. Die in der Schrift verwendete Literatur sowie das Ausmaß der mir im gesamten Arbeitsvorgang gewährten Unterstützung sind ausnahmslos angegeben. Die Schrift ist noch keiner anderen Prüfungsbehörde vorgelegt worden.} \\ \\ \\ \\ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \\ \\ \\ \\ \\ {\bf \textsf{Klagenfurt, 10.09.2002}} %%-------------------------------------- \abstract{ \hspace{145pt} {\huge Abstract} \\ \\ Hier kurz das Thema motivieren und zusammenfassen.} %%-------------------------------------- \tableofcontents %%-------------------------------------- \chapter{Vorwort} \chapter{Einleitung} \chapter{Theoretischer Teil} \section{Ebene 1} \subsection{Ebene 2} \subsubsection{Ebene 3} \paragraph{Ebene 4} \chapter{Praktischer Teil} \chapter{Resümme} \begin{thebibliography} \\ \bibitem[Vock02]{Vock02} Alfred Vockinger, \textsl{Java auf Mobilgeräten}, Java Spektrum Ausgabe 07/08 2002 \end{thebibliography} \end{document} |