No, I don't know of an easy way. I've done something like the following before to create random homework assignments from a template (before there was NotebookTemplate
):
nb = NotebookGet[..<notebook>..];
newnb = NotebookPut[nb /. "oldtag" -> "newtag"]
This would work if "oldtag"
appears only in CellTags
and the hyperlink Button
in the notebook expression. Since the notebook expression is a complicated mess of cells, boxes, etc., this is both rare (well, depending on the string "oldtag") and hard to know in advance, which is more worrisome. This may be more robust, although I don't know the range of forms for ButtonData
. There is another form for linking to a cell in another notebook (and for URLs).
nb = NotebookGet[..<notebook>..];
newnb = NotebookPut[nb /. {
HoldPattern[CellTags -> "oldtag"] -> CellTags -> "newtag",
HoldPattern[CellTags -> {a___, "oldtag", b___}] :> CellTags -> {a, "newtag", b},
HoldPattern[ButtonData -> "oldtag"] -> ButtonData -> "newtag"
}]
This creates a new, untitled notebook, which you can then save, either by hand or with NotebookSave[]
.