Friday, July 3, 2009

Speeding up Kile

Even though I'm mostly a Gnome user, my LaTeX editor of choice is Kile. Unfortunately, it can become a bit sluggish, especially when dealing with long lines. (I hate artificial line breaks, so I just type one line per paragraph and turn on dynamic word wrapping.)

This seems to have something to do with rendering. To make Kile considerably faster, start it like this:
kile --graphicssystem raster
Instead of raster, you can also try opengl, which is supposed to be even faster, but not considered stable yet. YMMV.

Monday, June 15, 2009

Creating a multi-page PDF from images

It is often convenient to pour a series of JPEG (or PNG, or GIF) files into a PDF, for example for printing or for e-mailing. Given the power of the Linux command line, this is surprisingly difficult, but I found a fairly straightforward way to do it. Skip to the bottom if you just want the oneliner.

Many websites will tell you the following:
convert *.jpg output.pdf
Easy, no? Don't do this. Why? Look at this:

-rw-r--r--  1 thomas thomas 129826204 2009-06-15 15:29 output.pdf
-rw-r--r--  1 thomas thomas    947022 2009-06-15 15:04 page1.jpg
-rw-r--r--  1 thomas thomas    962956 2009-06-15 15:05 page2.jpg
-rw-r--r--  1 thomas thomas    925291 2009-06-15 12:54 page3.jpg
-rw-r--r--  1 thomas thomas    952717 2009-06-15 12:54 page4.jpg
-rw-r--r--  1 thomas thomas    642471 2009-06-15 15:08 page5.jpg

The original JPG files are less than 5 MB altogether, but the resulting PDF is a whopping 124 MB! Clearly, convert (from the otherwise excellent ImageMagick bundle) re-encodes the images somehow, instead of embedding them straight into the PDF file.

Enter the little-known utility sam2p. It comes in an Ubuntu package of the same name. In its simplest form, it converts a single image file into a PDF by embedding the image file into the PDF file. For example:
sam2p page1.jpg page1.pdf
One of the shortcomings of sam2p is that it does not allow you to set the page size directly, so you'll end up with PDFs that exactly fit the original images.

Now we can generate all the pages as separate PDFs, but sam2p cannot create a PDF with multiple pages. Enter pdfjoin from the pdfjam package (available in Ubuntu under that name). It is simple to use:
pdfjoin page*.pdf --outfile output.pdf
This will use a consistent page size, so it is no problem that sam2p spit out pages of arbitrary size. It defaults to A4 paper; specify --paper letterpaper to use the Letter format.

Because I'm lazy, I wrote a little bash oneliner to do the trick, then let my readers improve upon it (thanks Mark, thanks Eamon!). It is now a twoliner, but who cares:
find . -maxdepth 1 -iname 'page*.jpg' -exec sam2p '{}' '{}'.pdf \;
pdfjoin page*.pdf --outfile output.pdf
This assumes that your input images are named page1.jpg, page2.jpg etcetera, and that there are no files named like page*.pdf in the current directory. If you have more than 9 pages, remember to prefix a zero to keep them in order. If you want to do this for PNG or other images, remember to change the extension in both places.

Tuesday, May 19, 2009

Windows Genuine "Advantage"

My Windows is genuine. I fail to see the advantage.

Wednesday, May 13, 2009

Accepted for Google Summer of Code!

I have been accepted for Google Summer of Code 2009! The title of my project is “Extend EclipseFP functionality for Haskell.” I have just set up a blog where I can keep all posts together that are related to this project. (This blog will also allow me to test-drive Wordpress, because as we all know Blogger sucks.) You can find more information at my new blog: EclipseFP GSoC '09.

Wednesday, February 25, 2009

Sumatra PDF Viewer for LaTeX users on Windows

If you use LaTeX on Windows, or in particular pdflatex, you must have noticed that viewing the resulting PDF file is not as easy as you would think.

Sure, Adobe Reader displays it fine. But apart from being bloatware and slow as hell, it also locks the PDF file it is displaying. Thus you cannot rerun pdflatex until you close the file in Reader, because the output file cannot be overwritten. This is a pain in the arse.

Foxit Reader seems like a decent alternative; it is much faster and less bloated than Adobe Reader (even though the installer tries to get you hooked on several other pieces of software that you probably don't want). Foxit does not lock the currently viewed file; however, it offers no reload option, and if you overwrite the output file, it will only display blank pages for what's not currently cached.

Enter Sumatra PDF. A very lightweight and very simple program, contained in a single executable file, written by a single developer, but it has the one killer feature that LaTeX authors need. It automatically reloads the PDF file whenever it changes. And it stays on the same place in the document while it does this.

There is currently a bug that causes the window to demaximize when it reloads, but you can work around that simply by not maximizing the window in the first place. This little viewer will definitely make my life easier.

Tuesday, February 3, 2009

Hamlet – by whom?

Apparently the Googlebot came by at just the wrong time.

Sunday, February 1, 2009

USB: the right direction

USB plugs are annoying, because it's hard to see how to plug them in, and you have only a 50% chance of getting it right on the first try. But I recently noticed what seems to be a little-known feature that increases your odds. There is a little USB logo on one side of nearly all plugs. It seems that manufacturers mount their ports in such a way that the logo should face upwards.

I haven't figured out the case of side-facing ports yet, but maybe there is a pattern there as well. If your computer has such ports, let me know in the comments which way the logo should face on those!