4
$\begingroup$

I want to assign each cell in my current notebook a tag so that I can rerun cells with specific tags later in the notebook (Using a method similar to this answer).

My questions are

  • How do I assign cells in my current notebook tags?
  • How do I view the tags that I have assigned?
$\endgroup$
0

2 Answers 2

7
$\begingroup$

You can use the menu item Cell | CellTags to do this. If you want to inspect and modify CellTags programmatically, you can use CurrentValue and SetOptions. For example:

cell = PreviousCell[];
CurrentValue[cell, CellTags]

{}

Change the tag:

SetOptions[cell, CellTags->"FOO"]

Check:

CurrentValue[cell, CellTags]

"FOO"

Another useful function is Cells, which will return a list of Cell objects satisfying various criteria.

$\endgroup$
1
$\begingroup$

For thoose looking at this question in the future if you want to label the first 3 input cells cell tags use the following

{cell1, cell2, cell3} = Cells[CellStyle -> {"Input"}][[1 ;; 3]]
SetOptions[cell1, CellTags -> {"FOO"}]
SetOptions[cell2, CellTags -> {"FOO2"}]
SetOptions[cell3, CellTags -> {"FOO3"}]
(*Check cell tags*)
CurrentValue[{cell1, cell2, cell3}, CellTags]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.