Perhaps it's some sort of cruel joke we're not in on but everything I've been able to find on the Internet about tilt-compensated headings from magnetometers leads to this paper [warning, it's a PDF]: http://www.ssec.honeywell.com/position-sensors/datasheets/sae.pdf
In it there is an algorithm for tilt-compensation. It's wrong. Here's what it should be: http://gist.github.com/322555
Ryan Beall is the man.