+
+ case MATH_HULL_CODE: {
+ // check for equation labels and resolve duplicates
+ InsetMathHull * ins = it->asInsetMath()->asHullInset();
+ std::vector<InsetLabel *> labels = ins->getLabels();
+ for (size_t i = 0; i != labels.size(); ++i) {
+ if (!labels[i])
+ continue;
+ InsetLabel * lab = labels[i];
+ docstring const oldname = lab->getParam("name");
+ lab->updateCommand(oldname, false);
+ // We need to update the buffer reference cache.
+ cur.forceBufferUpdate();
+ docstring const newname = lab->getParam("name");
+ if (oldname == newname)
+ continue;
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in);
+ itt != i_end; ++itt) {
+ if (itt->lyxCode() == REF_CODE) {
+ InsetCommand * ref = itt->asInsetCommand();
+ if (ref->getParam("reference") == oldname)
+ ref->setParam("reference", newname);
+ } else if (itt->lyxCode() == MATH_REF_CODE) {
+ InsetMathHull * mi = itt->asInsetMath()->asHullInset();
+ // this is necessary to prevent an uninitialized
+ // buffer when the RefInset is in a MathBox.
+ // FIXME audit setBuffer calls
+ mi->setBuffer(const_cast<Buffer &>(buffer));
+ if (mi->asRefInset()->getTarget() == oldname)
+ mi->asRefInset()->changeTarget(newname);
+ }
+ }
+ }
+ break;
+ }
+