# how to efficiently jump between sections in a notebook?

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?

• 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... – Szabolcs Nov 27 '13 at 22:19
• Take a look at CellTags, NotebookLocate and CreatePalette. – Kuba Nov 27 '13 at 22:31
• 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. – Szabolcs Nov 27 '13 at 22:31
• 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 ... – Rho Phi Nov 27 '13 at 22:55
• 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. – Szabolcs Nov 28 '13 at 1:28

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];
StanPrivategotoSection[section_String] :=
Module[{listOfLists, position},
ShowNotebook[notebookName];
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[cells[[#]] &,
Cell[___, "Subsection", ___]]]]]];
StanPrivatetemp = sectionNames[[1]];
Framed[
ListPicker[
Dynamic[StanPrivatetemp,
Function[{v, e},
(StanPrivategotoSection[v[[1]]];
e = v
),
HoldRest]],
sectionNames,
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"]