Re: Table of Contents
- To: mathgroup at smc.vnet.net
- Subject: [mg85438] Re: Table of Contents
- From: David Reiss <dbreiss at gmail.com>
- Date: Sun, 10 Feb 2008 05:21:55 -0500 (EST)
- References: <foejuo$huu$1@smc.vnet.net> <fogif4$3c1$1@smc.vnet.net>
Whoops! My mistake... In the place where it says SetOptions[nb, System`CellID -> True]; replace it with SetOptions[nb, System`CreateCellID -> True]; Sorry about the error.... If you have Mathematica version 6 or greater then this should now work. Best regards, David On Feb 9, 4:18=A0am, Larry <LJ2... at yahoo.com> wrote: > Sir, I tried you code in two cells in one notebook but it > produced no output. > > Then I tried putting TOCForNotebook definition cell in one > nb and the command TOCForNotebook[] in another nb, also no > output. I'm curious how this is supposed to work. Thanks. > > David Reiss wrote: > > Here is an example of a function that, when executed in the notebook > > in question, will generate a set fo cells at the top of the notebook > > that are hyperlinks to the section cells: > > > ClearAll[TOCForNotebook]; > > > TOCForNotebook[] := > > =A0 Module[{nbr, data, cells, nb}, > > > =A0 =A0nb = EvaluationNotebook[]; > > > =A0 =A0SetOptions[nb, System`CellID -> True]; > > > =A0 =A0SelectionMove[nb, All, Notebook, AutoScroll -> False]; > > =A0 =A0NotebookWrite[nb, NotebookRead[nb]]; > > > =A0 =A0NotebookFind[nb, "Section", All, CellStyle]; > > =A0 =A0nbr = NotebookRead[nb]; > > =A0 =A0data = > > =A0 =A0 nbr /. {Cell[x_, "Section", ___, z : (CellID -> w_), ___] :> {x,= > > =A0 =A0 =A0 =A0 w}}; > > > =A0 =A0cells = Function[x, > > =A0 =A0 =A0 =A0 TextCell[ > > =A0 =A0 =A0 =A0 =A0Button[TextCell[#[[1]], "Hyperlink"], > > =A0 =A0 =A0 =A0 =A0 NotebookFind[x, #[[2]], All, CellID], > > =A0 =A0 =A0 =A0 =A0 Appearance -> "Frameless"], > > =A0 =A0 =A0 =A0 =A0"Text"]][nb] & /@ data; > > > =A0 =A0cells = First[ToBoxes[#]] & /@ cells; > > > =A0 =A0SelectionMove[EvaluationNotebook[], Before, Notebook, > > =A0 =A0 AutoScroll -> True]; > > > =A0 =A0NotebookWrite[nb, cells]; > > > =A0 =A0]; > > > So, first execute this code somewhere in your current Mathematica > > session. =A0Then execute > > > TOCForNotebook[] > > > within the notebook in question. =A0If your Section cells have any > > formatting in them then this will not quite work as expected. =A0But it > > gives a start to others that would wish to modify this. =A0The code > > exposes several coding tricks that folks will perhaps find useful.... > > > -David > > A WorkLife FrameWork > > E x t e n d i n g MATHEMATICA's Reach... > >http://scientificarts.com/worklife/ > > > On Feb 7, 4:44=A0am, =8Aer=FDch Jakub <Ser... at panska.cz> wrote: > >> I use some notebooks as the collections of many small examples, which I= > >> allways start with cell styled as "Section" followed by usually one inp= ut = > > and > >> one output cell. The "Section" styled cell contains the name of the exa= mpl= > > e. > >> Does anybody know, how to create Table of Contents based on these secti= on > >> cells? Idealy it would contain interactive hyperlinks directly to the c= ell= > > s. > >> Thanks in advance > > >> Jakub