0% found this document useful (0 votes)
46 views19 pages

Some Sample L TEX Code

The document provides sample LaTeX code for creating a basic academic paper template. It includes LaTeX code for setting up document formatting and styles, adding a title, author, date and preamble. It also shows code for inserting tables of contents, figures, equations, and references. The document is intended to demonstrate the basic structure and elements of a LaTeX paper.

Uploaded by

ajithkoodal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
46 views19 pages

Some Sample L TEX Code

The document provides sample LaTeX code for creating a basic academic paper template. It includes LaTeX code for setting up document formatting and styles, adding a title, author, date and preamble. It also shows code for inserting tables of contents, figures, equations, and references. The document is intended to demonstrate the basic structure and elements of a LaTeX paper.

Uploaded by

ajithkoodal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 19

A Some Sample L TEX Code Jim Peterson email: petersj@clemson.

edu March 1, 2005

Note on

A L TEX

by Jim Peterson

Contents

Note on

A L TEX

by Jim Peterson

List of Figures

List Of Code Examples

Note on

A L TEX

by Jim Peterson

A In this short document, we will setup a sample short article in L TEX which could be used for A a paper or a Masters project. We will show raw L TEX code using a Verbatim command. This

is dened in a command in the le setup.tex. It has this form: %\mycode{cpp}{Source/CPPCellModels/SimpleHH/run1.prompts}% % {Source/CPPCellModels/SimpleHH/run1.prompts.html}

\begin{Verbatim}[frame=single,framerule=0mm,fontsize=\small]

Your raw code here

\end{Verbatim}

A A You create a pdf document from your L TEX source as follows. Assume your raw L TEX le is

called MyNotes.tex. The steps to create the pdf le MyNotes.pdf are these:
pdflatex MyNotes pdflatex MyNotes % often to resolve references etc you compile % source 2 - 3 times acroread MyNotes.pdf % note you need the extension here.

A We can use the Verbatim command to show you how the raw L TEX is used to create a document. A This le starts with many commands that set up how the le is to processed by L TEX. These lines

are shown below. Following each line is a percent symbol. This symbol indicates that the rest of the line is a comment. Ill try to explain briey what each line does after the percent symbol.

\documentclass[11pt]{article} \usepackage{amsmath} \usepackage{fancyheadings} \usepackage{setspace} \usepackage{fancyvrb} \usepackage{color} \usepackage[hyper]{listings} \usepackage{graphicx} \usepackage{geometry} \usepackage{wrapfig} \usepackage{subfigure}

% % % % % % % % % % % % %

sets up document using 12 pt font as an article using ams fonts uses a package to let us put comments in the headers at the top of each page lets us toggle single and double spacing when we wish lets us set up our own \verb type commands sets up some colors generates hyper links [hyper] to formatted source code {listings} lets us use graphics files package to help us set up the margins of the document lets us wrap text around a figure lets us do a figure with subfigures within it

Note on

A L TEX

by Jim Peterson

\newcommand{\goodgap}{ % special command to set up spacing between subfigures \hspace{\subfigtopskip} \hspace{\subfigbottomskip}} \usepackage{algorithm} % lets us format algorithms nicely \usepackage{algorithmic} % part of algorithms \usepackage[pdftex]{hyperref} % generate hyperlinks in the pdf file \pagestyle{fancy} % fancy headings -- comments at top or bottom of each page %\pagestyle{plain} % a simple heading style \geometry{lmargin=1.0in,rmargin=1.0in,top=0.75in,bottom=0.75in} % package that sets up our margins \rhead{by Jim Peterson} % puts a string at the right side of the top of each page \lhead{{\bfseries Note on}} % puts a string at the left side of the top of each page \chead{\LaTeX} % puts a string in the center of the top of each page \lfoot{} % puts a string at the left side of the bottom of each page \rfoot{} % puts a string at the right side of the bottom of each page \cfoot{\thepage} % puts a string in the center of the bottom of each page % here the page number \addtolength{\headwidth}{0.55in} % makes sure the line printed at top and % bottom of each page is same size as text. \setlength{\headrulewidth}{0.4pt} \setlength{\footrulewidth}{0.4pt} \setcounter{secnumdepth}{3} \setcounter{tocdepth}{3} % %these commands set up pdf hyperlink styles \hypersetup{letterpaper=true,% breaklinks=true,% colorlinks=true,% anchorcolor=blue,% pdfstartpage=1,% bookmarks=true,% bookmarksnumbered=true,% hyperindex=true,% pdfhighlight=/P} \title{Some Sample ~\LaTeX~ Code} % this is our title \author{Jim Peterson\\ % author email: {\tt [email protected]} } \date{\today} % date \include{setup} % includes a file of LaTeX macros \begin{document} % now we start document

The title was set using the following code


\title{Some Sample ~\LaTeX~ Code} \author{Jim Peterson\\ email: {\tt [email protected]} \date{\today}

A in the preamble of the document. This is the L TEX code that is typed prior to the line that begins

with \begin{document}.

Note on

A L TEX

by Jim Peterson

If we want to add table of contents for sections, gures and so forth, we use the code below placed right after the \maketitle command.
\newpage \tableofcontents % starts a new page % sets up table of contents

\addcontentsline{toc}{part}{Table Of Contents} % adds the TOC to the pdf hyperrefs \newpage \listoffigures % sets up a list of figures

\addcontentsline{toc}{part}{List Of Figures} % adds figures list to pdf hyperrefs

\lstlistoflistings

% sets of a list of code listings

\addcontentsline{toc}{part}{List Of Code Examples} % add code list to pdf hyperrefs \newpage

Next, we can layout a simple document using the article style. If you want to center and underline the section title, do this:
%\begin{center} %\section{\underline{INTRODUCTION}} %\end{center}

If you dont want to center the titles of the sections, just do this:
%No centering \section{\underline{INTRODUCTION}} \label{intro}

INTRODUCTION

Here you introduce the problem. What you are doing for this project.

Note on

A L TEX

by Jim Peterson

BACKGROUND

Here you talk about your problem, introduce whatever science and math are necessary to understand what is going on. Sort of like a tutorial or a lecture to bright, yet untrained in this area, colleagues. This can be split over several sections if required.

YOUR SPECIFIC TASK

What your task was and how you accomplished it. This can include theoretical development, algorithm development and software issues. This can be spread over several sections if necessary.

YOUR RESULTS

Discuss your accomplishments. Here is how you do a subsection: note we can move heading around using the \hspace command. \noindent \subsection{\hspace{.3in} Your Title Goes Here} \label{basic}

4.1

Your Title Goes Here

CONCLUSIONS

Your conclusions.

REFERENCES
1. D. Nguyen and Widrow, B., 1990, Neural Networks for Self-Learning Control Systems, IEEE Control Sys. Mag., Vol. 10, No. 3, pp. 18 23. 2. J. Peterson, 1992, On-line Estimation of Optimal Control Sequences: Pontryagin Estimators, in Intelligent Engineering Systems Through Articial Neural Networks, Pro-

Note on

A L TEX

by Jim Peterson

ceedings of the Articial Neural Networks in Engineering (ANNIE 92) Conference November, 1992, ed. C. Dagli, L. Burke and Y. Shin, ASME Press, pp. 579 584. 3. J. Peterson, 1993a, On-line Estimation of the Optimal Value Function: HJB Estimators, in Advances in Neural Information Processing Systems, 5, ed. S. Hanson, J. Cowan and C. Giles, Morgan Kaufmann Publishers, pp. 319 326.

APPENDICES

Note on

A L TEX

by Jim Peterson

8
8.1

A SAMPLE L TEX

Referencing A Paper:

A Here is L TEX code for referencing a paper:

According to ( Peterson ~\ref{peterson92a}), Dewey and Dagmar are doing a great job on their projects!

which compiles to:

According to ( Peterson ??), Dewey and Dagmar are doing a great job on their projects!

8.2

Some Math Equations:

A Here are some mathematical equations. Here is the L TEX code:

\begin{eqnarray} \begin{array}{cc} \min & \hat{J}(x,u,t)\\

u \in \cal U & \\ & \\ \end{array} \label{con11} \end{eqnarray}

\noindent where

\begin{eqnarray} \hat{J}(x,u,t) + \label{con11b} \end{eqnarray} &=& dist(y(t_f),\Gamma) \int_t^{t_f} \: {\cal L}( y(s),u(s),s) \: ds

\noindent Subject to:

Note on

A L TEX

by Jim Peterson

\begin{eqnarray} \label{con12} y^{\prime}(s) &=& f(y(s),u(s),s), \: \: \label{con13} y(t) \label{con14} y(s) &\in& {\cal Y}(s) \subseteq R^N, \: \: t \leq \: s \: \leq t_f\\ &=& x\\ t \leq \: s \: \leq t_f \\

\label{con15} u(s) &\in & U(s) \subseteq R^M, \: \: t \leq \: s \: \leq t_f

\end{eqnarray}

A Here is the L TEX output:

min uU

J(x, u, t) (1)

where

J(x, u, t) = dist(y(tf ), ) +
t

tf

L(y(s), u(s), s) ds

(2)

Subject to:

y (s) = f (y(s), u(s), s), t s tf y(t) = x y(s) Y(s) RN , t s tf u(s) U (s) RM , t s tf

(3) (4) (5) (6)

8.3

Embedding Mathematics and Referencing Equations:

A Here is L TEX code to handle embedded mathematics and referencing equations:

10

Note on

A L TEX

by Jim Peterson

Here $y$ and $u$ are the {\em state vector} and {\em control vector} of the system, respectively; $\cal U$ is the space of functions that the control must be chosen from during the minimization process and (~\ref{con13}) -(~\ref{con15}) give the initialization and constraint conditions that the state and control must satisfy. The set $\Gamma$ represents a target constraint set and $dist(y(t_f),\Gamma)$ indicates the distance from the final state $y(t_f)$ to the constraint set $\Gamma$.

A Here is the L TEX output:

Here y and u are the state vector and control vector of the system, respectively; U is the space of functions that the control must be chosen from during the minimization process and ( ??) ( ??) give the initialization and constraint conditions that the state and control must satisfy. The set represents a target constraint set and dist(y(tf ), ) indicates the distance from the nal state y(tf ) to the constraint set .

8.4

Setting Up a Table:

A Here is a L TEX code for a table and how it is referenced in the text:

\noindent A schematic of the learning algorithm for the network is given in Table ~\ref{criticlearn}; note that this training method is essentially a Gauss-Seidel procedure.

\begin{table}[hhh] \caption{Learning Algorithm} \begin{center} \begin{tabular}{cl} \\ 1 & $W_0 = 0$\\ 2 & $j=0$\\ 3 & $i=1$\\ 4 & 5 & Increment $j$\\ Set $W_j = W{j-1}$ \\

11

Note on

A L TEX

by Jim Peterson

6 & Input $y_i$, $\theta_i$ \\ 7 & Using the previous weights, $W_{j-1}$\\ & Calculate the desired target\\ & $D_i = \zeta {\phi}(W_{j-1},y_{i+1},\theta_{i+1}) +{\cal T}_{i}$\\ 8 & & Update the CMAC weights using gradient descent\\ to set ${\phi}(W_{j},y_i,\theta_i) = D_i$\\

9 & Increment $i$\\ 10 & If $i< \eta$ Go To (6)\\ & Else Continue\\

11 & If $W_j \neq W_{j-1}$ Go To (3)\\ & Else Continue\\

12 & Convergence\\ \end{tabular} \end{center} \label{criticlearn} \end{table}

A The L TEX output:

A schematic of the learning algorithm for the network is given in Table ??; note that this training method is essentially a Gauss-Seidel procedure.

8.5

Mathematics in a Enumerated Environment:

A Here, L TEX code to put math stu in an enumerated envoronment:

The CMAC architectures are used to construct predictions for each state variable using the temporal difference approach already outlined. We used the following $6$ temporal differences:

\begin{enumerate} \item $\sin(\alpha_c(t_i))-\sin(\alpha_c(t_{i-1}))$ \item $\cos(\alpha_c(t_i))-\cos(\alpha_c(t_{i-1}))$ \item $\sin(\alpha_t(t_i))-\sin(\alpha_t(t_{i-1}))$ \item $\sin(\alpha_t(t_i))-\sin(\alpha_t(t_{i-1}))$

12

Note on

A L TEX

by Jim Peterson

Table 1: Learning Algorithm

1 2 3 4 5 6 7

8 9 10 11 12

W0 = 0 j=0 i=1 Increment j Set Wj = W j 1 Input yi , i Using the previous weights, Wj1 Calculate the desired target Di = (Wj1 , yi+1 , i+1 ) + Ti Update the CMAC weights using gradient descent to set (Wj , yi , i ) = Di Increment i If i < Go To (6) Else Continue If Wj = Wj1 Go To (3) Else Continue Convergence

\item $x_c(t_i)-x_c(t_{i-1})/XSCALE$ \item $y_c(t_i)-y_c(t_{i-1})/YSCALE$ \end{enumerate}

A L TEX output:

The CMAC architectures are used to construct predictions for each state variable using the temporal dierence approach already outlined in earlier sections. We used the following 6 temporal dierences: 1. sin(c (ti )) sin(c (ti1 )) 2. cos(c (ti )) cos(c (ti1 )) 3. sin(t (ti )) sin(t (ti1 )) 4. sin(t (ti )) sin(t (ti1 )) 5. xc (ti ) xc (ti1 )/XSCALE 6. yc (ti ) yc (ti1 )/Y SCALE

13

Note on

A L TEX

by Jim Peterson

8.6

Another Table and How to Reference It:

A Here is L TEX code for another table with how to reference it. This table is a primitive attempt

to format an algorithm. The algorithm package does this better, but it is a bit hard to understand how to set it up, so for today, we will do it the simple way.
We will attempt to discuss generic software design issues, but we will use the truck backer-upper control problem as our framework so we can refer to concrete details when we need to do so. First, we look at a basic sketch of program flow as presented in

Table ~\ref{neurocontrolflow}.

\begin{table}[hhh] \caption{Neurocontrol Flow} \begin{center} \begin{tabular}{ll} \\ 1 & Set simulation parameters 2 & Set up CMAC architectures \\ \\

3 & Choose random truck start and control as state \\ 4 & i = 0 \\ 5 & Save state as sample i \\ 6 & Wait DATA\_FREQ time steps and store state\\ 7 & & & & & & & \hspace{.2in}If state lies in a new CMAC sensor, \\ \hspace{.4in} increment i\\

\hspace{.4in} save state as sample i of training set\\ \hspace{.4in} Compute next predicted optimal\\

\hspace{.6in} control using CMAC model\\ \hspace{.4in} If i $<$ num\_samples GoTo 6 \\ \hspace{.2in}Else, If i $<$ num\_samples GoTo 6 \\ \\

& Now have eta = num\_samples training samples 8 & For each output component d & & & \\

\hspace{.2in}For each input i, compute desired \\ \hspace{.4in} D = FUTURE\_WEIGHT*CMAC OUTPUT for input i \\ \hspace{.4in} + T for input i\\

9& Train CMAC to match I/O set \\ 10& Compute next predicted optimal control \\

14

Note on

A L TEX

by Jim Peterson

& \hspace{.2in} using CMAC model

\\

11& Save sample eta as state and GoTo 4 \end{tabular} \end{center} \label{neurocontrolflow} \end{table}

A L TEX output:

We will attempt to discuss generic software design issues, but we will use the truck backer-upper control problem as our framework so we can refer to concrete details when we need to do so. First, we look at a basic sketch of program ow as presented in Table ??. Table 2: Neurocontrol Flow 1 2 3 4 5 6 7 Set simulation parameters Set up CMAC architectures Choose random truck start and control as state i=0 Save state as sample i Wait DATA FREQ time steps and store state If state lies in a new CMAC sensor, increment i save state as sample i of training set Compute next predicted optimal control using CMAC model If i < num samples GoTo 6 Else, If i < num samples GoTo 6 Now have eta = num samples training samples For each output component d For each input i, compute desired D = FUTURE WEIGHT*CMAC OUTPUT for input i + T for input i Train CMAC to match I/O set Compute next predicted optimal control using CMAC model Save sample eta as state and GoTo 4

9 10 11

8.7

Inserting C Source Into The Document:

A Here is simple L TEX code I have used to insert source code into a paper. It uses macros from the

le setup.tex and the listings package. 15

Note on

A L TEX

by Jim Peterson

\mylistset{C++}{Setting Up A Parametric Study}% {$\;$ Setting Up A Parametric Study}% {run\_plot.c}{chh2runplot-d}% \begin{lstlisting} This macro takes five arguments: 1: C++ -- sets the source language 2: Comment which appears on top of source listing 3: $\;$ Comment which appears in Table of listings 4: Name of source file to appear on top of source listing 5: a label we can use to refer to the source code

code here

\end{lstlisting}

here is the LaTeX code to do the source listing:


\mylistset{C++}{Structures for a CMAC Artificial Neural Net}% {$\;$ CMAC Structures}% {Structure Fragment}{cmac-1}% \begin{lstlisting} struct cmacinput{ int training_set_size; int in_dimensions; int out_dimensions; float learning_rate; float *min_x; float *max_x; }; struct cmac{ int levels; int hash_value; float offset_value; float *width_value; float **offset; //the number of levels //hash value //offset = 1/levels //sensor width //store size of all offsets //the number of training samples //the dimension of the input space //the dimension of the output space //the learning rate used in training //lower bound for input components //upper bound for input components

float **receptive_field_width;

16

Note on

A L TEX

by Jim Peterson

//store size of all widths fhash hash; }; struct working_memory{ float **mem; }; \end{lstlisting} //working memory levels by hash_size //hash function

A Here is the L TEX output:

Listing 1: Structures for a CMAC Articial Neural Net


struct cmacinput { int t r a i n i n g s e t s i z e ; int i n d i m e n s i o n s ; int o u t d i m e n s i o n s ;
5

// t h e number o f t r a i n i n g s a m p l e s // t h e dimension o f t h e i n p u t s p a c e // t h e dimension o f t h e o u t p u t s p a c e // t h e l e a r n i n g r a t e used i n t r a i n i n g // l o w e r bound f o r i n p u t components // upper bound f o r i n p u t components

float learning rate ; f l o a t min x ; f l o a t max x ; }; struct cmac{

10

int l e v e l s ; int h a s h v a l u e ; float o f f s e t v a l u e ; float width value ; float o f f s e t ;

// t h e number o f l e v e l s // hash v a l u e // o f f s e t = 1/ l e v e l s // s e n s o r w i d t h // s t o r e s i z e o f a l l o f f s e t s

15

float r e c e p t i v e f i e l d w i d t h ; // s t o r e s i z e o f a l l w i d t h s f h a s h hash ; }; struct working memory { // hash f u n c t i o n

20

f l o a t mem ; };

// w o r k i n g memory l e v e l s by h a s h s i z e

17

Note on

A L TEX

by Jim Peterson

8.8

Putting A Graphics File Into The Document:

Heres how you embed a png le into the document. We use the macro \myincludegraphics for
A this. The L TEX source is

\begin{figure} \begin{center} %5.55in x 4.17in % \myincludegraphics{voltage0-99.png} {4.5in}{4.5in} \caption{Parametric Study of Action Potentials: $\overline{g}_{Na}$ ranges from $60$ to $180$ in $10$ and $\overline{g}_{K}$ ranges from $18$ to $54$ in $10$ uniform steps each. This gives a total of $100$ different Action Potentials. % name of your image file % width and height of image % caption you want to use

All of the currents were the response of the cell model to the synaptic pulse described in the text.} \label{chh2-AP} \end{center} \end{figure} % label for image

A L TEX output:

18

Note on

A L TEX

by Jim Peterson

Figure 1: Parametric Study of Action Potentials: g N a ranges from 60 to 180 in 10 and g K ranges from 18 to 54 in 10 uniform steps each. This gives a total of 100 dierent Action Potentials. All of the currents were the response of the cell model to the synaptic pulse described in the text.

19

You might also like