Wednesday, September 29, 2010

School Of Maths - Thesis Template

The school of maths provides a class file and thesis template which can be found on the school website (restricted access):-
Templates

Open both files with the editor/IDE of your choice. Notice that the muthesis.cls contains information both about how the file works, and the required structure of your thesis. Build and view the file, you should have the beginnings of a thesis! In this short tutorial, we shall go through how to create a table, import graphics and use bibtex for your bibliography.

Tables

Your thesis is likely to include tables of one sort or another. A table in latex is a float, that means it can have a caption, a label, can appear in the table of contents, and will be placed by latex within the text in order to make the document look nice.

In order to create a table, we need to know about the tabular environment. An example of a simple tabular environment is:

\begin{tabular}{c|r}
1  &  2  \\
\hline
three  & four
\end{tabular}

and the output is:


The arguments after \begin{tabular} specifies the number of columns, the justification, and any vertical lines between columns. For instance writing {c||rrr} makes one centered column, two vertical lines followed by three right justified columns. Inside the environment individual cells are separated with an ampersand (&) and the row is ended with the end line command double backslash. We can use the command \hline to give a horizontal line.

Now to make a table, we must include the tabular environment inside the table environment. An example follows:
\begin{table} % start table environment
\begin{center} % center the table and caption
% build the table
\begin{tabular}{c|ccc}
 & \multicolumn{3}{c}{Attendance at Course} \\
 Week & MATH10121 & MATH10212 & MATH10222 \\
\hline
1 & 234 & 157 & 153 \\
2 & 223 & 167 & 148 \\
3 & 227 & 129 & 133 \\
4 & 236 & 134 & 113 \\
5 & 212 & 127 & 101 
\end{tabular}
\caption{My table showing preparations times} % caption for the table (gives it a number)
\label{tab:myTable}
\end{center}
\end{table}
and the output is:
Including Graphics

In latex documents there are two ways to import graphics into your documents, depending on your required needs. If you are to be including technical plots, then encapsulated postscript graphics give the best looking results, and also allow latex to substitute text in your figures for typeset text. This can be particularly useful when you want equations or greek text in your figures. In order to use eps graphics and produce pdf's, you need to enable your IDE to run "LaTex -> DVI -> PS -> PDF". There are instructions on how to do this with kile or teXnicCenter elsewhere on this blog.

First let us try to import some simple graphics in png or jpg format. Go to the web and download a picture in jpg or png format, and save it in the same folder as your tex file. Now change your build profile to "LaTex => PDF", and include the following line after documentclass but before begin document:
\usepackage{graphicx}
Somewhere inside the document, maybe inside the introduction, include the line
\includegraphics[width=0.5\textwidth]{filename.jpg}
Now build and view the file, the picture should appear in the document. If you are having problems check that you have the usepackage command in the right place, and that you have the correct build profile.

Next we wish to make a figure. Like the table environment, a figure environment is a float, which means that latex will choose exactly where the figure will appear in the document, although you do have some control. Now try to place your picture inside a figure, with a caption and a label.
\begin{figure} % start the figure environment
\begin{center} % center the graphics and caption
% include the graphics
\includegraphics[width=0.5\textwidth]{help-my-dogs-as-fat-as-me.jpg}
\caption{A fat dog} % caption for the picture
\label{fig:fatDog}
\end{center}
\end{figure}
the output from this is:
Notice that because I have included the figure in chapter 2, the reference number for the figure gives the chapter number then the position in that chapter. It is possible to change this behaviour if you wanted to.

EPS Graphics and PSFrag

Now let us give an example of including eps graphics. Remove any statements that reference any jpg or png pictures. Now download the eps example figure from my website:
http://www.maths.manchester.ac.uk/~pjohnson/Latex/Figures/
Include the following line after documentclass but before begin document:
\usepackage{psfrag}
and change your build profile to "Latex -> PS -> PDF". Now enter the following:
\begin{figure} % start the figure environment
\begin{center} % center the graphics and caption
% setup psfrag
\psfrag{x}[][]{$\eta$}
\psfrag{y}[][]{$f(\eta)$}
\psfrag{f(x)=sin(x)/x}[][]{$f(\eta) = \frac{\sin(\eta)}{\eta}$}
% include the graphics
\includegraphics[width=0.75\textwidth]{example-figure.eps}
\caption{A figure using psfrag.} % caption for the picture
\label{fig:sinxoverx}
\end{center}
\end{figure} 
and the output is:




Bibliography

You may wish to use bibtex to cite articles in your thesis. This is useful because it generates your bibliography automatically. To do this, create a new file called "myBibFile.bib" and save it in the same directory as your thesis file. Open the file and enter:

@article{einstein1935can,
  title={{Can quantum-mechanical description of physical reality be considered complete?}},
  author={Einstein, A. and Podolsky, B. and Rosen, N. and others},
  journal={Physical review},
  volume={47},
  number={10},
  pages={777--780},
  year={1935},
  publisher={APS}
}
Note that from google scholar you can set it up to import citations into bibtex format. Here einstein1935can is the reference keyword for this citation. First place the following underneath your package list:
\bibliographystyle{plain}
and then edit the part for the bibliography to read
\bibliography{myBibFile}
% 
% \begin{thebibliography}{999}
% \bibitem{ANO} A.N.~Other, ....
% \end{thebibliography}
This should enable the bib file in your document. Now you just need to cite the text so that it will be included in your text:
Einstein showed in his paper \cite{einstein1935can} that ...
You can add as many reference as you like to your bib file, only those that are referenced within the text of your thesis will show up in the bibliography.

Tuesday, September 28, 2010

Texnic Center:- Latex -> Ps -> Pdf

To get TeXnicCenter to create pdf documents via ps files (required for psfrag, pstricks, eps graphics), you need to edit the profiles. From the main toolbar select "Build->Define Output Profiles...". Now select the profile "LaTex => PS", and press "copy", at the dialog change the name to "LaTex => PS => PDF".

Select the newly created profile, and click the tab "PostProcessor". Press the "new" button (a dashed square) to create a new postprocessor and call it ps2pdf. For the executable option, press the search box to the right and find the executable named ps2pdf on your system. You should find it in the directory
"C:\Program Files\MiKTeX 2.8\miktex\bin\ps2pdf"
or somewhere like that (depending on where program files are stored).

For the arguments box, enter
"%bm.ps"
including the quotes (very important).

Now select the "Viewer" tab. Under "Path of Executable" you can enter the path to adobe acrobat reader, if it is installed on your system and you can find it. On mine it is
"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32"

For the arguments box, enter
"%bm.pdf"
including the quotes (very important).


Now select the profile from the main toolbar, build from "Build->Current File->build", and view the file from "Build->View Output"


Installing MikTex and TexnicCenter on windows

This is a simple guide on how to install MikTex and TexnicCenter on windows machines to create beautiful typeset documents. First go to the MikTex homepage:
http://miktex.org/2.8/setup
and select to download the basic MikTex system.

Once the file has downloaded, run it and accept all of the default conditions. The program should begin installing...

Once MikTex is installed, we can move on to installing TeXnicCenter. Go to
http://www.texniccenter.org/
and download and run the installer. Again, just accept the default conditions.

Now when you start TeXnic for the first time you will be presented with setup wizard. In order for it to work you MUST tell texnic WHERE on your computer latex is installed.

Press on the box to search for the correct directory on your system. If you accepted the default settings on your MikTex installation the directory should be something like:
"C:\Program Files\MikTex 2.8\miktex\bin"
Once you have found the correct directory press next. It will not allow you to continue unless you have found the correct directory.

At the next screen you may choose a viewer for postscript files. You will need to install ghostscript if you want to view ps files. You can skip this step.

At the next screen you have the option to specify a pdf viewer. If you have adobe acrobat installed on your system you may choose it by searching for it. On my system I can find the executable at:
"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32"
Accept your settings and you should now be good to go! Open a new fie and try to compile and view the document.

If you need to convert to pdf via ps see the next turorial.


Tuesday, September 21, 2010

Using kile On School/Faculty Unix Machines

A Simple Latex File

Tex is a computer program that can typeset text and mathematical formulae. Latex is a markup language that uses tex as its typesetting engine. Basically this allows the user to embed commands within a text file that can be interpreted by latex to produce a high quality typeset documents. Kile is a latex integrated development environment (IDE), that means that you can both edit text files and produce typeset documents all in one program, it is available for free as part of any linux distribution. As it is written in Qt it is also available on windows. The interface is similar to that found on windows based IDEs, so learning latex on unix should be the same as learning it on windows.

Open up the program 'kile' from the menu bar. If you cannot find it open a terminal and type 'kile' followed by a return carriage. Once the program has opened, go the file menu and select new. At first select empty document, you can try using the wizard or standard templates at a later date.

Latex commands are always preceded by a backslash, there are predefined commands and the user may also specify their own. There is also a certain structure that must be adhered to. Two of the most common commands are \begin{} and \end{}, that signify the start and end of an environment. Like a good story all latex files need a start and an end, and the document environment signifies the start and end of a document, so all files require \begin{document} and \end{document}. The other requirement is some information about the structure of the document that you are creating. This information must be presented in the preamble (before \begin{document}) with the \documentclass{} command. There are certain default options that can be used, article is a popular choice. For the most simple of latex files enter the following text:

\documentclass{article}

\begin{document}
Some text...
\end{document}
and then save the file in a new directory. Call the file something like "test.tex", with the file ending ".tex".

Once the "tex" has been written, it must be compiled in order to generate a file that can be printed or viewed on screen. A standard file type to convert to is pdf. There are at least 2 ways to generate a pdf, one is to go directly from the latex file to a pdf (using the latexpdf command) or and another is by converting from tex->dvi->ps->pdf. Obviously the second method sounds more cumbersome but if you want to use packages such as pstricks or psfrag to make your document look nice you must use the second method. Luckily kile has a "QuickBuild" option that can run multiple latex commands in one go. Go to Settings->Configure kile and select Tools->Build->QuickBuild, then select Latex->DVItoPS->PStoPDF->ViewPDF from the configuration options. You may need to change the configuration of ViewPDF to acroread.

Now press quick build to preview your latex document...

Monday, September 20, 2010

Unix - Changing Your Password

Logging in for the first time

At the login  screen there is a session menu that allows one to choose the desktop environment. Popular choices for the linux desktop are the 'gnome' or 'kde' desktop environments. If you are familiar with windows 'kde' probably offers an experience most similar to what you are used to. The university linux image has both available, there is not much difference between them (they both have the same set of applications available) but you might prefer the look and feel of one over the other.

Once you have chosen your favourite desktop environment, simply enter your username and password into the appropriate boxes.


Changing your default password

The first task you must complete in order to use the school unix system is to change your default password. The first task is to open a terminal. In the gnome environment (default) there should be a icon in the panel at the top or the bottom. Otherwise it can be found in the menu under 'system tools'.


Now you must enter the command to change your password into the terminal. Simply click onto the terminal and type 'passwd'. You will now be asked to enter your old password (for security reasons), followed by your new password twice. Do not worry if you do not see characters appearing as you type the passwords, they are not meant to appear! If you have entered your new password correctly you will see
 The NIS password has been changed on babbage.ma.man.ac.uk

If there have been any problems, such as the passwords not matching, you will be notified. Once you have changed your password why not try to set up your webpage? Follow the instructions here.

School of Mathematics - Making Your Webpage

Creating a simple webpage

The idea of this tutorial is to make a simple web page using the terminal and some simple unix commands (most of which could also be done through a GUI). You should at the end be able to post links to your academic works, photo's and other files. Since the school website (along many other websites) runs on unix, you will need to know something about unix filesystems to run your website. It is assumed that you have already logged into the the school unix system and changed your password.

Creating an "index.html" file

The first task is to create a folder in which to store your website files. Open a terminal, and enter the following command to create a folder:
mkdir public_html
Check that the folder has been created in the correct place, by entering the command
ls ~
The directory "public_html" should be listed on screen.

Next we need to create an "index.html" file for our webpage. This file will describe the main page of your website. Enter the following command into a terminal:
emacs ~/public_html/index.html

This will open an empty file that can be edited. Enter the following code into the editor:
<html>
<body>
<h1> My webpage works!!! </h1>

<p> I can hardly believe it!?!</p>

</body>
</html>
Save the file and exit. Now open a web browser and enter the following address into the navigation bar (adjusting username for your unix username):
http://www.maths.manchester.ac.uk/~username
and you should see something like the following...


See further posts for more about "html" and how to post links and images.

Making Your webpage - Part II

Simple html commands

HTML, or HyperText Markup Language, is the language used on the web. It is a markup language, which basically means that the structure and appearance of a page can be encoded into a simple text file using tags (text surrounded by angle brackets). These tags may take the form of simple commands such as 'put a hyper link here', or 'put an image here', but can also be used to call scripting languages such as javascript. In this tutorial we shall just go the most basic commands, those for hyper links and images, and general structure of a web page.

Previous example

In the last entry we went through setting up a simple index file for your website. But what did each of the parts mean? Let us look through each line in turn.

  • Line 1: <html> This basically tells the computer that what follows is an HTML file.
  • Line 2: <body> What follows is the main body of the text, i.e. not header or footer.
  • Line 3: <h1> My Webpage Works!!!</h1> Text enclosed inside h1 tags will be displayed as a title, appearing in a font much larger that normal text.
  • Line 5: <p> I can... </p> Text enclosed inside p tags shall denote a paragraph.
  • Line 7: </body> The main body of the text has finished.
  • Line 8: </html> The HTML file has finished. Ignore subsequent text.
Note that every time a <tag> is started, it must be finished with </tag>.

Another Web Page

The 'index.html' page is used as the default page for a website. You can have as many separate webpages as you like inside your website, as long as you can present links to them!

Open a terminal and enter the following:

emacs ~/public_html/anotherpage.html
and copy the HTML code from the index.html file across to this new file. Edit it slightly so that you can tell it is different from the original, then save and exit.

Now reopen the original index.html file. Add the following line within the body of the text:

<a href="anotherpage"> Link to another page </a>

Reload your webpage and the link should appear underlined. Check that it is working.

Upload An Image

Now we may want to include a picture on our website. First we need to get a picture, then we need to place it somewhere that the world wide web can find it. Download a picture off the web, and save it to your hard disk. Locate the file and copy it to the public_html directory. Reopen the original index.html file and add the following line within the body of the text (changing for the appropriate file name, my example is 'dog.jpg')

<img src="dog.jpg" class="picture">
Reload your webpage and the image should appear.

Using Directories

You can also use directories to store files inside your web space. Try making a directory and store the your picture inside it using the terminal.

mkdir ~/public_html/myPictures
mv ~/public_html/dog.jpg ~/public_html/myPictures
Now change the line containing the img tag to now be the path to the file. For my example it would be:
<img src="myPictures/dog.jpg" class="picture">
Reload your webpage and check the image still appears. If you have lot's of directories and files things can get confusing since the src must define the path from your current directory to the directory containing the file. One way to circumvent this is to use the absolute path, much in the same way all of the terminal commands use ~/pathToFile so that they work regardless of your current directory. For my example on my website I would enter:
<img src="http://www.maths.manchester.ac.uk/~pjohnson/myPictures/dog.jpg" class="picture">

Restricting Access

As discussed in the lecture the unix filesystem provides a restrictions on the access of a file. Any file placed inside your public_html directory shall be open for the general public to view by default. The way to restrict access is by changing the file permissions. Try restricting access to the picture that you have created. First, from the terminal, navigate to the directory containing your picture. The commands will look like:

cd
cd public_html
cd myPictures
Then change the rwx access for 'other' users with the command:
chmod o-rwx dog.jpg
Reload your webpage and check the image should not load anymore. You may need to reload the page to refresh the cache. See if you can use the terminal to restore access to the file.

Using Dynamic Links

There may be instances where you want not to copy a file into your webspace, but access a file from somewhere else on your system. Rather than having multiple copies of the same file, we can get round this by using dynamic links (much like shortcuts on windows) to 'point' to a file in a different directory. Say I have a presentation file pres.pdf in the directory /home/pjohnson/presentations/pres.pdf. I want the latest version available on the web, and I will be updating the file regularly so don't want to copy it. I can create a 'link' to the file using the command:

ln -s ~/presentations/pres.pdf ~/public_html/pres.pdf
The '-s' denotes a soft link. This means that because it is not a copy, nor is it a hard link, deleting the link will not delete the original file. Download a presentation off my website and store it on your filesystem. Create a link to the file in your public_html directory and create a hyper reference to the file on your webpage. PDF files can be linked using the code:
<a href="pres.pdf" class="pdf">A Presentation</a>