LaTeX

advertisement
LaTeX
How to setup and write a lab in
LaTeX
What is it and how is it different?
• Latex is a scripting language used for writing
documents.
• It differs from Microsoft Word in that it uses a
WYSIWYM instead of a WYSIWYG editor
• The advantages of this are numerous, but are
most beneficial for academic writings.
• Say if you write a scientific paper and wish to get
it published. Each publishing firm will have its
own layout of how it wants things. If you write it
in Latex you only need to change the style file to
set it into their format. There is no need for a
complete rewrite.
Getting Started
• First, assuming that you use windows there are a few
things that need to be installed.
• The first of these is MikTeX. This is the software used to
compile the files into a presentable format. It also
includes a Dvi viewer. Dvi is the default out put for Latex.
It has numerous disadvantages to PDF format. The main
disadvantage is that the picutures can only be in eps or
png format while PDF supports jpg and bmp aswell.
• The next software that needs to be installed is the editor.
I will used Texnic Center. It is the free version. There are
alternatives such as WinEdt, but they cost money. One
other alternative is Texmaker, but it has not been fully
implemented yet
Installation notes
• Install Miktex first, unless you don’t have a
PDF viewer.
• The binary files for compilation are in
C:\Program Files\MiKTeX 2.5\miktex\bin
• This directory is important for when the
editor is being installed.
• Change version number based on the
version downloaded.
• Next install the editor.
Starting the report
• First consider what type of paper you are writing
so that you know whose packages to install.
– Physics uses The Physical Review Packages
– Math uses The AMS packages, which is also useful
for writing just a general document or a Logic report.
– Chemistry even uses some specialized packages, but
much of its writing can be achieved through AMS. If
you are interested in exploring chemistry packages
further follow the link to get started. Click Here.
– Most can just be searched on Google, or found using
the MikTex package manager.
Creating the directory
• Keep all of the associated files in a single
directory.
• Latex was probably originally made for linux, so
it is a little picky about path names.
• Path names should have not special symbols or
spaces. In fact the folder that you place the files
in should be kept in the root directory on a
windows machine.
• Also if you use any specialized style files they
should also be kept with the projects files. These
are .sty files.
Lets start the Document
• Now its finally time to do something.
• The first thing that must be done is all of
the headers must be created.
• First I will do a generic nonspecific one,
then I will do the more complicated
Physical Review stuff.
Document Class
• This is the first line.
• It starts \documentclass[options]{Class}
• Options are often specific to the class but
there are generic options for both.
• There are 4 main classes: article, letter,
book, and slides
• Each of these can have options
associated with it. These options will
define the document structure and look.
Options
• First define the font size. Options are 10pt, 11pt,
and 12pt, They are typed exactly like that.
• Use commas and only commas to separate
options.
• The next option you can define is paper size. If
you just want regular printer paper don’t put any
thing. Options for this are letterpaper, a4paper,
a5paper, b5paper, executivepaper, and
legalpaper.
• Columns:
– You can specify one or two colums with onecolumn or
twocolumn
Examples
• Example 1: 12pt font, regular paper, two
columns with a title page
– AMS
• \documentclass[12pt,twocolumn,titlepage]{article}
– Physical Review
• \documentclass[aps,prl,twocolumn,oneside,floatfix]
{revtex4}
– New options for the package being used. Aps and pr; are
just defining options. Oneside, which is not needed, will
format to print to one side of a page. Floatfix will anchor
floating objects to the pages. They can otherwise be sent
to a page of floats.
More Examples
• Example 2: 12pt font, regular paper, one
column columns with no title page
– AMS
• \documentclass[12pt]{article}
– Physical Review
• \documentclass[aps,prl,oneside,floatfix]{revtex4}
• As you can see just put options in there
separated by a comma an nothing else.
Next Set of Commands
• The next set of commands is the use
package commands.
• Its structure is:
\usepackage[options]{packagename}
• There is a set of packages that should be
loaded for just about every paper. These
packages define the math symbols and
how to use images.
Necessary packages
• When doing a generic paper there is one
package that must be loaded.
• That is: \usepackage[latin1]{inputenc}
• This calls the inputenc package and uses latin1
as its option.
• There are many other options than latin1 but for
the most part they look the same. They are:
ansinew, applemac, latin1, latin2, latin3, latin4,
latin5, latin9, latin10, cp437, cp850, cp852,
cp858, cp865,, cp866, cp1250, cp1252, cp1257,
decmulti, and next. [1]
More
• If you plan on using any math then there
are 3 packages that are a must. They are:
• \usepackage{amsmath}
• \usepackage{amsfonts}
• \usepackage{amssymb}
• If you plan on using images use
• \uspackage{graphicx}
Finally beginning a document
• Now with all of the defining information out of the way,
we can start the document.
• The body of the document is contained totally between
two tags.
• At the top after all of the stuff we have already declared
you begin the document with \begin{document}
• While you are there, so that you don’t forget you might
as well declare the end of document line.
• \end{document}
• Everything that you write goes between these two tags.
Generic Title
• The Generic title and the Physical review titles
are done differently
• The generic title will automatically put the date in
for you.
• You begin this section with the \title command.
• \title{title name}
• This will offset the title by itself with its own font.
• Next is the \author{author info} tag.
Generic \author
• The generic version of this tag is a little different than it is for the
Physical Review.
• In the generic tag you must also define affiliation information here.
• Its structure is:
• \author{name \\ Department Name \\ College Name \\ City, State, Zip
code}
• I have introduce a new command here. When you are writing Latex
will not register hitting enter as you wanting to go to the next line.
You must tell the compiler to go to a new line with the \\ command.
This command will apply any where in the document.
• You finish this section off with the make title command.
• It is \maketitle
Title
Your name
Department name
College name
City State Zipcode
Date
Making a Physical Review Title
• The \title tag is the same.
• Now the \author tag is just the authors
name.
• We get a new tag: \affiliation{affiliation
info}
• In this tag the affiliation info is the same
that extra part in the author for the generic
style.
Something Completely New
• The Physical Review package ads
something new to the title. It ads the
Abstract section.
• \begin{abstract}
• Abstract text
• \end{abstract}
• After this section you can put the make
title command.
Beginning a new section
• In the generic case the \begin{abstract} abstract
\end{abstract} goes before the first section
• Now you can begin a new section.
• To begin a new section simply type
• \section{section name}
• At the top of the next paragraph put \indent to
indent.
• Sometimes the compiler is stupid and you must
put \\ \indent, or \indent \indent
• To begin a new paragraph simply type \\ \indent
Now To More Specific Stuff
• Now you have seen all of the needed to
get the basic structure down we can start
getting into more specific things.
• I will first cover inserting math, then cover
inserting pictures, and to finish off inserting
tables.
Inserting math
• There are many ways to insert math
equations into Latex. Which way used all
depends on what your situation is.
Situation 1:
• You need to put units in a line, or put a value in a line, or insert a
greek\latin letter, or even put some logic symbols in a line.
• This is one of the most simple insertions that you can make. Say for
example you wish to write the acceleration of gravity in a line. You
write $9.8 \frac{m}{s^{2}}$
• You go into math rendering by typing a the ‘$’. You can type your
value. Then you need to put in units. Acceleration is expressed in
fractional units. So to get a fraction you type
\frac{numerator}{denominator}
• I also introduced a new command here. ‘^{power}’ This will raise
what ever it is attached to the specified power .
• If you wish to subscript you simple do the opposite and type
‘_{subscript}’
• Use ‘$’ to close off the last end of the math.
• $^{#}$ is also a good way to do references, and in text citation.
Situation 2
• You need an equation by itself. That is
also numbered. You do this with
• \begin{equation}
• Equation
• \end{equation}
• If you wish to leave it unnumbered simply
put an asterisk at the end of the word
equation. \begin{equation*} equation
\end{equation}
Lets expand.
 d 2 R 
rs   dv
I 
2 
 dt 
• I want to write the equation: i   
a
• I would write:
• \begin{equation}
• \lambda_{i} =\iint_{a}^{b}I \left(\frac{d^{2}\Delta
R}{dt^2}\right)\delta r \delta s \sqrt{\rho} \int dv
• \end{equation}
• Imagine how long that would take to put into Words
equation editor. It tooke me 5 minutes while I can type it
in latex in just a few seconds.
• Full lists of Mathematical symbols can be found all over
the internet. I one time found a 300 page book full of
them, and how to use each one. They were categorized
and shown.
b
The output
A final Special case
• There are many more special cases, but
their solutions are easy to find on the
internet, mainly in wikibooks.
• There is one more special math case that
must be considered. That is writing a
percentage. The percent symbol is the
symbol used to comment out a line. So a
percent sign must be written as
• $\%$
Inserting Images
• Most editors will have an image inserter,
but it will not hurt to know how to do it your
self.
• Here is the what your type
• \begin{figure}[Position]
• \includegraphics[width=\columnwidth]{File
name}
• \caption{ caption \\ \hline \label{figure#:}}
• \end{figure}
The parts
• The position is really tricky, Options are
–
–
–
–
–
T – top of page
R – Right side of page
! - let the compiler decide
Any combination can be used.
From my experience the compiler will put the image where ever
it feels like on the page that you are typing on. Just play around
with it until you get it where you want it. Sometimes it is even
useful to wait until you are done before you put in figures so that
you can see where every thing will go.
• The \\ \hline is not required, but I like to used it to set up
a divider between regular text and the figure itself.
Finishing Pictures
• There are still two more issues to discuss. That is the width and file
names.
• This used \columnwidth to set the picture size. This will probably be
desirable only for the case where you used two columns.
• Other than that you use decimal points to represent the desired size.
25% = 0.25
• File names are a final consideration. PDF format has support for
multiple files, including png and jpg. I usually use png because it is
default. The file names are case sensitive. The picture must lie in
the directory that the rest of the files are in, and it can not have any
spaces in the name.
• This is just a consequence of this originally being in Linux
Last topic is Tables.
• Tables have some very specific issues I
will cover each seperately.
• To do this I will use this example table.
The code for this table
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
\begin{table} [tr!]
\begin{ruledtabular}
\begin{tabular}{| c | c | c | c |}
\hline
$\lambda$(nm) &
$\lambda$ (m)
& $\frac{c}{\lambda}$
\hline
405
& 0.000000405 & 7.41E+14
& 0.815
\\
\hline
435.8
& 4.358E-07
& 6.88E+14 & 0.532
\\
\hline
546.1
& 5.461E-07
& 5.49E+14 & 0.499
\\
\hline
577.7
& 5.777E-07
& 5.19E+14 & 0.438
\\
\hline \hline
slope
& 3.28E-15 & $\frac{\phi}{e}$ & 1.4586 $^2$\\
\hline
$h_{theoretical}$ & 6.626E$-$34 & $h_{measured}$ & 5.16167E-34 \\
\hline
\end{tabular}
\end{ruledtabular}
\caption{This table is the data taken during this experiment.
\label{table1:}}
\end{table}
& Voltage(V) \\
First things first. Start out an work in.
•
•
•
•
•
•
•
•
•
Begin the table with \begin{table}[position]
And end with \end{table}
The position element works exactly the same.
Now there are two commands that go between that.
\begin{ruledtabular}
table info
\end{ruledtabular}
\caption{ Caption \\ \hline \label{table1:}}
This should be self explanatory from the picutures, but if
it is not stop me.
The table info
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
\begin{tabular}{| c | c | c | c |}
\hline
$\lambda$(nm) &
$\lambda$ (m) & $\frac{c}{\lambda} & Voltage(V)
\hline
405
& 0.000000405 & 7.41E+14
& 0.815 \\
\hline
435.8
& 4.358E-07
& 6.88E+14
& 0.532 \\
\hline
546.1
& 5.461E-07
& 5.49E+14
& 0.499 \\
\hline
577.7
& 5.777E-07
& 5.19E+14
& 0.438 \\
\hline \hline
slope
& 3.28E-15 & $\frac{\phi}{e}$ & 1.4586 $^2$\\
\hline
$h_{theoretical}$ & 6.626E$-$34 & $h_{measured}$ & 5.16167E-34 \\
\hline
\end{tabular}
(explain to them from memory)
\\
Final Statements
• Latex can be used even out side of the narrow
limits that I have explored it in. A little google, or
wikibooks search will uncover lots of information
for any issue.
• Even everyday MLA papers can be written with
it. I have a link in the Links section. There will be
many things put up on the CSC website from
this slide show, and then some.
• You can contact me at hembreer@hsc.edu or at
x6484
Links
•
•
•
•
•
http://www.miktex.org/
http://www.toolscenter.org/
http://www.ocf.berkeley.edu/~jjlin/latex/
http://en.wikibooks.org/wiki/LaTeX
http://web.ift.uib.no/Fysisk/Teori/KURS/WR
K/TeX/symALL.html
Download