Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Mathematica, notebooks (in fact all expressions) have a tree-like structure. In this regard, they are similar to XML files. For XML, one can travel through the document structure using tools like XPath. What would be the equivalent in Mathematica so that beginning with NotebookSelection one navigates towards the outermost Notebook until one reaches a parent that matches certain pattern (say Cell[__,”Input”,___]). If the pattern is reached, the selection is enlarged; otherwise, the selection stays the same.

To make the problem more interesting: is it possible to do it without changing the selection (the highlighted region should stay the same unless enlarged to avoid flickering) and without copying the notebook to a hidden one (the original notebook might be really large)?

Any pointers will be appreciated.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.