Random Wisdom


LaTeX Shell Escape

by on Mar.13, 2011, under How To ..., LaTeX

One of the lesser known features of LaTeX is its “shell-escape” mode. This is achieved using the LaTeX command \write18{cmdlist} in the document. This facility can be used to incorporate dynamic content or simply run additional processes during the compilation phase. An example document may look something like:

  \immediate\write18{date > tmpdate.tex}
  \immediate\write18{rm tmpdate.tex}

As \write18 is usually disabled on most systems for obvious security reasons, it must be enabled explicitly:

$ latex -shell-escape input_file

More details are available in the MiKTeX documentation under the heading “Running Programs From Within TeX“.

1 Comment :, more...

Graphics format conversion

by on Dec.09, 2009, under LaTeX, Linux, Software

Up until now I have been using the ‘convert‘ tool that comes with ImageMagick to switch between image formats — mainly for creating EPS files from JPG/PNG (raster format) files for use with LaTeX. Then I came across sam2p.

It is a light-weight utility that does one thing only and it does it well: convert between image formats. I’ve been using it for a while now and find that it can greatly reduce files sizes with minimal drop in quality. I’ve even used it to process existing EPS files just to get the reduction in file size. Best of all, it is multi-platform — executables are available for both Windows and Linux on the project homepage.

Goodbye convert and hello sam2p!

2 Comments :, , , , , , , more...

Squeezing space in LaTeX

by on Oct.29, 2009, under How To ..., LaTeX

Academic papers and articled often come with a predefined maximum page count and it is common to find that it’s a limit that is easily exceeded. Under such circumstances, it becomes necessary to pull a few “dirty tricks” that squeeze out every last bit of available space.

The most common approach is to simply redefine the ‘\baselinestretch’ variable in the preamble of the document. The parameter controls the scaling of the space between the bottom of two successive lines of text. Therefore, the definition used to squeeze that space by 2% is:


While that trick alone is sufficient in most cases, it is useful to be aware of other spacing parameters that can be adjusted. The Cambridge University Engineering Department has a nice page with lots of details. I personally find ‘\textfloatsep’ to be one of the more useful ones:


It is used to reduce the amount of space that is usually left between a float and the adjacent text block (e.g. end of caption of a top-figure and the text below).

1 Comment :, , , more...

Embedding fonts in a PDF document

by on Oct.03, 2008, under How To ..., LaTeX, Linux, Software

It is often a good idea (or a requirement) to embed the used font faces in a PDF document. This is easily accomplished using ps2pdf during the final stage of conversion of a document from PS to PDF:

$ ps2pdf -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 \
         -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true \
         'input_file.ps' 'output_file.pdf'

An explanation of the command options can be found in the Ps2pdf.htm file in the Ghostscript documentations (or here).


Leave a Comment :, , , , more...

Embedded multimedia in LateX/Prosper

by on Dec.01, 2007, under How To ..., LaTeX

The movie15 package by Alexander Grahn is useful for this purpose. The movies embedded, however, cannot be viewed with any PDF reader on Linux.

Leave a Comment :, , more...

Logo in a LaTeX document header/footer

by on Oct.22, 2007, under How To ..., LaTeX

Easily accomplished using the ‘fancyhdr‘ package:

\fancyhead[L]{}% empty left
\fancyhead[R]{ % right

All of that goes into the preamble of the document.

4 Comments :, , , , more...

Duplicate identifiers with hyperref in pdflatex

by on Oct.01, 2007, under LaTeX

The following warning is fairly common when hyperref is used with PDFLaTeX:

! pdfTeX warning (ext4): destination with the same identifier (name{page.1}) ha
s been already used, duplicate ignored

The solution is to use the ‘plainpages=false‘ option with hyperref.

However, this appears to be insufficient for the article class with the ‘titlepage‘ option. To remedy the warning the following is additionally needed around the \maketitle in the body of the document:


By switching the style of page counter before and after the title page, any ambiguity regarding page numbers is resolved (title page is logically page 1 but LaTex re-initiates the counter on the actual page 1 – leading to 2 successive page 1s).

Leave a Comment :, , more...

User installation of additional TeX/LaTeX classes and styles

by on Aug.09, 2007, under How To ..., LaTeX, Linux

When you are the sysadmin, you can simply drop the new class/style files under the system TeX path (e.g. /usr/share/texmf/tex/) and run ‘texhash’ to have them automatically picked up. But what do you do when you are just a regular user?

TeX/LaTeX looks at the TEXINPUTS environment variable to look for additional locations to search for included/referenced files. Therefore, new classes/styles can be easily added as follows:

  1. Create a directory for the files:
    $ mkdir -p $HOME/tex/latex
  2. Place the new class files into that folder (each class can be in its own directory and contain subdirectories):
    $ cp -a fancy-class $HOME/tex/latex/
  3. Export the TEXINPUTS variable and also add it to your $HOME/.bash_profile:
    $ export TEXINPUTS=.:$HOME/tex/latex//:$TEXINPUTS

The ‘.’ ensures that the working directory is included in the search path. The double-‘//’ tells bash to also include files in subdirectories of ‘$HOME/tex’ recursively.

New BibTeX files can also be added locally in a similar fashion. The variables to set are then BSTINPUTS and BIBINPUTS.

The environment variable to set for MakeIndex styles is: INDEXSTYLE.

Source: AstroNat – Installation at The Smithsonian/NASA Astrophysics Data System

UPDATE [16 July 2009] The Kpathsea manual provides a wealth of information about usable environment variables.

1 Comment :, , more...

Mass conversion of images

by on May.07, 2007, under How To ..., LaTeX, Linux, Software

The following “one-liner” can be used to mass convert a given image format into another using the convert (part of ImageMagick) and basename tools:

$ for A in $(ls *.$SRC_TYPE); do convert $A $(basename $A .$SRC_TYPE).$DST_TYPE; done

where $SRC_TYPE is the file suffix of the original images (e.g. png) and $DST_TYPE is the file suffix of the type desired (e.g. eps).

Leave a Comment :, , , more...