Monday, November 7, 2011

Free the research #2

Ok, this is the third part of the serie about doing scientific research with GNU/Linux, and we are gonna talk about Latex (not the material.... ok, stop laughing now).
Reports? Use Latex
Website: http://kile.sourceforge.net/
What is Latex (http://en.wikipedia.org/wiki/LaTeX)? It's a metalanguage, like html, and helps us to paginate our documents. Basically, we say to Latex what we want to write, wich images or tables should be inserted into the document, and it will prepare the layout automatically, using common sense. Since an example is better than a thousand words, let's see one immediately.
First of all we need to install an editor for Latex: one of the best choices is Kile (at least the version 2.1). Anyway, every other editor is fine. So, open your editor and create a new document: in Kile, there is a wizard that helps you choosing the main settings. Once you have a document ready, try writing these lines:
\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\title{Synthesis of Ala-Leu-OMe}
\author{Tringali Luca}
\begin{document}
\maketitle
\begin{abstract}
Reaction between Boc-L-Ala-OH and Leu-OMe to obtain Ala-Leu-OMe
\end{abstract}
\section{Mechanism of reaction}
\includegraphics[width=130mm]{meccanismo.png}
\section{Experimental procedure}
First of all, in a flask for 100 ml, insert 0.5 g of Boc-L-Ala-OH and 10 ml of CH$_{2}$Cl (suitable for synthesis of peptides) saturating the flask with Argon. Bla bla bla... At the end of the reaction, register the $^{13}$C NMR spectrum.
\end{document}
Please note that, before trying to compile the document, you will need to put a file called "meccanismo.png" in the same folder of the .tex file (Latex documents have ".tex" extension). You can take the image from here, if you want: https://picasaweb.google.com/109718345247929494628/Varie?authkey=Gv1sRgCKiUi4a9jZCcYA#5688945887642836658.
Now, give a look at the Latex code: the first line specifies that we are going to write an article, with A4 pages, and a font size of 10 points. The package "graphicx" allows you to include graphical objects, like images. The two following lines, instead, load a complete set of characters (useful if you are writing in italian, for example, and you need accented letters). The "title" tag specifies the title of the document (who would have thought?), while the "author" tag contains the naem of the author(s). Then, the document begins, and we immediately ask Latex to prepare the title. Under the title we put the abstract: it's a phrase that should sum up the purpose of the document. It's possible to create sections, useful to organize the document in a better way. An image can be included using the tag "includegraphics", and we can also specify the dimensions between brackets. Obiusly, the image should stay into the same folder of the document (if it's in another place we must specify the whole path).
Maybe you need to write some text in superscript or subscript: simply use the ^ or the _ simbol. Anyway, it's considered "mathematical notation", so you need to include the whole super/subscript part in $ (and the text should be clsoed into braces). For example, "$_{2}$" means that we will have the number 2 written as subscript. And "$x^{1-n}$" will write the "1-n" text as superscript. In GNU/Linux you can simply write braces using the composition button of you keyboard (usually it's "Alt Gr", on the right of the spacebar) and the number 7 or 0. It's better if you don't use the numeric keypad.


Kile makes it easy
Obiously, the purpose of Kile is to make easy the use of Latex, so you don't need to remember the language syntax. For example, if we want to add an image, just click on the menĂ¹ Latex/ImageInsertion. It's also possible to use toolbars, and set them to have al the things we can need handy (menĂ¹ Settings/Toolbars shown, or Settings/Configure Toolbars). Using the button QuickBuild we will obtain a PDF file, but it's also possible to save the file in other formats. 
If we want to prepare images to insert in the document (for example schemes), there's a program called Cirkuit (http://wwwu.uni-klu.ac.at/magostin/cirkuit.html) very useful to draw professional images.
Obiously, if we are not writing for the Nobel commission, we can also use the good old Inkscape to draw everything we want, and maybe add some notes over photos (for example, add some texts to describe the photo of an instrument tool).

5 comments:

  1. Do you have to tell anybody in research to use LaTeX? I don't think so. :D

    However, LaTeX seems to be kinda outdated, try LuaLaTeX, it supports all LaTeX features but has built in Unicode and scripting support. Ever tried to write a complex macro in plain LaTeX? That is just terrible.

    ReplyDelete
  2. Well, maybe researchers know Latex, but many students still use programs like Microsoft Word to write laboratory reports.

    ReplyDelete
  3. It may be a good idea to add to your introduction some links to good tutorials on LaTeX:
    http://www.eng.cam.ac.uk/help/tpl/textprocessing/ltxprimer-1.0.pdf
    http://en.wikibooks.org/wiki/LaTeX
    and some useful documents:
    http://texcatalogue.sarovar.org/bytopic.html
    http://mirror.ctan.org/info/symbols/comprehensive/symbols-a4.pdf
    http://amath.colorado.edu/documentation/LaTeX/Symbols.pdf
    and many others (but choose a few good ones in order to not overload people with too much information).

    ReplyDelete
  4. @glad: Thank you, in the original article I added some tutorials, but they are written in Italian, so I didn't linked them in this post.

    ReplyDelete
  5. Well, it probably also depends on the university, field etc. I have also heard about students at another university to be forced to use .doc-files. However, in my field seminar papers, thesises, lecture notes etc. are always created with TeX, for presentations it depends.

    ReplyDelete