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$
0

2 Answers 2

6
$\begingroup$

Here is an alternative:

Scan[SetOptions[#, CellTags -> {}] &, Cells[InputNotebook[]]]
$\endgroup$
1
  • 1
    $\begingroup$ This does evaluate faster. $\endgroup$
    – B flat
    Commented Oct 9, 2016 at 9:56
5
$\begingroup$

Try

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

This removes all the celltags in the current notebook.

$\endgroup$
7
  • $\begingroup$ Updated to overwrite the current notebook in one step $\endgroup$
    – dan7geo
    Commented Oct 9, 2016 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$
    – B flat
    Commented Oct 9, 2016 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
    Commented Oct 9, 2016 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
    Commented Oct 9, 2016 at 9:42
  • 1
    $\begingroup$ Updated to fix the error message $\endgroup$
    – dan7geo
    Commented Oct 9, 2016 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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