Message Boards Message Boards

[?] Cell tag containing a comma?

Is there a way to define a cell tag which contains a comma, so that the comma remains part of the cell tag, and not a separator which divides the tag into two different tags? The reason for the question is that in an article text I want to make references to the items in the bibliography/list of referenfces as hyperlinks which point to the corresponding items in the list of references. One can get the hyperlink into the text by clicking on the tag name. Now my references are in Harvard style, so the citation should be in the text something like "(Wolfram, 2017)". However, if I specify the cell tag as "(Wolfram, 2017)", then it becomes two tags, one is "(Wolfram" and the other "2017"). Thus, to get the citation into the text as a hyperlink, I need to create two hyperlinks, and connect them with a comma. I tried to embed the cell tag with the comma between citation marks, curly brackets, to precede the comma with a backslash etc., but nothing helped. Is there a way to get around this???

POSTED BY: Imre Pazsit
4 Replies

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
POSTED BY: Michael Rogers
POSTED BY: Imre Pazsit

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
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