Top Banner
S An introduction to LaTeX Dr. Paul Hancock The University of Sydney
31

An introduction to LaTeX

Feb 25, 2016

Download

Documents

rumor

An introduction to LaTeX. Dr. Paul Hancock The University of Sydney. Overview. What is LaTeX ? Why use LaTeX ? How to use LaTeX Common tricks Further references/resources. What is LaTeX ?. TeX is a typesetting system LaTeX is a document markup language based on TeX - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An introduction to  LaTeX

S

An introduction to LaTeX

Dr. Paul HancockThe University of Sydney

Page 2: An introduction to  LaTeX

Overview

What is LaTeX? Why use LaTeX? How to use LaTeX Common tricks Further references/resources

Page 3: An introduction to  LaTeX

What is LaTeX?

TeX is a typesetting system LaTeX is a document markup language based on

TeX “a programming language that produces

documents”

Page 4: An introduction to  LaTeX

Why Use LaTeX?

LaTeX can typeset equations and symbols with ease LaTeX can update citations and references automatically LaTeX separates content and structure from formatting and

style: You provide content/structure (.tex files) Publisher provides formatting and style (.sty files)

Ideally you spend more time on content than on formatting Most (astronomy) journals require submissions to be in

LaTeX

Page 5: An introduction to  LaTeX

LaTeX example

You can access many symbols and characters without needing to choose crazy fonts that no-one else has

L_{Edd}=4\pi GMm_{p}c/\sigma_{T}\cong1.3\times10^{38}(M/M_{\odot})\,\mathrm{erg\: s^{-1}} becomes:

Page 6: An introduction to  LaTeX

How to use LaTeX

Edit ms.tex in your favorite text editor (emacs/vim/etc)

“Compile” your document and open latex ms.tex; xdvi ms.dvior pdflatex ms.tex; acroread ms.pdf

Page 7: An introduction to  LaTeX

latex or pdflatex?

“latex ms.tex” will produce .dvi files that can be read by xdvi latex will leave spaces for eps/ps files which are then

added in by xdvi when displaying your document “pdflatex ms.tex” will produce .pdf files that can be

read by acrobat “pdflatex” will embed png/jpg files within the pdf itself

.pdf files are more easily transported cross platform and are smaller in size than .dvi+eps files

Page 8: An introduction to  LaTeX

Graphics format

You cannot use eps/ps and png/jpg graphics in the same document

Vector graphics Resolution independent Files size depends on content not image size Can be manipulated within latex using psfrag

Raster graphics Fixed resolution and file size More easily portable (no fonts needed)

Page 9: An introduction to  LaTeX

S

Basic components

Page 10: An introduction to  LaTeX

Sections

Use \section*{} for un-numbered sections

Page 11: An introduction to  LaTeX

Figures

\begin{figure}\end{figure}Placement of figure (h! = here damnit!)Center figure

within available space

Size of figure Filename (extension optional)Caption text

Label (must be *after* caption)

Page 12: An introduction to  LaTeX
Page 13: An introduction to  LaTeX

TablesColumn alignment (left, right center) use | here for lines between columns

& to separate columns

\\ to end row

\begin{tabular}makes columnsHorizontal lines

\caption must be after \end{tabular}

Label (must be after caption)

Page 14: An introduction to  LaTeX
Page 15: An introduction to  LaTeX

Equations and symbols

Inline mathmode uses $...$ Superscript uses ^, subscript uses _

For more than a single character: use 10^{-15} or S_{radio}

Page 16: An introduction to  LaTeX

Equations and symbols

Equation environment uses \begin{equation} \end{equation}

Page 17: An introduction to  LaTeX

Large ([{| in equations

\left( \right) \left{ \right} \left| \right| \left[ \right]

For matrices use \begin{array} \end{array} (cf. tabular)

These will scale with the height of whatever they enclose, including nested brackets.

Page 18: An introduction to  LaTeX

References and labels

Create labels with \label{fig:good_plot} \label{sec:introduction}

Reference with \ref{sec:introduction}

Page 19: An introduction to  LaTeX
Page 20: An introduction to  LaTeX

Citations and Bibliography

\usepackage{natbib} for easy bibliography Create a bibliography file eg, ms.bib Use \citep{Kormendy1995} when you want to cite

the paper See http://merkel.zoneo.net/Latex/natbib.php for

more ways to cite papers/authors At the end of your document write

\bibliographystyle{plainnat} \bibliography{ms}

Page 21: An introduction to  LaTeX

Creating a bibliography

Type of entry (@article, @book, @inproceedings, …)

Citation key for \citep{Kormendy1995}

Bibliographic information

Page 22: An introduction to  LaTeX

ADS can provide .bib entries

Bibliographic entry that you can copy into your .bib file. Usually needs editing.

Page 23: An introduction to  LaTeX

And then in the bibliography:

Page 24: An introduction to  LaTeX

Getting bibtex to work

(pdf)latex/bibtex rely on each other so you must do: Latex ms.tex % will complain about undefined \cite Bibtex ms % update ms.bbl and fix missing \cite Latex ms.tex % replace ??? with actual citations Latex ms.tex % fix long citations that overhang

Sometimes it all goes bad and you need to start fresh: >rm *.aux *.bbl

\usepackage[utf8]{inputenc} to avoid problems with unicode. eg, names like Königl

Page 25: An introduction to  LaTeX

Citation management

JabREF – Java stand alone Zotero – Browser plugin + stand alone Mendeley – Online + stand alone Papers2 –OSX/iOS stand alone ADS native – online Many more No universal solution

Still better than by-hand management

Page 26: An introduction to  LaTeX

Table of contents

\tableofcontents Long section titles

can be a problem \section[short

name]{long name} can avoid this

[short name] will appear in the ToC

{long name} appears in the text

Page 27: An introduction to  LaTeX

List of figures/tables

\listoffigures \listoftables Captions will be used

as labels. \caption[short cap]

{long cap} can avoid this

[short cap] appears in LoF/LoT

{long cap} appears in text

Page 28: An introduction to  LaTeX

Typesetting Code

\usepackage{listings} % For highlighting code \usepackage{color} % For colour Provides syntax highlighting for many different

languages Import whole files with \lstinputlisting{example.py} Short codes with

\begin{lstlisting}[language=matlab] \end{lstlisting}

Page 29: An introduction to  LaTeX

code.tex

Page 30: An introduction to  LaTeX

Useful Resources

Examples and templates: LaTeXthings.tar from www.physics.usyd.edu.au/~hancock/index.php/Main/

LaTeX I will maintain this page and update with examples upon

request Send me your solutions to problems

Fellow students PhD students and Postdocs are a good resource

(they have more time than professors)

Page 31: An introduction to  LaTeX

Detexify

http://detexify.kirelabs.org/classify.html is an easy to use lookup service for latex commands