Introduction to Unix – CS 21 Lecture 16
Lecture Overview LaTeX History Running and creating LaTeX documents Documents and Articles Tables Lists Fonts Math mode
LaTeX – What Is It? A general markup language LaTeX is a system that describes how documents should appear on paper Formatting Margins Section Headings Special characters
Other Examples Of Markup Languages HTML Hypertext markup language Used to describe how web pages appear A little bit of interpretation is still required and pages may look different on different browsers SGML Allows for the construction of special constructs
Where Did It Come From? TeX 1977 – Donald Knuth Low level formatting details Constructed to make mathematical books look good LaTeX 1980’s – Leslie Lamport A layer of abstraction on top of TeX
Why Not Just Use Word? Main reason: Bugs TeX has long had a bounty for serious bugs that no one can collect on Secondary reason: LaTeX does what you tell it to LaTeX doesn’t try to out-think you and put figures where it believes them to be best
O.K., How Does Latex Work? Latex works on plain text files that are annotated with commands Commands are of the form: \command{parameter} Example: \documentclass{article} Document class tells LaTeX what type of document you are creating Books have chapters, articles have sections, etc. Most common: article, book, letter, report, slides
What’s With The Braces? LaTeX uses the braces for grouping like parenthesis { text } is the same as simply text Commands inside braces (like changing fonts) only apply inside the braces Example: { \sf This is in a serif font } And this is not
What Does A LaTeX File Look Like?
How Do I Get A Printable Paper Out? Usage: latex document.tex This creates several files document.aux, document.log, document.dvi document.idx, document.toc, document.lof xdvi document.dvi Views the document dvips –o document.ps document.dvi
Example LaTeX Run
What To Do When Something Goes Wrong Latex will pop up with an error message whenever it encounters a problem Malformed or unknown command Simplest thing to do: Simply hit return and ignore whatever command LaTeX had problems with Alternative: type I followed by the correct command to replace the problem Example: I\end{document}
Sample Run With Problems
Example Latex File
Example Output dvi1.JPG
What Are Comments Doing In A Document? Might seem a little weird coming from using Word LaTeX can define new commands and can be confusing at times LaTeX is not a programming language like perl or awk
Normal Text All paragraphs of normal text are simply typed in without any commands. Spacing is not taken into account, and all spaces get reduced to one space Example: this is the same
Normal Text Example
Normal Text Output dvi2.JPG
Common Constructs Italics and Bolding Sectioning Lists Tables Footnotes Mathematical formulas
Italics And Bolding \emph{text to be emphasized} \bf Changes the font to a bolder font
Italic And Bolding Example
Sectioning Commands NameLevel \part \chapter0 \section1 \subsection2 \subsubsection3 \paragraph4 \subparagraph5
Section Example
Sectioning Output
Unnumbered Sections \section{Section Name} Always numbers the section You can change the format of sections numbers if you’d like \section*{Section Name} Will output an unnumbered section
Unnumbered Example
Unnumbered Output
Counters All sections have a counter associated with them You can adjust this counter if you’d like \addtocounter{name}{value} You can create your own counters \newcounter{name} \setcounter{name}{value}
Counter Example
Printing Out The Current Section Numbers “The” notation Will print out the current value of the counter associated \thechapter \thesection \thesubsection
Ordered And Unordered Lists Ordered lists are handled with the enumerate construct \begin{enumerate} \end{enumerate} Unordered lists are handled with the itemize construct \begin{itemize} \end{itemize} \item
List Example
List Output
Tables Tables are handled with the tabular environment \begin{tabular}{ FORMAT } \end{tabular} FORMAT determines how many columns are in the table and how text is arranged
Format Specifics | represents vertical lines Specific characters tell how to arrange text in the columns l = Left aligned c = Centered r = Right aligned
Table Internal Specifics & will separate columns \hline draws horizontal lines \\ ends a line
First Tabular Example
First Tabular Output
More Complex Tabular Example
Tabular Output
Footnotes Footnotes are handled with the \footnote construct \footnote{This is a footnote} Again, there is an automatic counter that keeps track of your footnotes on a section by section basis
Mathematical Constructs LaTeX was built on Tex, which was designed for easy representation of complex mathematical formulas A special mode for math formulas exists in LaTeX $Math mode$
Adding Accents
Accent Output
Greek Letters
Greek Letter Output
Relational Symbols
Relational Symbols Output
Various Math Symbols
Math Symbols Output
Superscripts and Subscripts In math mode: \sp{ } ^ as a shortcut \sb{ } _ as a shortcut
Complex Math Formula Example
Complex Math Formula Output
Vertical Skip And Horizontal Skip \vskip 0.2in \hskip 3in
When You Don’t Want Any Changes - Verbatim The verbatim environment will attempt to print out everything exactly as it appears \begin{verbatim} \end{verbatim} Spacing comes out just as typed in this mode
Next Time We will look a little more at LaTeX and examine the Make utility Quiz # 3 will be next Tuesday (March 8)