Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Because I find myself relocating frequently within a long notebook divided into sections, subsections, & subsubsections, I would like to display the identifying information for the section, etc. that I'm in at any point in time. I have in mind something similar to a readily visible header or footer that one might display within a word processing document or textbook. For example, if I am working somewhere within a section titled "4.2) Geometry of Matrix Transformations of the Plane", I would like that section identifier displayed conveniently and updated when my further relocating within the notebook takes me into a different section. My aim is not to compose a textbook/article/etc.; it's the far more humble purpose of helping myself as I work my way through an assigned textbook, making notes, computations, plots, and so forth and jumping this way and that throughout the notebook as the semester progresses. Suggestions for someone who is not a programmer? Thx!

share|improve this question
This is easy to set up for printing page headers etc. but just to be clear you want this in a working environment not on a printed page right? –  Mike Honeychurch Sep 29 '13 at 1:26
add comment

1 Answer

It isn't a simple question. My current solution is

SetOptions[EvaluationNotebook[], DockedCells -> Cell[#, "Output", CellMargins -> 0]] &@
  With[{GetTOC = 
      Cell[name_, style : "Section" | "Subsection" | "Subsubsection", ___] :> {style, name},
       Infinity] /. {"Subsubsection", x_} :> x[] //. 
     {x___, {"Subsection", y_}, z : Except[_List] ..., 
       w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} //. 
     {x___, {"Section", y_}, z : Except[_List] ..., 
        w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} &}, 
    DynamicModule[{TOC = GetTOC[]}, Row@
      {Button["Update", TOC = GetTOC[]],
        Dynamic@Refresh[" " <> StringJoin @@ (ToString[#] <> "." & /@ #) <> 
        " " <> If[Length[#] == 0, "", 
         Head@Catch@Fold[If[Length[#] >= #2, #[[#2]], Throw[#]] &, TOC, #]] &[
      CurrentValue[NotebookSelection[], {"CounterValue", #}] & /@ \
{"Section", "Subsection", "Subsubsection"} /. {x___, 0 ...} :> {x}], 
     UpdateInterval -> 1]}]]

enter image description here

It shows the DockedCell with the number and the name of the section (subsection, subsubsection) in which the pointer is located.

It updates every second. The button "Update" is needed only if you change the names of the sections.

The number of the current section can be easily obtained by CurrentValue[NotebookSelection[], {"CounterValue", "Section"}]. But as far as I know there is no standard option to obtain the names of the sections. So I parse the current notebook to obtain the tree of the TOC (table of contents).

share|improve this answer
add comment

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.