1
$\begingroup$

I have long notebook with several cells styles (Input, Output, Text, Section, Subsection,...), and I want to find words in the notebook only in the cells have same style.

It is very annoying when you have long notebook with same words in several cell styles and you want to find the words only in certain cell style.

For example, if I have the following notebook :

CreateDocument[{TextCell["test", "Section"], 
   ExpressionCell[test, "Input"], TextCell["test"], 
   TextCell["head one", "Section"], TextCell["test", "Section"], 
   ExpressionCell[Sin[x], "Input"]}];

How can I find the word test only in the Section style cells. If I use Find (Ctrl+f) and click Find Next, Find will search the next match wherever it is. I want the searching of the word to be only within Section style cells.

enter image description here

$\endgroup$
3
$\begingroup$
nb = CreateDocument[{TextCell["test", "Section"], 
   ExpressionCell[test, "Input"], TextCell["test"], 
   TextCell["head one", "Section"], TextCell["test", "Section"], 
   ExpressionCell[Sin[x], "Input"]}]

You can use NotebookFind on a subset of cells.

If[SelectionMove[#, Before, Cell]; NotebookFind[#, "test"] =!= $Failed, 
   #, 
   Nothing
] & /@ Cells[nb, CellStyle -> "Section"]

enter image description here

$\endgroup$
  • $\begingroup$ That is great. can you tell me how can I access the content of certain cell through its CellObject. For example, if I want to access the content of the Cell associated to the first CellObjec in the Out[47] in your answer, what should I do? The idea is I want to filter the result of the Cells[nb, CellStyle -> "Section"] and get only those CellObject associated to Cells containing "test". $\endgroup$ – Algohi Feb 1 '16 at 3:23
  • $\begingroup$ @Algohi It is already done. As you can see only two cells are returned out of three. $\endgroup$ – Kuba Feb 1 '16 at 6:48
  • $\begingroup$ Sorry, my mistake. Thank you $\endgroup$ – Algohi Feb 1 '16 at 17:12
  • $\begingroup$ @Algohi Great ;) tell my if you want to extend this or something. I don't have much time lately but I'm reading what's going on. Good luck. $\endgroup$ – Kuba Feb 1 '16 at 22:05

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.