 \documentclass[11pt]{article}
\usepackage{ucs}
\usepackage[utf8]{inputenc} 
\usepackage[pdftex]{color,graphicx} 
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{ulem}
\usepackage{pdfsync}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\usepackage{listings}
\usepackage{synttree}
\usepackage{floatflt}
\usepackage{varioref}
\usepackage[pdftex]{hyperref}

% Listings style definition for algebraic specifications.
\lstdefinelanguage{algspec} 
{
	morekeywords={algebra, including, sort, sorts, op, ops, is, end, eq, var, vars, :, ->}, 
	sensitive=false
} 
% Slightly nicer XML printing than the default.
\lstdefinelanguage{DCXML}
{
	morecomment=[n][keywordstyle]{<}{\ },
	morecomment=[n][keywordstyle]{<}{\\},
	morecomment=[n][keywordstyle]{<}{>},
	morecomment=[n][keywordstyle]{<}{\	},	
	morestring=[b]',
	morestring=[b]"
}

% Some nice defaults for listings
\lstset{
	language=DCXML, 
	basicstyle=\tiny, 
	stringstyle=\textit, 
	keywordstyle=\textbf, 
	identifierstyle=\textit, 
	breaklines=true, 
	frame=shadowbox, 
	float=htbp, 
	xleftmargin=5pt, 
	xrightmargin=5pt
}

%Notes
\newcommand{\note}[1]{{\color{blue}\underline{Note: #1}}}
\newcommand{\chennote}[1]{{\color{red}\underline{Note: #1 - Chen}}}
\newcommand{\jonote}[1]{{\color{green}\uuline{The crazy girl says: #1}}}
%For final version, uncomment the following lines:
%\renewcommand{\note}[1]{}
%\renewcommand{\chennote}[1]{}



\title{\LaTeX{} Tips and Tricks}
\author{UWS CompSci Postgraduates}

\begin{document}
\maketitle
	
	\section{Notes}
	
		It's useful to be able to annotate your work. \note{Like this}  I define two commands for this.  This first is for me, and the second one is for Chen to use when I send him drafts \chennote{This paragraph is all wrong}.  The two commands are defined using this section:
		
		\begin{lstlisting}{language=[LaTeX]TeX}
\newcommand{\note}[1]{{\color{blue}\underline{Note: #1}}}
\newcommand{\chennote}[1]{{\color{red}\underline{Note: #1 - Chen}}}
%For final version, uncomment the following lines:
%\renewcommand{\note}[1]{}
%\renewcommand{\chennote}[1]{}		
		\end{lstlisting}
		
		The last two lines, when uncommented, instruct \LaTeX{} to ignore all of the text highlighted this way, allowing all notes to be quickly removed for a final (non-draft) version.  The underlining and colouring of the notes makes it easy to identify them in the typeset output.
		
	\section{Listings}
	
		A lot of people use the verbatim package for code listings, but this lacks a number of useful features such as automatic line wrapping and syntax highlighting.
		
		The listings package defines a number of environments for typesetting listings.  It is also relatively easy to add new languages.  The top of this file contains definitions of a slightly nicer way of highlighting XML than the default and a basic set of keywords for typesetting a sigma algebra (for all of the theory people).  
		
		The listings package includes a number of features.  Snippets of code can be inserted in a paragraph, blocks of code can be inserted such as the one below, and entire files can be included.  The last feature is particularly useful for large code listings - you can include an entire source file (or selected lines from a file) and not have to worry about keeping the original in sync with the document.
		
		\begin{lstlisting}[caption=An example of lstlistings, label=lst:bool, language=algspec, literate={->}{$\rightarrow$}1]
Algebra Bool is

    sort Bool
    
    ops TT FF : -> Bool
	op and : Bool Bool -> Bool
	...

	var A, B : Bool
	
	eq and(TT,TT) -> TT
	eq and(B,FF) -> TT
	eq and(A,B) -> and(B,A)
	...
	
end Algebra
		\end{lstlisting}
		
		Listing \ref{lst:bool} shows an example algebra (a simplified version of the booleans) typeset using the listings package.  Note the use of the literare option to replace $->$ with a right arrow.

		
	\section{Makefiles}
		\label{sec:makefiles}
		As with any large project, a \LaTeX{} document often has many dependencies.  Make is an invaluable tool for keeping everything up to date.
	
		\begin{lstlisting}[caption=An example Makefile, label=lst:make]{language=[gnu]make}
Paper.pdf: Paper.tex pdfgraphs figures/Figure1.pdf Paper.bbl
        pdflatex Paper.tex

Paper.bbl: Paper.aux
        bibtex Paper

Paper.aux: Paper.tex
        pdflatex Paper.tex

pdfgraphs: 
        cd plots && make

view: Paper.pdf
        open Paper.pdf || xpdf Paper.pdf


clean:
        rm *.aux *.bbl *.dvi *.blg *.log *.out *.pdf > /dev/null 2>&1
        cd plots && make clean

vimclean:
        rm *~ *.bak > /dev/null 2>&1
        cd plots && make vimclean

check:
        aspell -t check Paper.tex
		\end{lstlisting}
		
		Listing \ref{lst:make} shows a simple Makefile that could be used for a paper.  It assumes that gnuplot is being used to generate plots using a separate Makefile in the plots/ subdirectory.  Running \texttt{make view} will open the output in the default viewer (on OpenStep / Mac OS X) or xpdf on *nix.  Running \texttt{make check} will spellcheck the document using aspell, which ignores \LaTeX{} markup.
		
	\section{I want to be a tree!}

		 \begin{floatingfigure}{6cm}
			\centering
			{
				\synttree[a [b [[c] [d]] [e]] [f] [g] [{h i j}]]
			}
			\caption{An example tree generated with the synttree package \label{fig:tree}}
		\end{floatingfigure}

		Drawing trees can be done simply using the synttree package.  This takes a nested square-bracketed expression and converts it into a tree.  There are other packages, such as xyfig, that give a more flexible way of generating directed graphs, but for simple trees the synttree package is very convenient.  It is particularly useful for trees generated programmatically; the syntax is simple and so it is very easy to automatically generate.  
		
		Incidentally, the floating figure to the right of this paragraph was generated by the floatflt package, which provides analogues of the standard floating environments with text wrapped around them.
		
		The tree in Figure \ref{fig:tree} was generated using this line of code:
		
		\begin{verbatim}
		
		\synttree[a [b [[c] [d]] [e]] [f] [g] [{h i j}]]
		\end{verbatim}
		
		
		Each sub-tree is represented by a node name followed by a list of sub-trees in square brackets.  Note that node names which contain spaces must be wrapped in braces.
		
		\section{Declaring Macros}
		
			As seen in the Notes section, declaring a macro is very easy using \verb|\newcommand|.  If there is a word or phrase you use often, then it can be convenient to declare a simple macro to use instead.  This is particularly useful when you are unsure of the correct capitalisation of a phrase, or when it includes some \LaTeX markup.
		
		\section{Graphics in \LaTeX{} and pdf\LaTeX{}}
			
			
			\begin{floatingfigure}{3cm}
				\centering
				{
					\includegraphics[clip=true,trim=2cm 2cm 2cm 2cm,width=3cm]{images/unilogo}
				}
				\caption{An \textsc{eps} figure in a \textsc{pdf} document.\label{fig:eps}}
			\end{floatingfigure}

			\LaTeX{} allows the inclusion of \textsc{eps} images.  pdf\LaTeX{} allows the inclusion of more or less anything except \textsc{eps} images.  The epstopdf package allows you to incorporate \textsc{eps} images into pdf\LaTeX{} documents.  Another option is to use the \verb|\DeclareGraphicsRule| command to define external programs to be be used to convert images between formats.
			
			The \verb|\includegraphics| command has some other nice features, such as the ability to crop an image.  The \verb|trim| attribute is used Figure \ref{fig:eps} to trim 2cm off each side of the university logo.  This can be particularly useful when you have an image that has a large border.  GNUplot is particularly bad about cropping its output, and trimming 15mm or so from each side can save you a lot of space in a document.  
			
		\section{Small Capitals}
			
			If you have a lot of text then from a distance, the page should look a constant shade of grey.  If you write WORDS IN CAPITALS, THEN THEY LOOK MORE BLACK.  To counter this, you can use the \verb|\textsc| command \textsc{to make small caps, which have the same size (and hence the same grey value) as lower case letters}.
			
			%\jonote{blah blah blah, onions, garlic, my children need wine!  Everything looks grey apparentely.  I stopped listening a while ago.  Anyway, which is why I personally like to use small capitals instead of normal capitals.  The problem with normal capitals in France is that we have no word for entrepreneur.  I'm going to f*cking bury the french.  I've done it before and I'll do it again.}
			
		\section{Hyperlinks and References}
			\label{sec:hyperref}
			The hyperref package allows you to insert hyperlinks in a document using the \verb|\href| and \verb|\url| commands.  The former allows you to associate a link with some text; \href{http://cs.swan.ac.uk}{this text links to the departmental web site, for example}.  If you just wish to insert a URL, then the latter allows you to do, like this:\url{http://cs.swan.ac.uk}
			
			Other advantages of the hyperref package is that it automatically turns references (including those pointing to the bibliography) into links inside the document when generating \textsc{pdf} or \textsc{html} output.  This lets you easily check that all of your references point at the correct things simply by clicking on them, as long as you are using a \textsc{pdf} viewer that supports hyperlinks.
			
		\section{Friendly References}
		
			Generic references (\verb|\ref|) in \LaTeX{} are useful for cross-referencing.  They give a figure or a section number, allowing you to write things like Figure \ref{fig:eps}, and have it update depending on which number this figure actually has.
			
			Sometimes it is nicer to be able to put a slightly more human-friendly reference, something like the 'on the last page,' or 'above.'  Unfortunately, such things can become inaccurate when the document is modified and typeset again.  The solution to this is the \verb|varioref| package, which adds a little extra information.  It can generate the forms of output shown in Table \vref{tbl:varioref}
			
			\begin{table}[htdp]
				\caption{Output from the varioref package}
				\footnotesize
				\centering
				\begin{tabular}{|c|c|}
					\hline
					\LaTeX & Output \\ \hline \hline
					\verb|the figure on page \pageref{fig:eps}| & the figure on page \pageref{fig:eps} \\ \hline
					\verb|Figure \ref{fig:eps}| & Figure \ref{fig:eps} \\ \hline
					\verb|Figure \vref{fig:eps}| & Figure \vref{fig:eps} \\ \hline
					\verb|the figure \vpageref{fig:eps}| & the figure \vpageref{fig:eps} \\ \hline
					\verb|Sections \vrefrange{sec:makefiles}{sec:hyperref}| & Sections \vrefrange{sec:makefiles}{sec:hyperref} \\ \hline
					\verb| \vpagerefrange{sec:makefiles}{sec:hyperref}| & Sections \vpagerefrange{sec:makefiles}{sec:hyperref} \\ \hline
				\end{tabular}
				\label{tbl:varioref}
			\end{table}%

			
		\section{HTML Output}
		
			The \verb|tex4ht| program is a good way of generating HTML output.  It provides a large number of options, and supports a significant number of \LaTeX{} packages.  This is not always useful for papers, but for some other contexts it can be useful to make a version of your work available for browsing on the web as well as in printed form.  If this is the case then many users find browsing a set of \textsc{html} pages nicer than reading a \textsc{pdf} document.
			
			During the conversion process, a large document is usually broken up into smaller \textsc{html} pages, allowing downloads to take place much more quickly.

\end{document} 