Re: Version 6 "Mathematica Book" - updated and expanded

*To*: mathgroup at smc.vnet.net*Subject*: [mg79985] Re: [mg79937] Version 6 "Mathematica Book" - updated and expanded*From*: "Thomas Muench" <thomas.muench at gmail.com>*Date*: Fri, 10 Aug 2007 01:46:01 -0400 (EDT)*References*: <200708090918.FAA21022@smc.vnet.net> <46BB3084.5080202@tue.nl>

It is interesting that - again - there is a helpful function (HelpLookup) which is not documented. At least searching for it doesn't turn up any results in the Documentation Center. I have a question: Considering my code as well as Fred's code, I wonder if there is an easy way to change the style of a cell (programmatically). In my code for the Mathematica Book I use some sort of hack, and Fred's version is rather complicated as well, although it at least looks like sound programming. What I expected to work (but it doesn't) is something like SetOptions[<cell to change>,CellStyle->"newstyle"]; NotebookWrite[nb,<cell to change>] But that sort of code prints the cell in its old style. If you look at the InputForm of the newly printed cell, it has CellStyle->"newstyle" as an option, but that doesn't do anything apparently, since "oldstyle" is still the second argument of Cell[...]. Any ideas? Thomas On 8/9/07, Fred Simons <f.h.simons at tue.nl> wrote: > > I was very surprised and amused that almost exactly at the time when I > wanted to post on this topic to mathgroup, the message of thomas entered > my mailbox. He did a lot more than I did, but with the same improvements > of the original version of the book as in my work. So my first idea was > not to post my version. But there are some differences in the way we > arrive at these improvements which I think are worth mentioning. Roughly > speaking, the technique discussed so far is to find in the tutorials > the complete cells with the links, often in a TOCChapter cell, then copy > these cells and after some modifications paste them into the Mathematica > book. > > My approach uses the new function Documentation`HelpLookup. For example, > > Documentation`HelpLookup["paclet:tutorial/AlgebraicCalculationsOverview"] > > opens the documentation on Algebraic Calculations. > > Also new in Mathematica 6 is the function Button. The first argument is > the text on the button, the second argument the action to be done. > Further, there are a lot of options for the appearance of the button. > For example: > > Button["Algebraic Calculations", > Documentation`HelpLookup[ > "paclet:tutorial/AlgebraicCalculationsOverview"]] > > Button["Algebraic Calculations", > Documentation`HelpLookup[ > "paclet:tutorial/AlgebraicCalculationsOverview"], > BaseStyle -> "Section", Appearance -> None] > > Hence the Mathematica book will consist of cells such as the following > one. Clicking on the text opens the tutorial. > > CellPrint[ > ExpressionCell[ > Button["Algebraic Calculations", > Documentation`HelpLookup[ > "paclet:tutorial/AlgebraicCalculationsOverview"], > BaseStyle -> {"Section", ShowStringCharacters -> False}, > Appearance -> None], "Section"]] > > It would have been very nice if the Mathematica function NotebookWrite > would be able to write ExpressionCells and TextCells. But as far as I > can see, this not (yet?) implemented. So before writing such a cell to a > notebook, we are forced to convert the cell contents to boxes. > > My implementation for the Mathematica book simply runs through all > overview tutorials and looks for cells with second argument TOCxxx. The > first argument of such a cell contains both the text to be displayed on > the button (no reason for beautifying ugly) and the corresponding > paclet. For whom is still interested, here is the code. > > overviews = FileNames["*Overview.nb", > ToFileName[{$InstallationDirectory, "Documentation", "English", > "System", "Tutorials"}]]; > (*Find "Overview.nb" files in the tutorials-directory*) > > orderOfChapters = {{36, 3, 8, 31, 4, 47, 1, 39, 32, 14, 20, 16, 18, > 17, 11, 43}, {10, 13, 35, 48, 22, 45, 9, 27, 38, 42, 44, 23, 12, > 26, 15, 40, 41}, {30, 25, 2, 21, 5, 7, 37, 19, 33, 34, 28, 29, 6, > 46, 24}}; > (*The file list is alphabetical-this is the order in which the \ > chapters should appear*) > > mainChapters = {"A practical introduction to Mathematica", > "Principles of Mathematica", > "Advanced Mathematics in Mathematica"}; > (*The three main headings*) > > mmabook = > CreateDocument[{}, > StyleDefinitions -> ToFileName["Book", " Textbook.nb"]]; > NotebookWrite[ > mmabook, {Cell["The Virtual Mathematica Book (v6)", "Title"], > Cell["A collection of links to the tutorials present in the \ > Mathematica 6.0 Documentation Center, arranged in the order of \ > chapters in \"The Mathematica Book\".", "Author"]}]; > > Do[ > NotebookWrite[mmabook, > Cell[mainChapters[[i]], "Subtitle", > CellMargins -> {{Inherited, Inherited}, {15, 30}}, > ShowGroupOpener -> True]]; > Do[ > nb = NotebookOpen[file, Visible -> False]; > While[(SelectionMove[nb, Next, Cell]; > z = NotebookRead[nb]) =!= {}, > Which[z[[2]] === "TOCDocumentTitle", > If[ MatchQ[z[[1]], TextData[_List]], > z[[1]] = With[{zz = (z[[1]] /. StyleBox[x_, ___] :> x)[[1]]}, > Fold[#1 <> "" <> #2 &, zz[[1]], Rest[zz]]]]; > With[{pac = > "paclet:tutorial/" <> > StringReplace[ > file, {DirectoryName[file] -> "", ".nb" -> ""}]}, > NotebookWrite[mmabook, > Cell[BoxData[ > ToBoxes[Button[z[[1]], Documentation`HelpLookup[pac], > BaseStyle -> {"Subsection", > ShowStringCharacters -> False}, Appearance -> None]]], > "Section", ShowGroupOpener -> True]]], > StringMatchQ[z[[2]], "TOC*"], > type = > Pick[{"Subsection", "Subsubsection", > "Subsubsubsection"}, {"Chapter", "Section", "Subsection"}, > StringDrop[z[[2]], 3]]; > If[type == {}, z[[1]] = "", type = type[[1]]]; > zz = > Cases[z[[1]], > ButtonBox[x_, ___, ButtonData -> y_, ___] :> {x, y}, > Infinity]; > If[Length[zz] > 1 && Equal @@ zz[[All, 2]], > zz = {{Fold[ #1 <> "" <> #2 &, First[zz[[All, 1]]], > Rest[zz[[All, 1]]]], zz[[1, 2]]}}]; > If[zz != {}, > With[{pac = zz[[1, 2]]}, > NotebookWrite[mmabook, > Cell[BoxData[ > ToBoxes[Button[zz[[1, 1]], Documentation`HelpLookup[pac], > BaseStyle -> {type, ShowStringCharacters -> False}, > Appearance -> None]]], type, > ShowGroupOpener -> True]]]]]]; > > NotebookClose[nb], > {file, overviews[[orderOfChapters[[i]]]]}], > {i, 1, Length[mainChapters]}]; > > SelectionMove[mmabook, All, Notebook]; FrontEndExecute[ > FrontEndToken["SelectionCloseAllGroups"]]; FrontEndExecute[ > FrontEndToken["OpenCloseGroup"]]; > SelectionMove[mmabook, Before, Notebook]; > > Fred Simons > Eindhoven University of Technology > >

**References**:**Version 6 "Mathematica Book" - updated and expanded***From:*thomas <thomas.muench@gmail.com>