C151 Multiuser Operating Systems Introduction to LaTeX
What is LaTex 2 LaTeX is a document markup language and document preparation system.
Why LaTeX? 3 LaTeX Separate contents from style Word WYSIWYG
Why not MS Word?
Why LaTeX? 5 Portable and free Professionally crafted layouts are available The typesetting of mathematical formulae is supported in a convenient way Output: many different formats Users need only to learn a few simple commands, which specify the logical structure of a document Complex structures such as footnotes, references, table of contents, and bibliographies can be generated easily
Required Tools 6 Editor: TeXnic Winedt Input file: The input for LaTeX is a plain text file with extension “.tex” You can create it with any text editor. It contains: the text of the document and commands which tell LaTeX how to typeset the text. Compiler ( Standard installation for Linux Windows Mac
Output Formats.dvi Device Independent.psPost Script.pdfPDF.rtfRich Text Format.htmlHTML
Compile LaTeX Generate a dvi file: >latex file_name.tex Generate a pdf file >pdflatex file_name.tex
9 Documents Structure (1) Every LaTeX document must contain the following three components: \documentclass{article} \begin{document} \end{document}
Document Structure (2) Every input file starts with the command: \documentclass{...} When all the setup work is done, you start the body of the text with the command: \begin{document} Now you enter the text mixed with some useful LaTeX commands. At the end of the document you use the \end{document}
\documentclass[options]{class} First line of all LaTeX documents specifies the {type} of the document and the [stylesheet] used. book report article letter Ready templates: IEEETrans, ACM, etc. In general, required information is included in LaTeX commands in braces {}, while optional information is included in square brackets []. \documentclass[ieee]{article}
\documentclass{article} 12
\documentclass[twocolumn]{article} 13
\documentclass{report} 14
LaTeX Document Example (1) \documentclass{article} \begin{document} This is some sample text. \end{document}
LaTeX Document Example (2) \documentclass{article} \begin{document} During the 1960s, many large software development efforts encountered severe difficulties. Software schedules were typically late, costs greatly exceeded budgets and the finished products were unreliable. \vspace{10 mm} \noindent People began to realize that software development was a far more complex activity than they had imagined. \end{document}
LaTeX Document Example (2): result
LaTeX Document Example (3) To add a title to a document use \title and \maketitle \title defines the title and \maketitle inserts it into the document \maketitle must come after \begin{document} \maketitle usually comes before any other text \title must come before \maketitle To add an author and date and use \author and \date \documentclass{article} \begin{document} \title{Hello, World! In Latex} \author{Marc Corliss} \date{2/15/2006} \maketitle Hello, World!\\ \end{document}
LaTeX Document Example (3): result
20 Abstracts To create an abstract, place your text in an abstract environment, i.e., between \begin{abstract} and \end{abstract} commands. The abstract should come immediately after your \maketitle command, but before any \tableofcontents command.
Sections \section{Section Title} \subsection{Title} \subsubsection{Title}
LaTeX Document Example (4) \documentclass{article} \begin{document} \title{Hello, World! In Latex} \author{Marc Corliss} \date{2/15/2006} \maketitle \begin{abstract} This is example 4. \end{abstract} \section{Hello, World!} Hello Everyone!\\ \end{document}
LaTeX Document Example (4): result
Spaces Whitespace characters (e.g. blank, tab, single linebreak) are treated uniformly as “space” by LaTeX. Several consecutive whitespace characters are treated as one “space”. An empty line between two lines of text defines the end of a paragraph. Several empty lines are treated in the same way as one empty line.
Spaces \documentclass{article} \begin{document} It does not matter whether you enter one or several spaces after a word. An empty line starts a new paragraph. \end{document}. Editor view Document view
Special Characters The following symbols are reserved characters, that have a special meaning in LaTeX $ & % # _ { } ~ ^ \ Some of these characters can be used in your documents by adding a prefix backslash (escape character): \$ \& \% \# \_ \{ \} The other symbols (and many more!) can be printed with special commands in mathematical formulae.
LaTeX Commands LaTeX commands are case sensitive and start with a backslash \ \documentclass{article} \begin{document} This is \emph{emphasized} text. \end{document} Editor view Document view
Comments When LaTeX encounters a % character while processing an input file, it ignores the rest of the present line. This is useful for adding notes to the input file, which will not show up in the printed version. \documentclass{article} \begin{document} This text is processed. % A comment isn’t \end{document} Editor view Document view
Page Styles LaTeX supports three predefined header/footer combinations. These are known as page styles. The style parameter of the \pagestyle{style} command defines which one to use: plain prints the page numbers on the bottom of the page in the middle of the footer (default page style) headings prints the current chapter heading and the page number on each page header. empty - both header and footer empty
30 Hyphenation There are four hyphens in LaTeX : 1. - (a single dash) is for hyphenating words (two dashes) is for ranges of numbers (three dashes) is for an honest-to-goodness dash between words. 4. $-$ is a minus sign in math mode.
31 Hyphenation \documentclass{article} \begin{document} My cousin-in-law lived in Germany in ; he speaks French--- really, he does. His favorite number is $-2$. \end{document} Editor view Document view
32 The LaTeX Logo You can typeset the LATEX logo with the \LaTeX command. As with most commands, it consumes any space behind it, so if it isn't at the end of a sentence, use \LaTeX\ instead.
33 Appearance of Words \underline{phrase} to underline a phrase, \textbf{phrase} to print a phrase in boldface, and \emph{phrase} to italicize a phrase.
34 Centering Text By default, LaTeX will start all text at the left margin. If you want to center a title, a table, etc., surround what you want centered with the commands: \begin{center} and \end{center}.
LaTeX Example (5) \documentclass{article} \begin{document} \title{\LaTeX\ 1, 2, 3} \author{Liguo Yu} \maketitle \section{Introduction} \begin{center} This is an intruduction! \end{center} \section{Conclusion} Thanks for reading this \textbf{article}. \end{document}
LaTex Example (5): Result
37 Bulleted Lists To create a bulleted list, surround the information with a \begin{itemize} and an \end{itemize}, and begin each item with an \item. \documentclass{article} \begin{document} \begin{itemize} \item A bulleted item. \item Another bulleted item. \begin{itemize} \item A nested bulleted item. \end{itemize} \item You get the idea. \end{itemize} \end{document} Editor view Document view
38 Numbered Lists To create a numbered list, surround the information with a \begin{enumerate} and an \end{enumerate}, and begin each item with an \item. \documentclass{article} \begin{document} \begin{enumerate} \item A numbered item. \item Another numbered item. \item You get the idea. \end{enumerate} \end{document} Editor view Document view
Typesetting Mathematics LaTeX has a Math mode for typesetting mathematics. Within a paragraph, math mode is entered between $ characters, or by using the \begin{math} and \end{math} commands \documentclass{article} \begin{document} Add a squared to b squared to find c squared, e.g. $a^2 + b^2 = c^2$. It’s as easy as that! \end{document} Editor view Document view
Typesetting Mathematics Greek Symbols \alpha, \beta, \gamma Superscript, Subscript x^yx_yx_y^z Calculus \int_0^\infty\int{\int} \frac{\partial u}{\partial x}
Typesetting Mathematics x = \frac{-b \pm \sqrt{b^2-4ac} } {2a}
Figures \begin{figure} \includegraphics{sample.jpg} \caption{A sample figure.} \end{figure}
Example \documentclass{article} \usepackage[pdftex]{graphicx} \begin{document} \begin{figure} \centering \includegraphics{Figure1.jpg} \caption{Depiction of the production of kernel-based software} \end{figure} \end{document} Compile: pdflatex file_name Compile: pdflatex file_name
Result
Columns \begin{tabular}{|…|…|} \end{tabular} Rows & - Split text into columns \\ - End a row \hline - Draw line under row Two Columns l = automatically adjust size, left justify r = automatically adjust size, right justify p = set size e.g p{4.7cm} c = centre text Tabular
Example of table \documentclass{article} \begin{document} \begin{tabular}{|l|r|c|} \hline Date & Price & Size \\ \hline Yesterday & 5 & Big \\ \hline Today & 3 & Small \\ \hline \end{tabular} \end{document} Editor view Document view
Bibliographies Articles can be referred to in the text using the \cite command The details of the cited articles are stored in BibTeX format, in a “.bib” file. BibTeX resolves the citations in the LaTeX file and generates the required bibliography
Bibliographies Example entries from test.bib author ={N. Ahmed and K. Rao}, title ={Digital signal processing}, publisher ={Springer-Verlag}, year ={1975}, address ={New York}, author ={James Austin and A. Phantom and B. Nom}, title ={High Speed Neural Networks}, booktitle ={IEE Image Processing and Applications}, year ={1989}, pages ={28--32}, }
test.tex file \documentclass[12]{article} \begin{document} \title{Work Study 1, 2, 3} \author{Liguo Yu} \date{\today} \maketitle \section{Introduction} This is an intruduction! \section{Result} By far the most commonly used feature is presented by \cite{Aus1989} and \cite{Ahr1975}. \section{Conclusion} Thanks for reading this article. \bibliographystyle{abbrv} \bibliography{test} \end{document}
Compile LaTeX We need to compile.tex and.bib separately and combine the output together to generate a PDF file >latex test (compile.tex file) >bibtex test (compile.bib file) >pdflatex test (geberate.pdf file) Might need to run several rounds to successfully combine them
Result: test.pdf