I have functions defined in some section of the notebook and some cells where I use these functions maaaaany pages below in the same notebook. If I want to go and change the definition of the function I need to climb up in the notebook, find the definition and change it, then climb down to the place where I was working and using these functions.

This is very inconvenient and looks like "navigation by sight". I was wondering how this can be made more efficient. For instance if it was a C++ or TeX source I would use the table of content of the file that my editor builds for me so that I can jump to the section where I define function clicking the TOC and then jump back to the original location either using "back" or again clicking the TOC.

Can anything like this be done in mathematica?

  • $\begingroup$ Did you know that you can close section by double clicking their cell bracket (vertical blue bracket on the right, spanning the whole section)? It's not what you asked for, but it's useful in long notebooks... $\endgroup$
    – Szabolcs
    Nov 27, 2013 at 22:19
  • 3
    $\begingroup$ Take a look at CellTags, NotebookLocate and CreatePalette. $\endgroup$
    – Kuba
    Nov 27, 2013 at 22:31
  • $\begingroup$ The Wolfram Workbench (Eclipse based IDE) does have such a dynamically updated "table of contents" BTW. I'm not sure if the IDEA plugin also supports it, but if it doesn't, you can suggest it. $\endgroup$
    – Szabolcs
    Nov 27, 2013 at 22:31
  • $\begingroup$ Checking it out, though it seems a major steering away from the current workflow with the usual Mathematica Front-End. the CellTags relatated command may provide a quick solution, sort of tagging my current Cell as "foo" going somewhere and then jump back to the "foo" cell. However seems far from optimal and the "human work" overhead is significant too ... $\endgroup$
    – Rho Phi
    Nov 27, 2013 at 22:55
  • $\begingroup$ The AuthorTools package may have the cell tags based thing implemented already. It does do some clickable TOCs, but I don't use it so I'm not too familiar with it ... Usually I simply collapse the sections I'm not currently using. You're right, the Workbench is for developing packages. It is not for interactive work and it's no replacement for the front end. If you have lots of definitions that you improve incrementally, you might find the Workbench useful. $\endgroup$
    – Szabolcs
    Nov 28, 2013 at 1:28

1 Answer 1


Here is one approach. This code is not re-entrant (cannot open on two windows at same time) - it uses a global variable for the gotoSection function - but this could be fixed.

SectionPicker[notebookName_String] :=
 (* problem running this twice *)
 (* simple fix = generate only one *)

 Module[{notebook, cells, sectionNames },
  notebook = Notebooks[notebookName][[1]];
  cells = Cells[notebook];
  Stan`Private`gotoSection[section_String] := 
   Module[{listOfLists, position},
    listOfLists = 
     Position[NotebookRead /@ cells, Cell[section, "Subsection", ___]];
    position = First[First[listOfLists]];
    SelectionMove[notebook, Previous, Cell, 1000];
    SelectionMove[notebook, Next, Cell, position];
  sectionNames = 
   Sort[Map[First[First[#]] &, 
     Map[NotebookRead , 
      Map[cells[[#]] &, 
       Position[NotebookRead /@ cells, 
        Cell[___, "Subsection", ___]]]]]];
  Stan`Private`temp = sectionNames[[1]];
     Function[{v, e},
       e = v
    FieldSize -> {{20, Infinity}, {5, Infinity}}, 
    Appearance -> "Frameless"],
   FrameStyle -> Black, RoundingRadius -> 10, 
   Background -> LightOrange]

MakeNotebookIndex[notebooks_List, width_Integer, height_Integer] := 
 Module[{button, listPickers},
  button = Button["Close", FrontEndTokenExecute["Close"]];
  listPickers = SectionPicker /@ notebooks;
  CreateDocument[Prepend[listPickers, button], 
   WindowTitle -> "Index", WindowSize -> {width, height}, 
   Saveable -> False]

Button["Index Snippets",
 MakeNotebookIndex[{"Snippets.nb"}, 300, 800], Method -> "Queued"]

enter image description here


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.