4
$\begingroup$

I am building a table of contents using AuthorTools. I used it to create cell tags so the TOC can make hyperlinks, but then I decided I wanted to change them. But I am having trouble removing the old tags.

Here's what I did, after first making a few sample Section and Subsection cells:

<< AuthorTools`
nb = Notebooks[][[1]]
Paginate[nb]
MakeContents[nb, "Book", CellTagPrefix -> "c:"]

That worked as desired (and it made tag names like "c:1", "c:2"), but then I decided I wanted to change the prefix to "toc:". To remove the old tags, I tried:

RemoveCellTags[nb, StringExpression["c:", __]]

but it didn't change any cell's tags. The following did work, however, to remove just one tag:

RemoveCellTags[nb, "c:1"]

So I think I am using StringExpression wrong. And yet, this works fine:

StringCases[{"c:3", "c:4"}, StringExpression["c:", __] ]
(* OUTPUT: {{"c:3"}, {"c:4"}}  *)

So, what should the input be to RemoveCellTags to get rid of all tags that start with "c:"?

$\endgroup$
3
$\begingroup$

That package was written some time ago and has not been maintained. You'll need to make the following changes to the Common.m file in the package:

Find this code in the file

RemoveCellTags[nb_NotebookObject?NotebookOpenQ, pat_String] :=
Block[{tags},
  tags = NotebookCellTags[nb]//Flatten//Union;
  tags = Select[tags, StringMatchQ[#, pat]&];
  SelectionMove[nb, All, Notebook];
  SelectionRemoveCellTags[nb, tags];
  nb
]

and change it to

RemoveCellTags[nb_NotebookObject?NotebookOpenQ, pat:(_String|_StringExpression)] :=
Block[{tags},
  tags = NotebookCellTags[nb]//Flatten//Union;
  tags = Select[tags, StringMatchQ[#, pat]&];
  SelectionMove[nb, All, Notebook];
  SelectionRemoveCellTags[nb, tags];
  nb
]

When I did that it worked fine for me

$\endgroup$
  • 1
    $\begingroup$ And for the record, I found that Common.m file (on the Mac) in: /Applications/Mathematica.app/Contents/AddOns/Applications/AuthorTools $\endgroup$ – Seth Feb 14 '16 at 4:03

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.