meta data for this page
  •  

This is an old revision of the document!


Back to the #itlab main page

Documents

Good documents about LaTeX basics.

Templates

A wide variety of templates are provided by itlab / MVPR:

Required Packages

In Ubuntu, you need to install the minimum Latex environment (Master's Thesis template requirements):

apt-get install texlive-latex-base texlive-latex-extra gnuplot texlive-fonts-recommended

Or just install everything:

apt-get install texlive-full

Tips

Markerless Footnote

Adding footnote without a marker: http://help-csli.stanford.edu/tex/latex-footnotes.shtml

First define in the beginning of a document

\long\def\symbolfootnote[#1]#2{begingroup%
\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup}

To use the footnote:

\symbolfootnote[0]{footnote}

Other symbols can be used if 0 is replaced with 1…?

Honouring Boundingbox in EPS

If you have an Encapsulated PostScript file gotten from somewhere, you might want to change the “viewport” or the area that is used in your document. You have to do two things:

  • edit the code of the EPS file, change the %%BoundingBox values to your liking. You can check the right values with the cursor while viewing the image in gv. The format is: X-left Y-lower X-right Y-upper.
  • In the LaTeX code, instead of includegraphics, use includegraphics* (note the star). You can also rotate the image with LaTeX.

CVS keywords in text

There is a package called rcs, but you can also do without: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=RCS Put this somewhere early in your .tex:

\def\RCS$#1: #2 ${\expandafter\def\csname RCS#1\endcsname{#2}}

Then you can use e.g.

\RCS$Date: 2007/01/29 16:30:15 $
\date{\RCSDate{} UTC}
\maketitle

and the title will include the date of the last CVS commit. CVS will update the string between $'s automatically.

Review comments in the text as footnotes

\usepackage{color}
\newcommand\newnotecommand[3]{%
  \newcommand#1[1]{{\color{#3}\footnote{{\color{#3}#2:} ##1}}}}
\newnotecommand\pq{pq}{red}
\newnotecommand\joni{Joni}{blue}

The command \newnotecommand declares a note command by name, using arguments for nick and color. Usage in text:

   and is thus proved.\joni{viite?} This concludes

Move figures and tables to the end of the document

Some journals want all the figures and tables to be located at the end of the document. This can be accomplished by loading endfloat.sty:

\usepackage{endfloat}

Approximate locations of the figures without endfloat.sty are marked within the text in square brackets.

Gnuplot

Gnuplot is a nice program that can not only plot data but also fit functions etc.

An example gnuplot script, that reads data from file paksuus.dat:

#!/usr/bin/gnuplot

set encoding iso_8859_1
set terminal postscript eps enhanced mono "Helvetica" 14
set out 'paksuus.eps'
set size 0.9, 0.9

set title "Värähdysajan riippuvuus tangon halkaisijasta"
set xlabel "d/mm"
set ylabel "T/ms"
set autoscale
set xrange [[2:9]]
set grid xtics ytics
plot "paksuus.dat" using 1:(2*$2) notitle with points

and the data file could look like this:

8.0 59.2
6.0 79.5
5.0 89.8
4.0 115.9
3.0 151.3

You can also set terminal to latex so that gnuplot generates the figure as LaTeX code, but it will need configuring to get it to look nice. There is also pdf output format, but postscript output is more advanced and nicer to work with with black and white figures.

Here is a more complex example that fits a line to computed values and draws them:

#!/usr/bin/gnuplot

set encoding iso_8859_1
set out 'kerroin.eps'
set terminal postscript eps enhanced mono "Helvetica" 14
set size 0.9, 0.9

r = 7.9e3
E = 200e9
l = 0.800

f(d) = l*l * sqrt(r/E) / d

g(x) = a*x + b
fit g(x) "paksuus.dat" using (f($1/1000)*1000):(2*$2) via a, b

set xlabel "f(d)/ms"
set ylabel "T/ms"
set autoscale
  - set xrange [[2:9]]
set grid xtics ytics
plot "paksuus.dat" using (f($1/1000)*1000):(2*$2) notitle with points, 
        g(x) notitle with line

Links to gnuplot resources:

Using pixel images

Vector graphics is easy, no need think about resolution, if you can keep it in vector format. EPS is just fine for that. Sometimes you want to use pixel based images, like photographs, in a LaTeX document. To avoid creating huge files, and EPS format tends to be verbose, you have to think about image resolution.

You should estimate the physical size of the image in millimeters when it is printed on paper. Use it to compute the number of pixels by multiplying with pixels-per-millimeter resolution. Printer resolutions are usually in dots-per-inch, and the relationship between a dot and a pixel is not straightforward, so a little math is required.

There is a script that can automatically convert a pixel image to an EPS image and do the required scaling. The script can be found in the CVS, itlab/utils/pix2eps, or http://www.iki.fi/pq/htyot/textemplate/pix2eps . You can give the image maximum dimensions in millimeters or maximum width in percents of textwidth, assuming the standard M.Sc. thesis page format. Optionally the script converts the image to gray scale.

Latex compilation using Makefile

There is a nicely working Makefile (zipped due to Wiki restrictions for the file extensions) written in the laboratory. Just add your document without extension to TARGET variable and say

  make view

Alternative option is to use the ready packages provided for Ubuntu, for example latex-make or latex-mk. Include the rules into your Makefile and that's it, for example (Ubuntu 11.10 with latexlive and latex-mk):

NAME= report
TEXSRCS= report.tex
BIBTEXSRCS= report.bib
 
include LaTeX.mk

Migration to ''texi2pdf''

Texi2pdf is similar to texi2dvi, but instead of DVI it produces directly PDF output. This avoids using PostScript as an intermediate format, allowing e.g. url{} commands to work better when the URL needs a line break.

Texi2pdf uses pdf(la)tex for processing LaTeX source. For graphics it means that JPG, PNG and PDF images are supported natively, but not EPS.

Migration considerations:

  • For packages like graphicx and hyperref, replace dvips driver with pdftex.
  • If you defined your own graphics extensions to eps, change them to png, jpg and pdf.
  • Convert your eps images to pdf, or use original jpg or png images.
  • When adding your images to CVS, do not forget -kb
  • Check that all fonts are embedded in your document. Hints: http://axiom.anu.edu.au/~luke/embedded_fonts.html

Convert your eps images to pdf with epstopdf. Do check the result for correctness and font embedding. A command to insure embedding of all fonts:

  epstopdf --nogs input.eps | gs -q -sDEVICE=pdfwrite -dAutoRotatePages=/None \
  -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 \
  -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=output.pdf - -c quit

or as a Makefile rule:

%.pdf: %.eps
        epstopdf --nogs $< | gs -q -sDEVICE=pdfwrite \
        -dAutoRotatePages=/None -dPDFSETTINGS=/printer \
        -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true \
        -dEmbedAllFonts=true -sOutputFile=$@ - -c quit

Note that pixmaps will apparently be JPEG-compressed.

Also, do not use the following in your document or style files, because it breaks URL line breaking:

% Make URLs breakable, but also inactive.
\def\url{\begingroup \let\Url@Hyper@Hook\Url@Make@Link \Url}
\def\Url@Make@Link#1{\expandafter\href\expandafter{\Url@String}{#1}}

If you use both natbib and babel packages, load natbib before babel to prevent tilde showing up in citations. Loading natbib after babel and using citep-command will make “et al.” shown as “et~al.”.

Bibtex entries

Entry name

A good rule-of-thumb: Use up to the first three letters from surnames of the first three authors. First letter of each of them is capitalized. After the names add “:” and then the publication year. If there are multiple articles producing the same entry index, then use incremental number after the name part using two digits.

Examples:

  1. Kamarainen, J.-K., Kyrki, V., Kalviainen, H., Doing things as a Scientific Manifest, In Proceedings of the 13th Weird Conference (Mexico City, Mexico, 2003), pp. 666-667.
  2. Kamarainen, J.-K., Kyrki, V., Giving Up as an Important Scientific Contribution, In the Proceedings of the Annual Meeting of Idiots (Lappeenranta, Finland, 2003), pp. 1-2.
  3. Kamarainen, J.-K., Kyrki, V., Kalviainen, H., How much we did without achieving anything, Journal of Complete Idiots 17, 2 (2003), pp. 100-101.

Result to the following bibtex entries:

@InProceedings{KamKyrKal:2003,
  author =          {J.-K. Kamarainen and V. Kyrki and H. Kalviainen},
  title =           {Doing things as Scientific Manifest},
  OPTcrossref =     {},
  OPTkey =          {},
  booktitle =       {Proceedings of the 13th Weird Conference},
  pages =           {666--667},
  year =            {2003},
}
@InProceedings{KamKyr:2003,
  author =       {J.-K. Kamarainen and V. Kyrki},
  title =        {Givin Up as Scientific Contribution},
  OPTcrossref =  {},
  OPTkey =       {},
  booktitle =    {Proceedings of the Annual Meeting of Idiots},
  pages =        {1--2},
  year =         {2003},
}
@Article{KamKyrKal02:2003,
  author =          {J.K. Kamarainen and V. Kyrki and H. Kalviainen},
  title =           {What have we done without achieving anything},
  journal =         {Journal of Complete Idiots},
  year =            {2003},
  OPTkey =          {},
  volume =          {17},
  number =          {2},
  pages =	    {100--101},
}

It is convenient to save pdf files of these articles using the same convention, e.g., “KamKyrKal2003.pdf”.

Entry types

Those standard ones - available in the emacs “entry type” menu ;-) Check Wikipedia and Google.

Bibtex and personal list of publications

This can be conveniently done using the multibib latex package. For an example see the following (compile by typing “make view”):