Magnetometer tilt compensation without accelerometer
If the orientation of the device is fixed during the measurement then the computation is relatively straightforward as Dave Tweed has pointed out.

The main issue is calibration. A quick way would to establish at an approximate min, max for each x,y,z direction. Hopefully the zeros will lie roughly on the averages of the min and max. That is, this will give an \$x_\min\$, \$x_\max\$ and similarly for the other axes. From this estimate \$x_\text{zero} = {1 \over 2} (x_\min+x_\max)\$, and \$r_x = {1 \over 2} (x_\max-x_\min)\$, etc.

Then for a reading, compute \$x_\text{est} = { x_\text{meas}-x_\text{zero} \over r_x} \$, etc. Hopefully this will be in the range \$\pm 1\$.

I would check that \$|z_\text{est}|\$ is (1) no larger than some number (\$&lt;1\$ here) so that you get a meaningful direction, and (2) that it remains fairly constant for the duration of a measurement.

To compute an angle, use \$\text{atan2}(y_\text{est} , x_\text{est})\$ (check your particular API). To compute the difference with another (hopefully nearby) angle, just be careful with the \$\pm\pi\$ boundary.

This is obviously a quick overview with many optimisations and sanity checks omitted.