LaTex fun

Posted on April 16, 2011 with tags .

Recently, I’ve had the pleasure of having to write many short documents in LaTex (short as in 1 to 6 pages). I haven’t written a lot in LaTex since my school time, so this was a very nice flashback to those times.

However, since then PDF is the new “standard” format, not PostScript, so I had to do a bit of adjustement. The biggest change is that pdflatex doesn’t “like” EPS files for images, so what to do?

As usual, the road to enlightenment has many turns…

First, reading docs, I said simple, create a PNG file, scaled at high resolution, then include it scaled down so that it kind of loses the ugly scaled-bitmap feel.

But that’s not a nice solution: it is still bitmap, just looks like aliased. So I wanted another solution—and threw gnuplot’s set terminal png and fig2dev’s -L png out the door.

Next was, of course, embedding PDFs, since pdflatex supports that. However, gnuplot’s pdfcairo output is not as nice as I wanted. It works, but only kind of. Issues with font consistency and scaling, etc.

Then I remembered the nice pslatex output from xfig, and learned that there’s a pdftex output. And that gnuplot also can generate .fig output. So I went and redid my Makefiles and gnuplot command files and everything, and suddenly all looked almost right. There are still a few issues:

  • if you select an invalid font in gnuplot (set terminal fig … font "foo"), it will simply ignore that font, without any warning
  • while you can tell it to set the “special” fig flag on the emmitted text (set terminal fig textspecial) , you can’t give gnuplot a LaTex font name, since it only has definitions for the normal PostScript fonts; this can be worked around via giving it a PostScript font that has the same index as the desired LaTex font
  • the font size specified in gnuplot is not really influencing the actual fonts used in LaTex
  • as xfig doesn’t know the actual font rendering box as computed by LaTex, you lose the (simple, but good) WYSIWYG features, and need to go back and forth between the created PDF and xfig to change the actual layout
  • if you use a \resizebox{} around the inclusion of the pdf_t file, the fonts are scaled too, which is plain wrong :(

So while this setup has some drawbacks, it works well enough. I was happy to simply have a well defined workflow.

But then I wanted to do a simple graph (of a 3-wire sorting network), and I realised that positioning all of that using xfig will be painful. I kept stumbling upon pgf and tikz during my previous investigations, and I said I should check it out.

Wow. tikz and pgfplot. While you lose a bit on the graphing capabilities, you also gain a lot. Basically one can replace both xfig (instead of hand-drawn diagrams you can actually write them in code, programatically, no more guessing) and gnuplot (so that you have consistent fonts/scaling). I was so amazed at this excellent combination that I’ve converted for all my new docs to this.

And now I have the problem that I keep wanting to write LaTex code in ikiwiki :)

PS: Yes, I’ve been busy lately, so busy that my Debian work has mostly been suspended. Should be back in about a month or so.