Message Boards Message Boards

Is there a way to tag cells and hyperlinks programmatically?

Posted 12 years ago
Does anyone know of a way (or have an example) of how to programmatically create CellTags and Links in StyleSheet definition?

For example, suppose I have a table of contents---can link automatically to a chapter or a section.  This assumes that I can create a CellTag automatically in a Chapter Style, and that CellTag would use the current cells Counter in its tag name.

Another example, suppose I want to have a section of footnotes.  One would want to link from the text to a particular footnote, and then link back from the footnote to the position in the text (i.e., a "back button" from a section of footnotes).  Again, one would need to use Counters that update in a similar way to LaTeX.

I looked in the TextBook.nb style sheet definitions briefly, but couldn't find anything that I could modify to do this.
POSTED BY: W. Craig Carter
3 Replies
If all you're looking for is an automatically generated unique identifier for each cell you want to link to, then you could use CellIDs.  If you set the notebook option CreateCellID -> True (which you can set in the style sheet), then every cell created in that notebook will have a unique CellID.  The downside is that you'll have to roll your own code to generate the links, but at least you're guaranteed to have the identifiers set.

-Brian
Some things to consider: when inserting an automatic numbering object, one can select a cell tag as an attribute of the target, and then the inserted counter becomes a link to that object. When clicking the counter to follow the link, you can execute FrontEndTokenExecute[nb, "HyperlinkGoBack"] to return to the cell the counter is in.

So you could make this go-back functionality part of a button in a cell frame label for the style definition of a reference, for example. But a style definition will not resolve the need to properly identify the target cell when inserting the citation. That still requires user interaction. You can define that interaction to begin by selecting the target cell, which could get an automatically created unique cell tag written to it, and then prompt the user to insert the citation, which would be written as a counter with that same tag.

Methods of managing cell tags include:

FrontEndExecute[FrontEnd`SelectionAddCellTags[nb, "MyTag"]
FrontEndExecute[FrontEnd`SelectionRemoveCellTags[nb, "MyTag"]
SetOptions[NotebookSelection[nb], "CellTags" -> "foo"] (* or  "CellTags" -> {"foo", "fun"} *)
CurrentValue[NotebookSelection[nb], "CellTags"]

Brian mentioned CellIDs; an example of searching for those would be:

NotebookFind[nb, 426769483, Next, CellID]

AK
POSTED BY: Andre Kuzniarek
Are you asking for a style definition that assigns a unique CellTag to each cell of that style? I don't believe there is any way to assign CellTags via a style definition.

Have you tried using AuthorTools to generate a table of contents?
POSTED BY: Larry Adelston
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