Is there a command to obtain all the CellTags
and the style of the cell they are in? This question is derived from this question which was answered by jVincent. Based on his answer I want to be able to create a function which takes in a string. Looks for the text "\ ref{String_}" (There should be no space between \ and ref, I'm not sure how to avoid mathjax here, if you know how to please make the proper edits) and uses that information to insert a CounterBox
. The problem is that the type of counterboxes I want to insert require two arguments, the first is the style of a cell and the second is the CellTag
. So really, this is a two part question:
1) How do you find out all the CellTags
available? The obvious answer is by going to Cell > Add/Remove Cell Tags
. This only works if you have a cell selected. If you give a cell a cellTag it will appear under "All cellTags in the notebook". So obviously Mathematica keeps a list of all the CellTags available in the notebook. The question is, how do we get this list?
2) Once we found out if this celltag is available, is there a way to obtain the style of the cell in which it is in? For instace, I might create a "DisplayFormulaNumbered" cell, and tag it as "eq1".
So why all of this? The idea is to have some cell with text like this:
From equation ref{eq1} we then ...
Note that I did not include the backlash before ref because I don't know how to avoid mathjax from transforming it at this point. Back to the idea, now using jVincent's code we could create a button that when the cell is selected, it looks for all instances of ref, grabs the input (in this case eq1), looks to see if it is a valid tag, if it isn't then it just issues a warning telling you that there's no valid tag, otherwise it replaces the ref section for the counterbox which as inputs the Cell style in which the tag is contained and the tag.
Answer
First question, try
nb=InputNotebook[];
NotebookTools`NotebookCellTags[nb]
Second question, a start could be
NotebookFind[nb, "lakj", All, CellTags, AutoScroll -> False];
Flatten[{NotebookRead[nb]}][[All, 2]]
EDIT, thanks John Fultz
That last line is inefficient and can fail at times. A better alternative is
"Style" /. Developer`CellInformation[nb]
Comments
Post a Comment