Archive for March, 2006

Editing EPS/PDF files in Linux

Wednesday, March 29th, 2006

I recently wanted to make small changes to EPS charts I had once generated. It seems that EPS-editing is not so simple, but i have at least two solutions that works:

1. Import the file into CorelDraw and save back as EPS. I had previously been importing EPS files there and the results were amazingly good (BTW: choose “interpreted EPS”, not the one decoded by the system driver!).
2. Use `pstoedit` to save it to a `.fig` file, use xfig and then export back as EPS.

pstoedit -f “fig:-startdepth 999″ .eps .fig

I tried the last option so far and in kindof worked. The resulting file looked ok, but the bounding box was somewhat changed (that was probably the problem in the original file). Also the resulting EPS file was 10 times bigger then the original one. Well… nothing is perfect. Wonder how the CorelDraw solution works…

  • [Calatrava lectures @ MIT](http://web.mit.edu/civenv/Calatrava/) – transcripts and a lot of multimedia content. A must see if you’re interested in Calatrava’s works. (0)

The ultimate Latex Makefile

Friday, March 24th, 2006

After a long time of trial and errors (a.k.a. _procrastination_), I finally finished my “make phd” script for my thesis.
The script uses bibtex (rerunning Latex as many times as needed) and can use either Latex or PDFLatex (if you want to use hyperref and nice PDF stuff) and if necessary converts all your images to PDFs.

You can use it like this:

make all <- build the document using latex, dvips, epstopdf
make clean <- clean up (remove all intermediate (and final), including converted eps images (in using pdflatex)
PDF=true make all <- builds the document using PDFLatex

Here's the main makefile:

# Makefile for Tadek's thesis
# This file builds a paper - PDF file and if (PDF is defined) a PDF with hyperlinks
#
# Written (c)2005 by Tadeusz Pietraszek (pie@zurich.ibm.com)
# $Id: Makefile 597 2006-01-12 15:43:59Z pie $
#
#Egrep trick from: http://xpt.sourceforge.net/techdocs/Latex/
#MakefileForTeX/Latex08.000.html

TEXFILES=thesis.tex
#TEXFILES=$(wildcard *.tex)

TARGETS=$(patsubst %.tex,%.pdf,$(TEXFILES))

RERUN = "(There were undefined references|Rerun to get (cross-references|the bars) right)"
RERUNBIB = "No file.*\.bbl|Citation.*undefined"

phd: all

all: all-recursive $(TARGETS)

clean: clean-recursive
  rm -f *.aux *.log *.bbl *.blg *.brf *.cb *.ind *.idx *.ilg  \
        *.inx *.ps *.dvi *.pdf *.toc *.out *.lot *~ *.backup

all-recursive:
  for dir in $(wildcard *); do if [ -d $$dir ] && [ -f $$dir/Makefile ]; then cd $$dir; $(MAKE) all; cd ..; fi; done

clean-recursive:
  for dir in $(wildcard *); do if [ -d $$dir ] && [ -f $$dir/Makefile ]; then cd $$dir; $(MAKE) clean; cd ..; fi; done

ifndef PDF
#building the document using .dvi, .ps, -> .pdf
%.dvi: %.tex
  echo $(SHFILES)
  latex $<
  egrep -c $(RERUNBIB) $*.log && (bibtex $*;latex $<); true
  egrep $(RERUN) $*.log && (latex $<) ; true
  egrep $(RERUN) $*.log && (latex $<) ; true

%.ps: %.dvi
  dvips -Ppdf -ta4 -G0 $<

%.pdf: %.ps
  ps2pdf $<

else

#this is making the same file using pdfelatex
%.pdf: %.tex
  pdfelatex $<
  egrep -c $(RERUNBIB) $*.log && (bibtex $*;pdfelatex $<); true
  egrep $(RERUN) $*.log && (pdfelatex $<) ; true
  egrep $(RERUN) $*.log && (pdfelatex $<) ; true

endif

My pictures are built using the following Makefile (in a subdirectory of the main paper):

# Makefile for Tadek's thesis - pictures!
#
# Supports two targets: all and clean - and calls other makefiles recursively
# If PDF is defined, converts EPS into PDFs
#
# $Id:$
#

#If you want to add your custom grpahic file .foo you need to
#
#FOOFILES=#(wildcard *.foo)
#EPSFILES=... $(patsubst %.foo,%.eps,$(FOOFILES))
#
#%.eps: %.foo:
# foo2eps -o $*.eps $<

#source files
DIAFILES=$(wildcard *.dia)
INKSCAPEFILES=$(wildcard *.svg)

#target files (only those that we are building, and will be deleted)
EPSFILES=$(patsubst %.dia,%.eps,$(DIAFILES)) $(patsubst %.svg,%.eps,$(INKSCAPEFILES))

ifdef PDF
#target files (if we're building PDFs)
PDFFILES=$(patsubst %.eps,%.pdf,$(EPSFILES) $(wildcard *.eps))
else
PDFFILES=
endif

  • [Python2.3 Quick Reference](http://rgruet.free.fr/PQR2.3.html) – useful. (0)
  • [article](http://xkr.us/articles/javascript/encode-compare/) on different “encode” functions in Javascipt and the differences between them. Useful. (1)
  • [exploring ActiveRecord](http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord) – an interesting whitepaper on Ruby on RAILS architecture and how it can be adopted to Java (thanks to James for this pointer). (0)
  • [XMaps library](http://xmaps.busmonster.com/) is a great library enhancing GoogleMaps with custom on-the-fly made icons, polylines and a lot of cool stuff. Neat, but has some rendering problems with Firefox (and also the development seems to have stalled). (0)

Adding binary data to DOM tree in Python (charset encoding problems)

Wednesday, March 15th, 2006

When I was reading some stuff from the database (Postgres) and adding it to a DOM tree in Python, I encountered a strange encoding problem (that’s got something to do with UTF-8).

Ultimately the solution was to set the client encoding to utf-8 in postgres:

alter user set client_encoding to ‘utf-8′

In the process I also discovered, that if you add binary (not unicode) data to a DOM tree you should decode it first:

.decode(“utf-8″)

And encode it back to utf-8 when writing XML:

doc.toprettyxml(indent=” “, encoding=”utf-8″))

Obviously, if the variable contains UFT-8 to begin with, there’s not much point in encoding it back and fourth, however, if other encodings are involved, it should be done this way.

  • [safari bookshelf](http://safari.oreilly.com/) is an affordable subscription-based access to (not only) O’Reilly books. It looks like a good place to start if you don’t know which book you’re looking for. The downside is a monthly subscription fee (from $10). (1)

Editing Python programs in VI

Monday, March 6th, 2006

I recently discovered that if you have to edit your python code from `vi`, the following definiton is very useful:

:se et ts=8 sw=4 softtabstop=4 smarttab

But other than certain rare cases, I’d recommend to run [PyDev](http://pydev.sourceforge.net/) in Eclipse. There’s also a nice [tutorial](http://www-128.ibm.com/developerworks/opensource/library/os-ecant/) if you need it.