Preparation of titanium nitride (TiN) and titanium carbide (TiC) from a polymeric precursor