Message Boards Message Boards

[✓] Cell tag containing a comma?

GROUPS:

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 Pázsit
Answer
2 months ago

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
Answer
2 months ago

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 Pázsit
Answer
2 months ago

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
Answer
2 months ago

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 Pázsit
Answer
2 months ago

Group Abstract Group Abstract