I have a .nb file including several large parts so that finding something in it and even seeing whole is difficult. I think it is better to put a "table of content" in start of the file and link them to relevant section. I expect that all sections to be in a close form at start and expand just after someone clicks on their name on "table of content". What is the best way to do so? or someone knows a better way to organize my file? Thanks in advance.
2 Answers
How about then just start very simple and build up:
Choose File/New/Notebook. This will bring up the default style sheet. Should read up on style sheets later.
Immediately, choose Cell/Groupings/Manual groupings. This will prevent Mathematica from automatically, and usually incorrectly grouping cells together. However it comes with a (minor) cost of you having to group them.
Now lets create a section of code and then group it manually: Type in myf[x_]:=x^2 and hit the enter key. This creates an input cell and output cell. You can see the cell bars (the small left-facing brackets) on the right side of the page.
Now below those cells, type Plot[myf[x],{x,0,1}] and hit enter. This again creates an input and output cell and you can see the cell bars at the right.
Now lets group these into a Section. Place cursor above the input cell where you entered myf[x_]. Next choose Format/Style/Section. This creates a Section cell. Type a heading for it such as "First section".
Finally, let's group all the cells together into a section block with a tab. Click on the "Section" cell bar at the right of the screen (the little left facing brackets). Now, go to the last cell you want in this section, and while holding the shift key, click it's bar at the right of the screen. This will highlight all the cell bars from the first one to this one.
Now, hold down the Shift and Ctrl key and press the "g" key (for "group"). This will now group all the cells you selected in one group and now the Section cell has a "tab" (up and down arrow that you can now expand and collapse the section.
Sometimes you need to "ungroup" them. Simply highlight the first and last cell bars and then hold the Shift and Ctrl key and press "u" (ungroup) to ungroup them.
Finally, I should point out there are some idiosyncrasies with the cell groupings. For example, suppose you want to insert a block of selected cells that you selected elsewhere say between cell x and cell x+1 in a section. Generally, just put the cursor there and press Ctrl-v. However I have notices sometimes this ungroups the section. Not sure why. To avoid this, I first put the cursor where I want to insert the block, press enter, this then creates an input cell while maintaining the grouping, and then insert the cell blocks into this newly created cell. Just keep and eye on the cell brackets.
- 2,904
- 1
- 9
- 14
-
Many Thanks, it's great. Also for building a table of content we can use 'Hyperlink' and 'cell tag' – Wisdom Dec 06 '20 at 10:22
Try this code: ResourceFunction["NotebookOutlineMenu"][] then you can paste the output anywhere in your notebook and it dynamically updates with chapters/sections/subsections etc.. Information on this is from Wolfram documentation- "NotebookOutlineMenu".
Alternatively or simultaneously you can create a Cell Tag (Menu---Cell>Cell Tags>Add/Remove Cell Tags) that you can find again by going to menu Cell>Cell Tags>Find Cell Tags. Also a tip to organise your notebook by creating well defined sections, subsections and subsubsections for creating collapsible parts to your document as you develop your notebook to see a clear trail of your document. Example image shown below 
- 69
- 4
{a,b,c}=GenerateData[...],xA=DoComputation[a],xB=DoComputation[b],xC=DoComputation[c],Plot[{xA,xB,xC}],AnalyzeData[xA,xB]. In order to make your functions flexible make use of optional arguments. See also here – yarchik Dec 06 '20 at 08:22