separate reference consumption and replacement

previous behaviour was to replace referencable objects (figures,
sections, math) at the same time as appending their reference info to the
ReferenceManager internal state.

Now we 'consume' and replace reference objects in separate stages. This
allows us to pass over text and get all the reference info without
modifying it.