Message Boards Message Boards

[?] Cell tag containing a comma?

POSTED BY: Imre Pazsit
4 Replies

I don't know how to do it with the cell tags dialog, but you can add the option

CellTags->{"(Wolfram, 2017)"}

directly to a cell by editing the cell expression (menu Cell > Show Expression). Try it on a temp notebook first. If you accidentally mess up the editing, it can ruin the cell.

The option CellTags does not seem to be available in the option inspector (menu Format > Option Inspector...).

The only other way I can think of is to programmatically alter the cell in the notebook expression. For instance, write your own cell tag dialog. But that seems like it could be complicated.

POSTED BY: Michael Rogers

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[].

POSTED BY: Michael Rogers

Thank you for the hint - it works perfectly. This goes very fast when using the shortcut for opening the cell expression with shift-command-E (on a Mac). That helps me a lot! I wonder one more thing, although I suspect the answer is "no". Is there a way to update the hyperlinks in a text, pointing to a cell tag, if one changes the tag itself in the definition of the cell? That is, is there some "refresh" or "update" function which knows which cell the reference was made to, even if the cell tag is altered? This would be a real luxury and it is not much needed; I just wonder. It is not available in other systems either; if the label of a reference changed in latex, then one must update the references to that label also automatically.

POSTED BY: Imre Pazsit

Thanks very much for the further suggestions. I have not had time yet to try them, but the first one seems to be fine to do what I was looking for. I have not used these functions previously, but I will test.

POSTED BY: Imre Pazsit
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract