Difference between revisions of "LaTeX"

From AstroBaki
Jump to navigationJump to search
(7 intermediate revisions by 4 users not shown)
Line 2: Line 2:
* None
* None
=== Additional Reading ===
=== Useful Links ===
* [https://github.com/AaronParsons/ugradio/raw/master/texprimer/simple.ps LaTeX Tutorial] Carl Heiles' original LaTeX tutorial (note: may need to save to disk first before opening)
* [https://github.com/AaronParsons/ugradio/blob/master/latex_template/Lab_Report_Guidelines.pdf Lab Report Guidelines] Comments on how to write a lab report
* [https://raw.github.com/AaronParsons/ugradio/master/texprimer/sample.tex LaTex Tutorial Code]: the raw code for compiling the above document
* [https://github.com/AaronParsons/ugradio/tree/master/latex_template/lab1 LaTex Template] Template you may use for your lab report
** [https://www.overleaf.com/read/hvrwkmfkvkhg Overleaf version of the lab template]
\usepackage{amsmath, amsfonts, amssymb}
%Remember that in a tex file, a percent sign means 'comment' and the
* Carl Heiles' original LaTeX tutorial
%rest of the line will not appear in the printed output.
** [https://github.com/AaronParsons/ugradio/raw/master/texprimer/sample.pdf LaTeX Tutorial]
** [https://raw.github.com/AaronParsons/ugradio/master/texprimer/sample.tex LaTex Tutorial TeX] The original LaTeX file to the original LaTeX tutorial
%another option include preprint2, which gives you two columns. to invoke:
* AASTeX Resources
** [http://journals.aas.org/authors/aastex/aassymbols.pdf AAS Symbols] Useful AASTeX Greek, Maths and Astronomy symbols
** [http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf Extended Cut of AAS Symbols] Dr. Scott Pakin's All the Symbols Your LaTeX-ing Will Ever Need
** [http://journals.aas.org/authors/aastex.html AASTeX Packages] AASTeX Style files
%Note: If you're doing work for some other class and don't want to use
* [http://detexify.kirelabs.org/classify.html Detexify] Help finding the LaTex symbol you are looking for
%aastex formatting, you can use some varient of the following commands,
%which are intrinsic to LATEX. However, some commands below, such as
%\altaffiltext and \deluxetable, are peculiar to aastex.
\title{\LaTeX\ Is Your Friend OR ENEMY?????????.}
{\bf Originally written by Nathan Lundblad}
\begin{abstract} We present a paper on useful \LaTeX\ stuff. Make sure
to look at the source code for this document, as that is where the real
story is. For more fun, look at Leslie Lamport's book in the 705
Campbell bookshelf. \end{abstract}
\section{The Big Picture}\label{bigpicsec} %NOTE THE LABEL SYNTAX
LaTeX (pronounced {\it lay}-teck or {\it lah}-teck) is a
designer package based on a typesetting program called \TeX\, which was
originated by Donald Knuth of Stanford many many years ago. \LaTeX\ first appeared in
1985 and is extremely popular, particularly in the scientific community
where it has become an almost universal standard. Using \LaTeX\ will
result in stunningly beautiful documents and will, in the long
run---because of mathematics and labels/referencing---be easier to deal
with than using Micro\$oft Word$^{tm}$ and its cousins. Although
creating reports and articles in a different fashion from what you may
be used to can be a little intimidating at first, a few basic facts and
a couple of good sample documents will
take you a long way.
\section{How To Use \LaTeX: The Most General Possible Summary}
        Remember on PC word processors how there is an option called
{\it reveal codes} or some such? Well, in \LaTeX\ you essentially write
those codes yourself, and then compile them to get your printable
output. You'll type up these codes in your favorite text editor and
name the file something appropriate with a <tt>.tex</tt> suffix.
        Then you must compile that file at your shell prompt by typing
<tt>pdflatex whatever</tt> (you can include the suffix <tt>.tex</tt> if you
want). \LaTeX\ will spit out some random files (provided you haven't
made any errors), including <tt>whatever.pdf</tt>, which is your printable
output. \LaTeX\ will also print some messages on your screen. {\it Be
sure to look at these messages!!!!!!!} If your compilation failed, they
will attempt to tell you what error you may have committed. Once you
figure it out, you edit the <tt>tex</tt> file and try running <tt>pdflatex
whatever</tt> again. The most common error is to forget the \$ sign on each
side of an equation, or to have unmatched curly brackets. The error
message gives the line number; the easiest way to find the offending
text is to go to that line number in your editor. {\it NOTE} that many
times the error occurs {\it before} the line number given by the \LaTeX\
        To view the <tt>whatever.pdf</tt> file on your terminal screen,
type <tt>evince whatever.pdf</tt> at your shell prompt. The nicely-formatted output appears
on the output window. You can edit the <tt>tex</tt> file and left
click on your <tt>pdf</tt> output window; the updated text appears.
Look things over carefully and make any changes {\it before printing it
on paper}---support environmentalism! Finally, to print the output when
you're all done:
\item <tt>lp whatever.pdf</tt> (prints the file).
\section{Some Basic Syntax}\label{basicsec}
Every LaTeX document must be enclosed by a
<tt>begin</tt> and <tt>end</tt> tags.
Nothing goes after the latter, but some very important stuff goes
before the former, such as documentclass declarations and suchlike,
which you'll learn about later.
As you may have noticed, LaTeX reserves more than a few characters for
its own nefarious purposes. Generally, to produce them in your final
document you must invoke the backslash. The same method applies to other
special characters: \{ \# \} \%.
There are three kinds of hyphens in LaTeX: -,--, and ---. The
first is used for intra-word dashes, the second for number ranges
(41--42), and the third for the standard intra-sentence dash---it's my
personal favorite. In other situations, just use whatever looks the
Grouping letters and words is accomplished with the \{ and \}
characters. Most commands only work on one group at a time, so surround
the parts of your text you want to modify with curly brackets. For
example, you can have {\it italicized type}, {\bf boldface type}, and
{\tt typewriter-type type}.
Footnotes are incredibly easy to produce, and are automatically
The observant student in the back of the room may cleverly ask
``So how do you create a backslash, if \\ represents a
skipped line?''. Well, you have to use the
<tt>verb</tt> (verbatim) environment, which is handily revealed in the
source code. The argument of the <tt>verb</tt> environment is delimited
by two identical characters; above, we used ampersands. You can use a
pair of any normal characters as the delimiter. The <tt>verb</tt>
environment has an unfortunate peculiarity: you have to put all of its
argument on a single typed line in the <tt>tex</tt> file. Here's an example
of the output from the verbatim envroment:
function wopen
;WOPEN -- return list of all open windows
; Quick way to find all open windows
; result= wopen()
; The current device must be X Windows.
; Written CARL, who finally got fed up
if (!d.name ne 'X') then begin
message, 'DEVICE not set to X Windows.', /INFO
return, -1
device, window_state=openwindows
openwindows = where(openwindows,Nopen)
return, openwindows
The $begin$ tag with the verbatim environment
has the perhaps unfortunate
peculiarity that it skips and starts a new line.
When you're preparing a LaTeX document, it's {\it smart, labor-saving,
sophisticated, and good practice}---but not necessary---to use the
<tt>label</tt> command. The use of labels ensures that you can refer
to sections, equations, figures, and tables by a name---i.e., by {\it
reference}---and not a number. So what's the difference? When you're
inserting, cutting, and pasting, you {\it will} lose count of what
section you're in or what equation is what, which will make referring to
such objects in the text. Because I labeled the beginning of this
section, I can always refer to it using the label, regardless of whether
I go back and make changes in section order.
\section{Style files, packages, and user defined commands}\label{stylesec}
You may have noticed the a <tt>documentclass</tt> in some LaTeX documents.
This line sets a template for the document as a
whole; it tells LaTeX that you want to write an article-type document
using the American Astronomical Society's preprint class package.
The AAS TeX class (used for most astronomy documents) sets the font and layout for
the entire document and it automatically loads some useful packages,
which are collections of new commands that allow you to customize your
document and do nifty things with images and layouts.
        The great beauty of LaTeX lies in how the math comes out. It
does numbered equations exceptionally well, enables math within standard
text, and has a shocking number of special characters available.
Inserting standard equations into a LaTeX document is done with the
<tt>equation</tt> environment, and works like so:
\begin{equation} \label{laplacian}
\frac{\partial^2 V} {\partial x^2}+\frac{\partial^2 V}
{\partial y^2} + \frac{\partial^2 V}{\partial z^2}=0
Laplace would have loved \LaTeX. You can also do Greek letters easily:
\begin{equation} \label{gammaeq}
If you want to put mathematics into text, you can use math
mode, which is commonly delimited by dollar signs.
If you want to show a matrix math equation, you use the <tt>eqnarray</tt>
\begin{eqnarray} \label{smeqn}
{[ ss ]} & {[ st ]} & {[ su ]} & {[ sv ]} \\
{[ ts ]} & {[ tt ]} & {[ tu ]} & {[ tv ]} \\
{[ us ]} & {[ ut ]} & {[ uu ]} & {[ uv ]} \\
{[ vs ]} & {[ vt ]} & {[ vu ]} & {[ vv ]} \\
\; \right]
A \\
B \\
C \\
D \\
\; \right]
\; =
{[ s y ]} \\
{[ t y ]} \\
{[ u y ]} \\
{[ v y ]} \\
\; \right]
If you want an equation, such as $\alpha = \beta \times \Lambda \cdot
4$, to be in bold---including those Greek letters---surround the whole
equation by <tt>boldmath<tt>.
If you want to bring in plots from Python or, for that matter, an
arbitrary graphic, you
must first make sure that the file in question is
an Encapsulated PostScript File or a PostScript file. Once you have the
file in the same directory as your <tt>.tex</tt> file, you can insert it
into the document like so:
\caption{A Gaussian. \label{gaussfig}}
In addition to width, you can define height, angle, and scale. If you
specify only width or height, the other dimension scales automatically.
If you specify both, you can stretch the image. Angle rotates the image
by some number of degree in the positive direction. Scale multiplies the
picture's original size by the number you specify.
When specifying width or height, you must include units. Some options
are: textwidth, in, cm, pt, em, ex. See the Not So Short Guide for more
If you want to display several pictures together or have size scaling or
stretching or rotation, as in Figure \ref{silly}, you can do this.
\begin{figure} [!p]
\caption{This is a very silly figure! \label{silly}}
        One of the most difficult tasks for the novice (and, even, the
experienced!) typesetter is image placement. \LaTeX\ places floating
bodies where it thinks they best fit, which isn't always the most
logical place in a document. You have one way to control placement: the
placement commands, which work for tables and figures. They are: {\tt
[h!], [t!], [p!], [b!]}, meaning: ``put here'', ``put at top of page'',
''make a new page'', ``put at bottom of page''. Sometimes
they are frustratingly inattentive to your desires; this occurs because
\LaTeX\ is smarter than you think it is---there's not enough space to
put the figure exactly where you want it. .Judicious use of sizing (for
images) and using smaller fonts (for tables), or relocating, are your only options.
        Tables are useful for displaying a large number of results.
There are two environments provided for tables; \verb&{table}&, which is
a \LaTeX\ resident environment, and <tt>deluxetable</tt>, which is an
AAS\TeX\ custom environment. <tt>table</tt> is a simpler
version for which the placement commands work; <tt>
deluxetable</tt> is a more elaborate version for which the placement commands
do not work---it always puts the table at the very end, so it's not very
nice for lab reports.
Let's begin with the ordinary table, which is more flexible
because you the placement commands work.
\caption{Sample table \label{normtable}}
%TABULAR FORMAT IS THE WORD HERE; the c's represent centered
%columns, and the vertical bars represent vertical lines.
%Lines are broken by \\, and columns are separated by the
\begin{tabular}{|c|c|} \hline
Temperature & Voltage Drop \\
310K & 0.6761V$\pm$0.0004V\\
300K & 0.7064V$\pm$0.0005V\\
77K & 1.5318V$\pm$0.001V\\
And now, we end with the deluxetable; it's always at the end, on
its very own page. Because we're ending with it, this is one of the few
instances where it's properly placed---but because it's on its own page,
it's placement definitely not elegant!

Latest revision as of 14:04, 2 February 2021

Short Topical Videos[edit]

  • None

Useful Links[edit]

  • Detexify Help finding the LaTex symbol you are looking for