This stylesheet solution syncs CellTags to CellIDs every time (n) is clicked. To try this out...Execute the following code in a notebook to change alter its stylesheet.
Module[{event, label, cellid},
event = "MouseClicked" :> {
(*this scans and syncs ALL CellTags in the notebooks to their CellIDs everytime an (n) is mouse clicked*)
Scan[(cellid = "CellID" /. Developer`CellInformation[#];
SetOptions[#, CellTags -> ToString@cellid]) &,
Cells[InputNotebook[], CellStyle -> "DisplayFormulaNumbered"]];
(*this copies state of counter at CellTag.*)
CopyToClipboard@
Cell@TextData[{CounterBox["DisplayFormulaNumbered",
Replace[CurrentValue[ParentCell@ParentCell@EvaluationCell[],
CellTags], l_List :> First@l]]}]};
(*this labels DisplayFormulaNumbered cell as (n) using and creates a mouseclick event handler to initiate the copy when clicking any (n)*)
label = Cell[
TextData[{"(",
Cell@BoxData@
TagBox[CounterBox["DisplayFormulaNumbered"],
EventHandlerTag[{event}]], ")"}],
"DisplayFormulaEquationNumber"];
(*this embeds it all in stylesheet*)
SetOptions[EvaluationNotebook[],
StyleDefinitions ->
Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["Notebook"], CreateCellID -> True],
Cell[StyleData["DisplayFormulaNumbered"],
CellFrameLabels -> {{None, label}, {None, None}}]},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]]
Now that the stylesheet is changed, create a few "DisplayFormulaNumbered" cells and a text cell. In the text cell, make some references to the "DisplayFormulaNumbered" cells by clicking one of the (n)'s to copy and then paste it in the text cell. Notice, the reference will update when "DisplayFormulaNumbered" cells are added or deleted so that the reference stays intact. This works with as many references as you need.
If a "DisplayFormulaNumbered" cell is created by copy-pasting another "DisplayFormulaNumbered" cell, just click any (n) to resync all of them. I don't see this as a problem as one would click the new (n) anyways to create the reference which the point of having numbered cells in the first place.
CellID
as aCellTag
) i on a new cell, it does not seem to be so simple when applying it to a stylesheet modification (to me, at least). You’ll need to do something likeCellTags->ToString[CurrentValue[EvaluationCell[],CellID]]
, I think. $\endgroup$