4
$\begingroup$

Below is some code that will delete all CellTags in a notebook where the CellTag is given by the string "temp".

NotebookLocate[{InputNotebook[], "temp"}];
SelectionMove[InputNotebook[], All, Cell];
SetOptions[NotebookSelection[], CellTags -> {}];

However, I want delete every CellTag in the notebook so there are none left at all. I tried replacing "temp" with * but that doesn't work. Any ideas here?

$\endgroup$
6
$\begingroup$

Here is an alternative:

Scan[SetOptions[#, CellTags -> {}] &, Cells[InputNotebook[]]]
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ This does evaluate faster. $\endgroup$ – Michael McCain Oct 9 '16 at 9:56
5
$\begingroup$

Try

NotebookPut[NotebookGet@#/.(CellTags->_)->Sequence[],#]&@InputNotebook[];

This removes all the celltags in the current notebook.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Updated to overwrite the current notebook in one step $\endgroup$ – dan7geo Oct 9 '16 at 9:29
  • $\begingroup$ I was about to say... I needed a solution for the current notebook. But looks like you got it solved. Thanks again! $\endgroup$ – Michael McCain Oct 9 '16 at 9:30
  • 1
    $\begingroup$ No problem! I must say it's really pleasing to see how Mathematica lets you seamlessly integrate pattern matching, pure functions, and the fact that everything is an expression. $\endgroup$ – dan7geo Oct 9 '16 at 9:34
  • 1
    $\begingroup$ @Kuba It did disappear from the notebook expression without any error messages in version 11.0 on Windows. I'm actually surprised that it works :D $\endgroup$ – dan7geo Oct 9 '16 at 9:42
  • 1
    $\begingroup$ Updated to fix the error message $\endgroup$ – dan7geo Oct 9 '16 at 9:44

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.