LaTeX notes

This page contains notes I took during my own writing of LaTeX documents. It is no general reference to LaTeX writing but may contain some useful hints that are hard to find in other documentation.

Page and content formatting

Paragraphs

  • Line Spacing: The packagesetspace provides among others the commands \singlespacing, \onehalfspacing, \doublespacing and \setstretch{baselinestretch}.

Tables / Arrays

You can use the package array for enhanced formatting of tables.

The longtable package provides support for tables longer than a single page.

Sometimes you have to use the command \tabularnewline instead of the usual \\ to start a new row, e.g., in \raggedright aligned columns as \raggedright re-defines \\.

Counters

Counters for use with \setcounter{counter}{value} (a value of -1 disables counters very often):

  • tocdepth: depth of \tableofcontents
  • secnumdepth: depth of section numbering

Page size

Some publishers require PDFs in letter format (instead of A4). pdflatex generates A4 by default. In order to enforce letter format for pdflatex, you can change the config file “pdftexconfig.tex” (probably located at /usr/share/texmf/tex/generic/config/pdftexconfig.tex) or include the commands “\pdfpagewidth 8.5in” and “\pdfpageheight 11in” in your LaTeX source. If you produce your pdf with dvipdfm(x), use the option “-p letter”.

Hyperref package

The hyperref package is useful to make internal (\ref, \cite,…) and external (\url, …) links clickable, which is quite useful when reading documents. Moreover, it provides options and commands to customize the generated PDF when using PDFLaTeX and specify PDF metadata such as title or author information.

For the impatient: Just try the following command and see whether it fits your needs:

\usepackage[bookmarks, pdftitle={your title here}, pdfauthor={Your name here}, colorlinks=true, linkcolor=black, citecolor=black, urlcolor=black]{hyperref}

Some options of the hyperref-package

  • pdftitle: The title of the generated PDF.
  • pdfauthor: Author of the PDF file.
  • colorlinks: Should hyperlinks be colored?
  • linkcolor: Color for internal links.
  • citecolor: Color for references.
  • urlcolor: Color for URLs.
  • linktocpage: make page number, not text, be link on TOC, LOF and LOT (default: false).
    This can be used to prevent the failure pdfTeX error (ext4): link annotations can’t be nested

Custom PDF bookmarks

To add an entry to the PDF bookmarks, you can use \pdfbookmark[level]{bookmark text}{anchor}level is chapter, section; bookmark text is your text, and anchor is an internal label. Do not omit the anchor as otherwise the bookmark will not point to the right location.

Correct hyperlinks and bookmarks in PDF

\phantomsection has to be used to get the hyperlinks (and bookmarks in PDF) right for index, list of files, bibliography, …
Example:
\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures

Differences in LaTeX documents

If you collaborate with colleagues and have to edit documents together, the “track changes” feature in MS Word or Openoffice is quite useful. You can achieve a similar effect for LaTeX documents by comparing two versions of a document with latexdiff. Latexdiff is a perl script and hence requires perl to be available on your computer. If you are running MS Windows, you might consider to use cygwin or ActivePerl.

Embedding fonts in PDF documents

In order to ensure that the fonts used in a PDF document can be correctly displayed on any machine, the fonts have to be embedded. When publishing a paper via IEEE, the IEEE PDF eXpress tool demands to embed all used fonts in the PDF. Below you can find how to include your fonts and how to check whether they are included.

How to verify that fonts are included

Some options:

  • Use the pdffonts binary provided by the xpdf package (Linux, cygwin) and check whether output when called for your PDF provides “yes” in the “emb” column. If there is a “no”, the corresponding font is not embedded.
  • Open the document properties of the PDF in the Adobe Reader or Acrobat, select the “fonts” tab and look whether all the fonts are embedded.

How to include the fonts in your PDF

If your check shows that not all fonts are embedded, there are different things you do to include the fonts:

  • Probably the easiest option – if you have Adobe Acrobat – is to open the PDF document and print it to the PDF printer driver with the option to include all fonts. This might work for other PDF generators that work by registering a printer driver as well.
  • Depending on your configuration, PDFLaTeX might not include the base 14 PDF fonts. To force the inclusion, you have to set “pdftexDownloadBase14 true” in the updmap.cfg file and run update-updmap or updmap directly to update the config files used by PDFLaTeX. Some locations where this file might be found are:
    • /var/lib/texmf/web2c/
    • /usr/share/texmf/web2c/
    • /etc/texmf/updmap.d/
  • The previous configuration parameter does not solve the issue of the fonts used in figures embedded in your PDF files. For this, you can convert the PDF file to PS with pdf2ps <file.pdf> and then back to PDF with ps2pdf14 <file.ps>. If that does not work, you can try to use the “-dPDFSETTINGS=/prepress” option. Unfortunately, the quality of your PDF usually suffers from these conversions.

Links to resources

  • Links to general documentation can be found on the getting started with LaTeX page.
  • If you install the tetex-doc package (tested for Fedora and cygwin), you can find the useful “Guide to teTeX Documentation” including LaTeX and PDFLaTeX as well at /usr/share/texmf/doc/index.html. This path may also be the same (or similar) for other versions of GNU/Linux. Of course, if you want to access the documentation provided by cygwin with your Web browser, you have to prefix the aforementioned path with the %CYGWIN_INSTALL_DIR%.