My LaTeX tutorial


Here's the template of my PhD thesis manuscript.
Below's how I proceed...


1. Architecture

All chapters/parts come in different files.
The main file 00_Main.tex just brings them all together.

----------------------------------------------------------------------------
\input{00_Packages} \begin{document} \include{01_PageDeGarde} \include{02_Dedicace} % ... \end{document} ----------------------------------------------------------------------------

Packages used are declared in 00_Packages.tex

----------------------------------------------------------------------------
\documentclass[a4paper,twosides,11pt]{book} %\usepackage[]{} %... ----------------------------------------------------------------------------

For a clearer writing-up, it might be useful to create one file per section. Here's how I structured my chapters:

----------------------------------------------------------------------------
\chapter{My Chapter} % Introduction This chapter describes... First is introduced... Then, ... Finally, ... \minitoc % Table of contents for the current chapter (See below) \input{ChapN_Section01.tex} \clearpage % clearpage forces figures and tables (floats) to belong to the corresponding section \input{ChapN_Section02.tex} \clearpage \input{ChapN_Section03.tex} \clearpage \input{ChapN_Section04.tex} \clearpage \section{Synthesis/Transition} This chapter showed ... We can now safely move to the next chapter, which deals with ... ----------------------------------------------------------------------------


2. Details

2.1. Compilation

I'm using pdflatex that directly creates .pdf files.
There's no more need to go through latex ... && dvips ... && ps2pdf ...), just type pdflatex.
Several compilations are necessary for the bibliography and the index to be created

----------------------------------------------------------------------------
pdflatex 00_Main.tex && makeindex 00_Main.idx && pdflatex 00_Main.tex && bibtex 00_Main && pdflatex 00_Main.tex && pdflatex 00_Main.tex ----------------------------------------------------------------------------

It would really be a pity not to take advantage of hyperlinks (toc, ref, links to web pages and mails) whilst using pdflatex.
Many options are available.

----------------------------------------------------------------------------
\usepackage{color} % to color the links the way you like \usepackage[...]{hyperref} ----------------------------------------------------------------------------

2.3. Margins etc.

See package geometry. Lots of options available.
To put comments in the margin, you can use the command

----------------------------------------------------------------------------
\marginpar[...] ----------------------------------------------------------------------------

2.4. Headers and footers

See package fancyhdr.
With the book class, all new chapters begin on an odd page, the style of which is plain (no headers and footers).
If you want to keep headers and footers on the title chapter page, add the following line after your chapter declaration:

----------------------------------------------------------------------------
\protect\thispagestyle{fancy} ----------------------------------------------------------------------------

If you want them to be removed from the previous white page, use the following trick:

----------------------------------------------------------------------------
\usepackage[strict]{changepage} \newcommand{\sdp}{% insert white page or not \checkoddpage% \strictpagechecktrue \strictpagecheckfalse \ifoddpage %do nothing \else \thispagestyle{empty}~\newpage \fi } ----------------------------------------------------------------------------

and add \sdp at the end of all chapters.
Alternatively, you could redefine the include command used in the main file 00_Main.tex in order not to be bothered.

----------------------------------------------------------------------------
\newcommand{\myinclude}[1]{\include{#1}\sdp} ----------------------------------------------------------------------------

To get the total number of pages of your document, use the package lastpage.

2.5. Intermediate TOC

To create intermediate table of contents aka 'TOC', use the package minitoc.

2.6. Special characters

----------------------------------------------------------------------------
\usepackage{textcomp} %\textmu, \textohm, \textcelsius, \textperthousand \usepackage{upgreek} %\upmu, \upalpha, \upbeta, \upgamma \usepackage{gensymb} %\degree \usepackage{eurosym} %\euro, \geneuronarrow{} ----------------------------------------------------------------------------

The lipsum package allows you to generate dummy text in latine for debug purposes.

2.7. Maths

----------------------------------------------------------------------------
\usepackage{amsmath,amssymb,euscript,cancel} ----------------------------------------------------------------------------

2.8. Pictures

Graphicx of course!
A pinch of subfigure also...

In pdflatex, only 3 formats can be integrated

An interesting feature of the graphicx package is the draft options, which will not display the picture but keep in mind its dimension,
thus allowing gain in compilation time.

----------------------------------------------------------------------------
\includegraphics[draft=false, width=50mm, angle=-90]{...} ----------------------------------------------------------------------------

Two other packages used here are:

Used for basic drawing.

----------------------------------------------------------------------------
\usepackage[all]{xy} ----------------------------------------------------------------------------

As its name indicates it, only .ps files can be created.
This package thus cannot be directly used with pdflatex.
You will have to create a specific .tex file for your picture, generate the corresponding .ps file with latex
then convert it to .pdf and integrate it using \includegraphics

----------------------------------------------------------------------------
\usepackage{pstricks, pst-text, pst-grad} ----------------------------------------------------------------------------

2.9. Tables

Several packages are very useful, especially ctable (modern display), dcolumn (decimal point alignment), multirow.

----------------------------------------------------------------------------
\usepackage{multirow, bigstrut, hhline, rotating, array, slashbox, tabularx, ctable, longtable, colortbl, dcolumn} ----------------------------------------------------------------------------

2.10. Animations

Flash animations (.swf files) can be integrated using the movie15 package.
You can add a preloading picture. This is this picure that will be printed.

2.11. Bibliography

I simply used BibTeX and created my own .bst (bibtex style) file.
To create a .bst file, 2 softs are available: makebst and Bib-it.
Neither one nor the other will give you the expected result. You will have to fix stuff inside the .bst file.
Everyting's explained here: Tame the BeaST!
Be patient!

To add stuff before the biblio items, just renew the bibliography environment renewenvironment
by copying the original code in the file book.cls and adding what you want.

2.12. Index

See package makeidx.

2.13. Glossary

Popup windows (on Acrobat Reader only) can be created with the cooltooltips package.


3. Advices

3.1. How to install a new package?

Try to catch the '.sty' file corresponding to the package you want on the web (e.g. on CTAN).
If you just can get the '.ins' and '.dtx' files, download them and, in the directory they lie, type latex myPackage.ins.
This will create the '.sty' file.
If you want to install the package for good, copy the '.sty' file in /usr/share/texmf/tex/latex/tools/ and type texhash wherever.
Otherwise you can let the '.sty' file in the directory you're working.

3.2. Struggling with a specific package?

If you already spent hours browsing forums (see above) and still haven't found any solutions, feel free to contact the authors of package you're using.
I always receive fast answers.

3.3. Struggling with .eps/.pdf files?

There are many tools to play with: Acrobat Pro (available on xxx), GhostScript, epstools, convert, pdftk, pdfedit, pdfcrop...
Just breathe!

3.4. ROOT plots

The Root .pdf export function is crap for some reason (at least on Cygwin).
Ugly thick lines appear. This is not the case with a .ps output.
So, save your canvas in .ps

----------------------------------------------------------------------------
myCanvas->SaveAs("foo.ps") ; ----------------------------------------------------------------------------

Then, convert it in .pdf in 2 steps

----------------------------------------------------------------------------
ps2epsi foo.ps && epstopdf foo.eps ----------------------------------------------------------------------------

Do not forget to always save your files in the native Root format (.root) in order to reopen them to add/remove anything.

3.5. Drawing sketches, schemes, diagrams, graphs...

If you have such an object to create, use a vector graphics editor e.g. Inkscape, or for simpler stuff Dia (a modern xfig-like). Both are free.
This way, you could integrate your object wherever (article, presentation, poster) with no quality loss at all.
The picture will always look perfect.

3.6. Animations

If you have animations to create, make them in Flash since .swf files can be integrated anywhere:

Free flash softwares exist. See e.g. e-anim.
Alternatively, you can use Adobe Flash Pro (could be installed on xxx, ask the Windows men).


4. Docs

There are bunches of docs on the web.
Here are some I often consult:

Of course, beginners should read or browse

And there are loads of other nice packages to discover, e.g.


5. Epilogue

I might post the complete source of my template some day but I really believe you should struggle a bit...
In the meanwhile, here's the cover page source (with the vectorial logos).
Other CNRS/IN2P3 logos can be found here.

Happy LaTeXing!


Back to Table of Contents
Copyright: Mathieu Trocmé, Mon 28 Dec 2009 (14:13:46)