Home Français English

Sébastien's Latex Tricks

While writing my thesis, I did experience quite a few problems when typesetting the manuscript with LaTeX. A plain search on latex will usually return a couple of thousands of answers ranging from outdated pages, undocumented packages, as well as latex items you might not be looking for... Therefore, I decided to sumarize some information I collected that could be useful for other people.

1- Usefull websites
2- Usefull sofware 3- Documentation available on this server
4- Packages I used
5- Creating a PDF file with LaTeX

1- Usefull websites

Headings
Left headings


Headings
Right headings


Summary
Sumaries


Side caption
Side captions


Side caption
Figures side by side

2- Usefull sofware

  • Emacs... Does everything, edit LaTeX file, spellchecking, coffee...
  • Flyspell: on the fly spellchecking for emacs: extremely useful.
  • Kile: LaTeX source editor - TeX shell - Gnuplot front end for KDE 3. I did not use this software to write my thesis because I discovered it very late in the process of writing. However, I have used it since and I find it more convenient than emacs, and you DO keep control on the LaTeX source.
  • Xmgrace: WYSIWYG 2D plotting tool for the X Window System and M*tif. That's what I use for all my plots. By the way, it runs on windows as well (it's part of cygwin).
  • Xfig: I use this figures. It's basic but it works and figures are clean. It's also part of cygwin on M$ windows.
  • Jabref: graphical frontend to manage BibTeX databases. I find it great, no need to dig into BibTeX files, it does a very good job at maintaining a database, searching... It's in java so it should work on any platform.

3- Documentation available on this server

4- Packages I used

  • natbib: for inserting citations in a human readable for format. It also expands the Latex \cite command to obtain citations such as (merkel et al. 2000), merkel et al. (2000), (see Merkel et al. 2000) or Merkel et al. 2000 within the same document. I have a small reference sheet here.
  • To switch to french mode with TeteX (available on most linux platforms), the commands are
    \usepackage[latin1]{inputenc} % To use characters such as é without typing \'e
    \usepackage[cyr]{aeguill} % To display characters such as é
    \usepackage{xspace} % To get the right spacings in front of : and so on
    \usepackage[french]{babel} % To get into french mode
    Comment from Mathieu Kociak: for the mac users, the command \usepackage[latin1]{inputenc} does not work properly, you should use \usepackage[latin1,applemac]{inputenc} instead.
  • For the insertion of postscript figures
    \usepackage{graphicx}
    Comment by David Coudert: when including an image, do not add the extension of the file (\includegraphics[...]{blah}). If the file is compiled with Latex, it will look for blah.eps, if it is compiled with pdflatex, it will look for blah.pdf
    Comment from David Coudert: trick for including jpeg images
    You will need the software jpeg2ps, avalaible at http://www.pdflib.com/products/more/jpeg2ps.html intalled. Add the following lines into the definitions in the latex file
    %%%%%%%%%%%%
    % Pour inclure des .jpg dans le tex
    \DeclareGraphicsExtensions{.jpg, .eps}
    \DeclareGraphicsRule{.jpg}{eps}{.jpg.bb}{`jpeg2ps -h -r 600 #1}
    To include a jpeg file, myimage.jpg for instance, type
    \includegraphics[....]{myimage}
    Please note that the .jpg extension is removed, this is very important. The jpeg file will be directly included into the file, and converted into postscript only when printing, saving a lot of disk space. By the way, it does work with pdflatex.
    Comment by Constantin Vernicos: for including gif images
    Well, there is no way to include gif files, and gif images look like shit when converted into jpeg. You better use pnm instead:
    - convert the file from gif to pnm and create a bounding box
    giftopnm blah.gif > blah.pnm
    pnmtops blah.pnm | grep "^%%" > blah.pnm.bb
    - In the TeX/LaTeX file, replace
    \usepackage{graphicx}
    by
    %Check if we are compiling under latex or pdflatex
    \ifx\pdftexversion\undefined
    \usepackage[dvips]{graphicx}
    %%%%%%%%
    %% Pour inclure du .jpg et .pnm sous latex
    %%%%%%%%%%%%%%
    \DeclareGraphicsExtensions{.jpg,.eps,.pnm}
    \DeclareGraphicsRule{.jpg}{eps}{.jpg.bb}{`jpeg2ps -h #1}
    \DeclareGraphicsRule{.pnm}{eps}{.pnm.bb}{`pnmtops #1}
    \else
    \usepackage[pdftex]{graphicx}
    \fi
    This way, pnm files will be converted on the fly when working with LaTeX, Dvi, and PS files, but pnm files will not work with pdflatex, unfortunatly...
    Comment by David Coudert (again!): jpeg and png images
    To include jpg/png depending on context (pdf or eps/epsi/ps), you can also use pgfimage.
    \usepackage{pgf}
    and include the image with
    \pgfimage[height=6cm]{blah}
    It will adapt to all situations (ps or pdf). pgf stands for "LaTeX Portable Graphics Format".
  • I redefined my heading as follow
    \usepackage{fancyheadings}
    \pagestyle{fancyplain}
    % Remember chapter title
    \renewcommand{\chaptermark}[1]{\markboth{Chap. \thechapter:\ #1}{}}
    % section number and title
    \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
    \lhead[\fancyplain{}{\bfseries\thepage}] %
        {\fancyplain{}{\bfseries\rightmark}}
    \rhead[\fancyplain{}{\scshape\leftmark}] %
        {\fancyplain{}{\bfseries\thepage}}
    \cfoot{}
    You can see the resulting headings on this example.
  • I also created a small command to add summary boxes in the text
    \newcommand{\resume}[1]{
    \addcontentsline{toc}{section}{Résumé}
    \begin{center}\fbox{\parbox{12cm}{\bf #1}}\end{center}}
    You use it as follow:
    \resume{
        Pour résumer:
        \begin{itemize}
        \item Pour un monocristal
        \item Pour un polycristal
        \end{itemize}
        }
    You can see the result on this example.
  • I also wanted figures with captions on the side, the sidecap package does that
    \usepackage{sidecap}
    You use it as follow
    \begin{SCfigure}[][t]
    \includegraphics[width=8cm,clip]{figure.eps}
    \caption[Short caption]{\label{thelabel} Long caption.}
    \end{SCfigure}
    You can see the result on this example.
    Do not use this package to have two figures side by side! For this, you should use a combination of figure and minipage environments:
    \begin{figure}
    \begin{minipage}[t]{8cm}
    \begin{center}
    \includegraphics[width=8cm,clip]{figure1.eps}
    \caption[Short caption for figure 1]{\label{labelFig1} Long caption figure 1}
    \end{center}
    \end{minipage}
    \hfill
    \begin{minipage}[t]{7.5cm}
    \begin{center}
    \includegraphics[width=7.5cm,clip]{figure2.eps}
    \caption[Short caption for figure 2]{\label{labelFig2} Long caption figure 2.}
    \end{center}
    \end{minipage}
    \end{figure}
    See the result on this example.
  • The spacings in the table of content and list of figures were too short, you can configure that with the tocloft package
    \usepackage{tocloft}
    My configurations were
    % More space for figure numbers
    \setlength{\cftfignumwidth}{3.0em}
    % Space between elements of the list
    \setlength{\cftbeforefigskip}{0.1cm}
    % Space before chapter entries in the TOC
    \setlength{\cftbeforechapskip}{0.2cm}
    % Space before parts in the TOC
    \setlength{\cftbeforepartskip}{0.7cm}
  • Finally, I used the package hyperref to tune the PDF ouput (see below)

5- Creating PDF files with LaTeX

The simple way
Creating a PDF file with LaTeX is actually much easier than it sounds. The way to proceed is simple:
  1. Create the latex document
  2. LaTeX, create the dvi
    latex file.tex
  3. Create a postscript file with dvips, the trick is to include the fonts in the postscript so they will look nice in PDF. You do it that way
    dvips -o psfile.ps -Ppdf dvifile.dvi
  4. Use ps2pdf to convert it to PDF. If your document is in A4, add -sPAPERSIZE=a4 in the command line. The complete command is
    ps2pdf -sPAPERSIZE=a4 psfile.ps
And that's all, you'll have a nice PDF with correct fonts that can be read on unix, windows or macOS.
More tuning...
You can also tune the PDF file with the hyperref package (see the links for a manual). The functions I used are as follow.
  • Plain user of the package:
    \usepackage[a4paper=true,ps2pdf=true,pagebackref=true]{hyperref}
    This will add commands into the PDF to create a linked table of contents, as well as links for the cross-references such as calls to figure and page numbers
    • The a4paper option is easy to understand.
    • ps2pdf=true tells the compiler that you'll use ps2pdf to create the PDF output.
    • pagebackref=true is a great option, it adds page numbers in the bibliography and links to the positions in the document where you actually cite them.
  • You can also add information about you document:
    \hypersetup{
        pdftitle =
            The title of my PDF,
        pdfauthor =
            My name,
        pdfsubject=
            The subject,
        pdfkeywords =
            keyword1 keyword2 keyword3
    }
  • Finally, I also used colors:
    \hypersetup{
        colorlinks = true,
        linkcolor = red,
        anchorcolor = red,
        citecolor = blue,
        filecolor = red,
        pagecolor = red,
        urlcolor = red
    }
    That will put some colors in the PDF documents to make the links more obvious to the reader.
  • See example 1, example 2, and example 3 for screenshots of the final PDF.
Table of contents in PDF
PDF with table of contents


Color links in PDF
PDF with color links


Bibliography in PDF
Color links in the bibliography
1- Usefull websites
2- Usefull sofware 3- Documentation available on this server
4- Packages I used
5- Creating a PDF file with LaTeX

Sebastien Merkel, 06/2016
09/2003: added comment on side by side figures.
09/2003: added two comments from David Coudert.
09/2003: added one comment from Mathieu Kociak.
05/2004: modified layout.
12/2004: corrected error about pdflatex and jpeg images.
12/2004: added comment by Constantin Vernicos.
12/2004: added comment by David Coudert.
05/2005: updated entry on kile, added links to xmgrace, xfig, and jabref.
06/2006: after a suggestion from Matthieu Moy, corrected inclusion of jpeg files with pgf.
07/2006: after a suggestion from Dirk Schlimm, corrected the spelling of "useful", full of use, but only one L!
06/2016: removed broken links.
 

© Sébastien Merkel, Université de Lille, France

Home > Latex > index.php