Make IdMap#save more atomic: if an error occurs it should not leave the ID map file in an intermediate state.
Only set KCODE when on Ruby 1.8
Add chapter movement detection.

When one adds a new chapter to a document, all following chapters will
have their chapter number changed, so they need to be reassociated with
their IDs in the ID map. Previously we relied on fuzzy text matching,
but this has proven to be a suboptimal strategy:

 * The fuzzy text matching would match the chapter number as well,
   causing bad results in some cases.
 * All reassociated entries are marked fuzzy.

The new algorithm will associate with the ID that has the same title,
but a different chapter number. If there are multiple candidates then
it will choose the chapter whose number is the closest to the original.
Furthermore, IDs that are associated this way will not be marked fuzzy.