Tortoise face

I mostly use Linux (an operating system) and LaTeX (a professional typesetting language). One of the charming things about these systems is their scripts; short programs to automate and speed up repetitive tasks.

The dollar sign $ is not a reference to money, but to the hackers’ interactive promptserving humanity since punched tape went out of fashion. These scripts are provided free under the GPL for your convenience.
I cannot guarantee that this code will do what you expect, nor that this code will not do what you would not expect—like e-mail itself to your friends, wipe your data, blow smoke, and die laughing. Therefore what these scripts do to you, your data, or your material possessions, is your responsibility and not mine.
If you would like such guarantees to become possible — then fund computer science research.

Convert for web

Let’s start with something simple. I have used this bash script to convert my photos to 1600×1200 for the web:

for i in *.dir/*[.jpg,.JPG];
do convert -size 1600x1200 $i -resize 1600x1200 -quality 65 $i;
echo Converted $i;
chmod -R o+x *.dir
chmod -R o+R *.dir/*

Too many math alphabets in LaTeX

This annoying error message is explained here. Bottom line: if you’ve got \usepackage{bm} in your preamble, try this:

%avoid "too many math alphabets" latex error

Improve fonts in LaTeX

I recommend using \usepackage{microtype} (even if you are using pdflatex). It just makes everything nicer.

There are also plenty of nice fonts out there. Here is my `fonts’ preamble:

%TeX Gyre Adventor is based on the URW Gothic L family of fonts 
%   (which is derived from ITC Avant Garde Gothic, 
%    designed by Herb Lubalin and Tom Carnase).
%TeX Gyre Bonum is based on the URW Bookman L family 
%   (from Bookman Old Style, 
%    designed by Alexander Phemister).
%TeX Gyre Chorus is based on URW Chancery L Medium Italic 
%   (from ITC Zapf Chancery, 
%    designed by Hermann Zapf in 1979).
%TeX-Gyre Cursor is based on URW Nimbus Mono L 
%   (based on Courier, 
%    designed by Howard G. Kettler in 1955, for IBM).
%TeX Gyre Heros is based on URW Nimbus Sans L 
%   (from Helvetica, 
%    prepared by Max Miedinger, with Eduard Hoffmann in 1957).
%TeX Gyre Pagella is based on URW Palladio L 
%   (from Palatino, designed by Hermann Zapf in the 1940s).
%TeX Gyre Schola is based on the URW Century Schoolbook L family 
%   (which was designed by Morris Fuller Benton for 
%    the American Type Founders).
%TeX Gyre Termes is based on the URW Nimbus Roman No9 L family of fonts 
%   (whose original, Times, was designed by Stanley Morison 
%    together with Starling Burgess and Victor Lardent and 
%    first offered by Monotype).

Sometimes I uncomment a different choice of font and work with it, just for the pleasure of the different atmosphere it lends the paper. Try tgbonum and tgschola for that old-fashioned feel.

No margins in LaTeX

Am I the only one to be irritated by small letters and wide margins in documents onscreen?

I use the LaTeX geometry package to adjust minimise set to zero and eliminate the margins, thus extirpating that pesky white space around the edges … like so —

%Small pagesize and no margins = nice big letters onscreen. 

— and the document fits nicely on my desktop screen in dual page mode.

Here are example pdf files: with margins and without margins. The text is an excerpt from my brother’s PhD thesis.

Read double page spread on small (notebook) screen

Notebook computers tend to have small screens and (for the moment) relatively low resolutions. Every pixel counts, and every square centimeter too. So people like me, who write academic papers while travelling, will have problems with reading on-screen: modern “wide aspect ratio” screens are the wrong shape, and the margins may waste precious screen real estate too. Add this to your preamble to get a nice readable double page spread:


The numbers above are good for a 1024×768 (i.e. 4:3) screen; you may wish to adjust the numbers to suit you.
Here is an article using the modified page layout and using the default page layout.

Compact bibliographies in LaTeX

So now you’ve typeset your paper and it’s 16 pages long (one page over the limit) — because of the generous separation between items in the bibliography. The bibliography is not intended for reading as a continuous piece of text, and we should not typeset it as if this were the case. This works like a charm:

%Compact bibliography, due to Axel Reichert.
 \renewenvironment{thebibliography}[1]{ %
     \fontsize{8.4}{9.4} %Change these numbers to
                         %change font size
 { %
   \end{oldthebibliography} %

I got it from here.

Put ‘DRAFT’ on your draft papers in LaTeX

So you want to share a draft pdf with a colleague, but you’re worried about incomplete versions of your paper being leaked?
You can use the draftcopy package but that is not compatible with pdflatex.
I add this to my LaTeX preamble, to put “DRAFT” in the background of every page:

%Put "DRAFT" in the background.  Due to Filox
\usepackage{graphics} %or \usepackage{graphicx}
\AddToShipoutPicture{ %
            \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){ %
        \makebox(0,0){\rotatebox{55}{\textcolor[gray]{0.95} %
           % Adjust 7cm to desired font size as necessary
            } %

I got it from here; it’s somebody’s blog, and I know nothing whatsoever about them aside from hypothesising that they are a male Croatian science student who has been blogging since November 2007. No, I’m not Sherlock Holmes, I can just follow a link.

Lists in LaTeX

The spacing of lists in LaTeX tends to be a little generous.
The mdwlist package offers compact list environments enumerate* and itemize*.
On this topic you might also like to check out the paralist package.

Rounded boxes in LaTeX

So you want to emphasise parts of some equation by putting them in nice rounded boxes, like this:

\usepackage{etex} %avoid error messages from tikz due to bug
\definecolor{shade}{HTML}{F4F4FF}%light blue shade
\node [fill=shade,rounded corners=3pt]

Then using the shademath command you can can get this:

I adapted this from here.

Align equations in LaTeX across multiple lines of text

This has been a real bugbear for me. You want equations separated by lines or paragraphs of text, to line up. In certain circumstances you can use intertext, but that’s far from perfect. Here’s what I came up with:

%in preamble
%in document body
g([a]X, [a]a) = g([d]c, [d]d) & \Longrightarrow
& [a]X = [d]c, [a]a = [d]d
... lots of other text ...
f([a]b,  Z,  X) = f([d]b,  [a]a,  Y) & \Longrightarrow
& [a]b = [d]b,\  Z = [a]a,\  X = Y

You get this perfectly aligned pair of equations:

LaTeX consecutive numbering theorems & lemmas

Many publishers’ style files number Theorems, Lemmas, Remarks, and so on distinctly; so you can have Theorem 1, Remark 1, Lemma 1, Lemma 2, Lemma 3, Remark 3, Theorem 2, Corollary 1, etcetera. It’s dreadful.

How to fix this elegantly depends on whether you are using llncs or ams class files (the two classes on which most other class files are based, at least in my area of research). Here is some LaTeX you can drop into place to give you nice, well-typeset, consecutively numbered theorems and lemmas. I have this at the head of most of my papers:

%for llncs
\spnewtheorem{thrm}{Theorem}[section]{\sc }{\itshape}
\spnewtheorem{lemm}[thrm]{Lemma}{\sc }{\itshape}
\spnewtheorem{prop}[thrm]{Proposition}{\sc }{\itshape}
\spnewtheorem{corr}[thrm]{Corollary}{\sc }{\itshape}
\spnewtheorem{nttn}[thrm]{Notation}{\sc }{}
\spnewtheorem{defn}[thrm]{Definition}{\sc }{}
\spnewtheorem{xmpl}[thrm]{Example}{\sc }{}
\spnewtheorem{rmrk}[thrm]{Remark}{\sc }{}
... or this ...
%for amsthm
\newtheoremstyle{jamiestyle}% name of the style to be used
  {4pt}% measure of space to leave above the theorem. E.g.: 3pt
  {0pt}% measure of space to leave below the theorem. E.g.: 3pt
  {\it}% name of font to use in the body of the theorem
  {0pt}% measure of space to indent
  {\sc}% name of head font
  {.}% punctuation between head and body
  { }% space after theorem head; " " = normal interword space
  {}% Manually specify head
\newtheoremstyle{jamienfstyle}% name of the style to be used
  {4pt}% measure of space to leave above the theorem. E.g.: 3pt
  {0pt}% measure of space to leave below the theorem. E.g.: 3pt
  {\normalfont}% name of font to use in the body of the theorem
  {0pt}% measure of space to indent
  {\sc}% name of head font
  {.}% punctuation between head and body
  { }% space after theorem head; " " = normal interword space
  {}% Manually specify head

Convert pdf to djvu

Djvu (pronounced ‘dejaview’) is a document format which is more compact and faster to view than pdf. Converting pdf to djvu used to be difficult, so I developed a script adapted from pdfs2djvu which uses code kindly supplied by Sebastien Carlier.
Click here to download the pdftodjvu script

I include it for completeness; you might be better off using the better-written pdf2djvu package (which if you use Debian you can install by typing sudo apt-get install pdf2djvu).