LaTeX examples¶
Example 1¶
Our first example is to show a very basic set of LaTeX typesettings on font styles, spacing, comment lines, itemized and enumerated lists, mathematical expressions, and figures.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | \documentclass[11pt]{report}
% available options are: article, book, report, proc, slides, letter, beamer, memoir, minimal, etc.
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Let's start writing your report
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%re
\section{Spacing, new lines, comments}
This is your first LaTeX document!
\indent \indent Math is fun.\\
This is your first LaTeX document!
%
\indent \indent Math is fun.\\
This is your first LaTeX document!
\indent \indent Math is fun.\\
%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Itemized list}
An itemized list of font styles:
\begin{itemize}
%
\item {\rm{Roman character}}
\item {\it{italic character}}
\item {\bf{bold character}}
\item {\em{emphasized}}
\item {\tt{typewriter}}
%
\end{itemize}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Enumerated list}
An enumerated list of mathematical expressions:
\begin{enumerate}
%
\item
\begin{equation}
ax = b
\end{equation}
%
\item
\begin{eqnarray}
f(x) &=& x^2 + e^{-x} + log_{10}2x \\
g(x) &=& f(x-3)\\
&h(x)& = f(\alpha x) + \gamma - \frac{\kappa}{x-9}
\end{eqnarray}
%
\item You can also write inline mathematical expressions using dollar signs, $f(x) = \sqrt{x}$.
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Figures}
Including a figure is easy. Make sure you have
\verb|\usepackage{graphicx}| before
\verb|\begin{document}|
\begin{flushleft}
\includegraphics[width=2.0in]{baskin-logo-banner.jpg}
\end{flushleft}
\begin{center}
\includegraphics[width=2.0in]{baskin-logo-banner.jpg}
\end{center}
\begin{flushright}
\includegraphics[width=2.0in]{baskin-logo-banner.jpg}
\end{flushright}
You can change the size of your figure and add caption to it.
\begin{figure}[h]
%you need \begin{figure} in order to put caption of your figure
%"h" is for a command option to put your figure "HERE!!!"
\begin{center}
\includegraphics[width=4.0in]{baskin-logo-banner.jpg}
\end{center}
\caption{A bigger figure.}
\end{figure}
\end{document}
|
Buidling the document will generate a pdf output. The LaTeX file, the baskin logo, and the pdf output can be downloaded here:
Example 2¶
Now let’s move on to a more advanced LaTeX documentation.
In the second example we see that a style file
ams200.sty
is included using a command
\usepackage{ams200}
. The style file is a collection of
various useful things, including definitions of user defined
commands, definitions of formatting styles, etc. In this way
users can use the customized commands and definitions
in the main body of documentations
by simply including the style file using \usepackage
command.
This becomes very handy when you wish to use your own custom
commands and definitions in multiple LaTeX files; otherwise
you have to define them at the begining of each LaTeX file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | \documentclass[11pt,twoside]{article}
\usepackage{ams200}
\usepackage{epsf}
\usepackage{epsfig}
\usepackage{lscape}
\usepackage{subfigure}
\usepackage{color}
\usepackage{courier}
\newcommand{\mbf}[1]{\mathbf{#1}}
\newcommand{\noteb}[1]{\textcolor{blue}{{\bf#1}}}
\newcommand{\noter}[1]{\textcolor{red}{{\bf#1}}}
\pagestyle{myheadings}
\setcounter{equation}{0}
\setcounter{figure}{0}
\setcounter{footnote}{0}
\setcounter{section}{0}
\setcounter{table}{0}
%%% MAIN PART OF DOCUMENT
\begin{document}
{\centering{
\includegraphics[width=5.0in]{baskin-logo-banner.jpg}
$\mbf{}$\\
\title{AMS 200: Working on Linux/Unix Machines}
$\mbf{}$\\
$\mbf{}$\\
Prof. Dongwook Lee (dlee79@ucsc.edu)}}
$\mbf{}$\\
$\mbf{}$\\
{\centering{
Department of Applied Mathematics and Statistics}}\\
{\centering{
University of California, Santa Cruz}}
\section{Remote login via SSH}
First of all, you will need to install an SSH (secure shell) client
in order to access one of cluster machines (i.e., computing resources such as grape) remotely. \\
* If you're a PC user, you can download PuTTY from
\\(http://www.chiark.greenend.org.uk/$\sim$sgtatham/putty/download.html). \\
* If you're a Mac or Linux user, you can simply use a terminal that is already available for you.
For example, in Mac, go to $\mbf{Applications}$ $\rightarrow$ $\mbf{Utilities}$ and
open $\mbf{Terminal}$ application. In Linux, $\mbf{Terminal}$
can be found under $\mbf{System}$ in general.\\
Next step is to log in yourself to one of the AMS machines. For today,
you are logging in to a cluster named ``grape". To log in to the cluster,
you need to use a command \texttt{ssh} using the terminal we just mentioned.
In the command line, you type in\\
\texttt{ssh -X your\_name@grape.soe.ucsc.edu}\\
\noindent with your SOE login password. At the step, you're logging into a master node or login node.
As you login for the first time to the master node, you are asked to enter a passphrase.
You can enter a very secured if you wish, or you can simply press enter.
This process is to generate, so-called, ``SSH keys", which is a way to identify trusted computers,
i.e., the rest of compute nodes, without having to enter password every time you run parallel jobs
on these compute nodes. Note that running a parallel job means that you run multiple jobs on
multiple processors, which actually require you to login to the requested compute nodes with password.
This SSH key generation save you from doing this process.
Your login is successful if you see something like the following on your terminal:
\includegraphics[width=5.0in]{firstLogIn.png}
\section{Basic Linux Commands}
There are few rules in using command lines in Linux. Several important rules are\\
* Commands are case-sensitive.\\
* Make sure you always logout yourself by typing \texttt{exit} when you're done.\\
* The Linux command lines enables you to create complex functions by combining
built in command lines together. This capability gives you countless ways to
make your commands work in various different ways. \\
{\it{Exercise 1:}} Please run matlab by typing in a command \texttt{matlab} on a command prompt. \\
{\it{Exercise 2:}} Please exit your current session and try to login again without
having \texttt{-X} option. Please run matlab again. Is there any difference from
the case with \texttt{-X}? You can use \texttt{-Y} instead of \texttt{-X}.\\
{\it{Answer to 1 \& 2:}} \texttt{-X} or \texttt{-Y} option enables X11 forwarding in SSH,
which provides you not only a command line interface from the console,
but also a variety of graphical-user-interfaces (GUIs). With the X forwarding option in login,
you can enjoy a full set of interface display functions remotely.\\
Here you're introduced to learn very basic Linux command lines.
For more comprehensive studies, you can use to display a manual page using the \texttt{man} command,
or you can come to ask the instructors for more help and resources.
\subsection{Managing Files}
\texttt{> ls} --- lists your files\\
\texttt{> ls -l} --- ls in long format\\
\texttt{> ls -a} --- ls all files\\
\texttt{> mv filename1 filename2} --- remane filename1 to filemane2\\
\texttt{> mv filename1 dirname} --- move filename1 to a directory called dirname\\
\texttt{> cp filename1 filename2} --- copy filename1 to filename2\\
\texttt{> rm filename} --- remove a file\\
\texttt{> more filename} --- display the contents of a file as much as will fit on your screen\\
\texttt{> less filename} --- similar to \texttt{more} with the extended navigation capability allowing both
forward and backward
navigations\\
\texttt{> wc filename} --- tells you number of lines, words and characters in a file\\
\texttt{> touch filename} --- creating an empty file (multiple filenames after \texttt{touch} command will create
multiple empty
files)\\
{\it{Exercise 3:}} See if you can find \texttt{ls -l} and \texttt{ls -a} when you execute \texttt{man ls}.\\
\subsection{Managing Directories}
\texttt{> mkdir dirname} --- create a new directory called dirname\\
\texttt{> cd dirname} --- change directory, meaning you go to a directory called dirname\\
\texttt{> pwd} --- tells you where you currently are in the directory tree\\
\texttt{> rmdir} --- an empty directory deletion\\
{\it{Exercise 4:}} Create a directory called \texttt{dirA}, then under \texttt{dirA}, create an empty file named
\texttt{filenameNull}.
\\
{\it{Exercise 5:}} Delete the file \texttt{filenameNull}. Also delete the directory \texttt{dirA}
using \texttt{rm} command. {\it{Hint: Please look up man page of}} \texttt{rm} {\it{and find a useful option for
directory deletion}}.
\\
\section{Editors}
The following text editors are available on grape. You can choose whichever you want to use.\\
(1) vim (or vi): \\
To start --- \texttt{> vi filename1}\\
To edit --- enter ``i" and start inserting text until $<$Esc$>$ hit \\
To delete single character --- \texttt{x}\\
To delete entire current line --- \texttt{dd}\\
To exit --- pressing $<$Esc$>$ key followed by \texttt{:x <Return>} or \texttt{:wq <Return>}
will quit \texttt{vi} saving the content to filename1, whereas pressing $<$Esc$>$
key followed by \texttt{:q! <Return>} will quit \texttt{vi} without saving the latest change to filename1\\
\noindent See more basic commands for \texttt{vi} in http://www.cs.colostate.edu/helpdocs/vi.html\\
\indent (2) emacs:\\
To start --- \texttt{> emacs -nw filename1}\\
To edit --- unlike \texttt{vi}, you can type in any characters in the editor\\
To save the current buffer-- press hold down Control key and type in ``x" and ``s"\\
To save the current buffer with different file name --- press hold down Control key
and type in ``x" and "w" and then enter new file name
To exit the buffer --- press hold down Control key and type in ``x" and ``c"\\
\noindent See more basic commands for \texttt{emacs} in http://www.cs.colostate.edu/helpdocs/emacs.html
\section{Parallel Computing}
Please read the pdf file by Prof. Nic Brummell:\\
https://ams.soe.ucsc.edu/sites/default/files/AMS\_cluster\_grape\_evennewer\_0.pdf
\section{Two Examples}
In both tests, you demonstrate one of the most basic tasks such as printing ``hello world".
\subsection{Running a short program in R -- Statistic Computing}
Use your preferred editor to implement the following lines and save it to a file named ``test.R":\\
\texttt{print(date())\\
\indent set.seed(43678)\\
\indent print("Hello World")\\
\indent print("Random number from standard normal")\\
\indent print(rnorm(1, 0,1))\\
}
\noindent There are two ways to run your R script.
If you want to run the program using an R batch command, type from the Linux shell:\\
\texttt{> R CMD BATCH test.R}\\
Or, you can also run it by first start R (by typing ``R" at the Linux command prompt)
and once inside the R program, you can execute
your source file with the command:\\
\texttt{> source(`test.R')}\\
In the first approach, you can see your results written out to a default output file \texttt{test.Rout}.
In the second example, you should be able to see the output on your screen such as\\
\texttt{[1] "Mon Oct 20 00:43:37 2014"\\
\indent [1] "Hello World"\\
\indent [1] "Random number from standard normal"\\
\indent [1] 0.7932329\\
}
\subsection{Running a short program in Fortran -- Scientific Programming Language}
Again, please use your preferred text editor and implement the following short fortran program:\\
\texttt{\noindent program hello\\
\indent real :: n,m\\
\indent integer :: i,j\\
\indent i = 10\\
\indent j = 2014\\
\indent n=real(i)\\
\indent m=159.e0\\
\indent print *,"i+j=",i+j\\
\indent print *,"n-m=",n-m\\
\indent print *, "Hello World"\\
\indent end program hello\\
}
\noindent You save it to hello.f90. Now you are going to compile it in order to
generate an executable binary. On grape, you can do this using gfortran compiler:\\
\texttt{> gfortran hellow.f90}\\
After compiling your program, you should be able to see an executable
binary file with a default name, \texttt{a.out}. Run it by entering a command line:
\texttt{> ./a.out} \\
{\it{Exercise 6:}} What does your result look like from running hello.f90? \\
{\it{Exercise 7:}} Can you give a different name for the executable instead of the default \texttt{a.out}? \\
{\it{Exercise 8:}} Can you extend the previous serial run of test.R
(and/or hello.f90) to a parallel job, say 2 nodes with 8 processors on each node (i.e., a total of 16 parallel
tasks)?\\
\end{document}
|
You will see that the second example produces a list of basic Linux commands (this is something you also need to learn!).
You can download the files and build them for youself: