Re: Version 6 "Mathematica Book" - updated and expanded
- To: mathgroup at smc.vnet.net
- Subject: [mg79976] Re: [mg79937] Version 6 "Mathematica Book" - updated and expanded
- From: Tim Brophy <timbrophy at mac.com>
- Date: Fri, 10 Aug 2007 01:41:20 -0400 (EDT)
- References: <200708090918.FAA21022@smc.vnet.net>
Thomas, Thank you very much. This works perfectly on a Mac. Tim Brophy On 9 Aug 2007, at 10:18, thomas wrote: > Hello, > > thank you for the nice feedback on my code for generating a virtual > "Mathematica Book" for version 6. I am sorry that the initial code was > not platform independent, that occurred to me a bit late, and other > have posted corrections for that in the meantime. > > I have kept working on the code, and have incorporated some of the > changes suggested by others. Below you find an updated and expanded > version. The changes are: > > - correct hyperlinks, even to the "New" tutorial topics (the structure > of the "New" files is slightly more sophisticated than the older ones, > the hyperlinks were not reproduced correctly) > > - links to ALL tutorial files in the documentation, not only the ones > that are reached by links in "The Mathematica book" (which includes > files that were previously found in the "Getting started" section of > the v5.2 help system, and in the "Reference guide" of the Mathematica > book, and various other files). I have tried to put this files into > reasonable order, and may or may not have succeeded. > > - links to all tutorials and guides of the packages. > > I hope that the code does work on non-Windows platforms, I have no way > of testing this by myself. > > Best, Thomas > > Code follows: > > (* -==- Make "The Mathematica Book" based on "...Overview.nb" files \ > in the tutorials directory -==- *) > > fn = FileNames["*Overview.nb", > ToFileName[{$InstallationDirectory, "Documentation", "English", > "System", "Tutorials"}]]; > (*Find "Overview.nb" files in the tutorials-directory*) > > nameList = {StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, > 1]] + 1, -12}], > "paclet:tutorial/" <> > StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, 1]] + > 1, -4}], #} & /@ fn; > (*create a list of strings needed for future code*) > > Do[nameList[[i, 1]] = > "New: " <> nameList[[i, 1]], {i, {3, 6, 7, 8, 18, 28, 29, 40, 41, > 46, 48}}]; > (*mark the chapter not present in v5.2 with "New: "*) > > 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*) > > structure = Table[nameList[[i]], {k, 3}, {i, orderOfChapters[[k]]}]; > (*needed for the code further down-represents the structure of the \ > Mathematica book*) > > mainChapters = {"Getting Started", > "A Practical Introduction to Mathematica", > "Principles of Mathematica", "Advanced Mathematics in Mathematica", > "Reference Guide", "Further Tutorials", "Packages"}; > (*The three main headings*) > > beautify[ugly_] := > StringReplace[ > StringReplace[ > ugly, {l1_?LowerCaseQ ~~ l2_?UpperCaseQ :> > l1 <> " " <> l2}], {" And " -> " and ", " Of " -> " of ", > " In " -> " in ", " The " -> " the ", " For " -> " for "}]; > (* based on code by Selwyn Hollis - Thanks! *) > > d[x_, style_: "Section", margin_: {{36, 0}, {5, 5}}] := > Module[{sectitle = beautify[x[[1]]]}, > Cell[BoxData[ > ButtonBox[ > PaneSelectorBox[{False -> sectitle, > True -> StyleBox[sectitle, "HyperlinkActive"]}, > Dynamic[CurrentValue["MouseOver"]]], > BaseStyle -> {"Link", style}, ButtonData -> x[[2]], > ButtonNote -> x[[2]]]], style, CellDingbat -> None, > ShowGroupOpener -> True, CellMargins -> margin]] > (* Cell representing a hyperlink to a file *) > > nb = NotebookPut[]; SetOptions[nb, > StyleDefinitions -> ToFileName["Wolfram", "Reference.nb"]]; > (*Open new Notebook*) > > NotebookWrite[ > nb, {Cell[ > Row[{ToBoxes[ > Import[ToFileName["ExampleData", "spikey.tiff"], "Graphics", > ImageSize -> 70]], > Cell["The Virtual Mathematica Book (v6)", "Title", > TextAlignment -> Center]}], "Title", TextAlignment -> Center], > 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\".", "Text", > TextAlignment -> Center]}]; > (* Print the titel *) > > Do[NotebookWrite[nb, > Cell[StringJoin[Table["xxxxxxxxxx", {k}]], "Text"]]; > If[2 <= k <= 4, > Do[NotebookWrite[nb, d[i]]; > With[{nb1 = NotebookOpen[i[[3]], Visible -> False]}, > SelectionMove[nb1, All, Notebook]; > NotebookWrite[nb, NotebookRead[nb1] //. > {"TOCChapter" -> > Sequence @@ {"Subsection", CellDingbat -> None, > ShowGroupOpener -> True, > CellMargins -> {{48, 0}, Inherited}}, > "TOCSection" -> > Sequence @@ {"Subsubsection", CellDingbat -> None, > ShowGroupOpener -> True, > CellMargins -> {{58, 0}, Inherited}}, > "TOCSubsection" -> > Sequence @@ {"Subsubsubsection", CellDingbat -> None, > ShowGroupOpener -> True, > CellMargins -> {{68, 0}, Inherited}}, > "TOCSubsubsection" -> > Sequence @@ {"Text", CellDingbat -> None, > ShowGroupOpener -> True, > CellMargins -> {{78, 0}, Inherited}}, > ShowCellBracket -> True}]; > NotebookClose[nb1]], > {i, structure[[k - 1]]}] > ], > {k, Length[mainChapters]}]; > (*write all the links to the main chapters, as well as to \ > sub-chapters*) > > Do[NotebookFind[nb, cellsToDelete, All, CellStyle]; > NotebookDelete[ > nb], {cellsToDelete, {"SymbolColorBar", "AnchorBarGrid", > "FooterCell", "TOCDocumentTitle"}}]; > (* Delete unnecessary styling cells that are part of the tutorial \ > notebooks *) > > SetOptions[nb, > StyleDefinitions -> ToFileName["Book", "Textbook.nb"]]; > Do[NotebookFind[nb, StringJoin[Table["xxxxxxxxxx", {k}]], All]; > SelectionMove[nb, All, Cell]; > NotebookWrite[nb, > Cell[mainChapters[[k]], "Subtitle", ShowGroupOpener -> True, > CellMargins -> {{10, 0}, {5, 10}}, > CellTags -> "Section" <> ToString[k], > CellFrame -> > If[MemberQ[{1, 6, 7}, k], {{0, 0}, {0, 2}}, False]]], {k, > Length[mainChapters], 1, -1}]; > (* Finishing touches *) > > (* -==- Add links to tutorials that are not linked yet -==- *) > > SelectionMove[nb, All, Notebook]; > links = StringCases[ToString[NotebookRead[nb], InputForm], > Shortest[("\"paclet:tutorial/" ~~ y__ ~~ "\"")] :> y]; > (* Extract all links to tutorials present in "The Book"... *) > > linkedFiles = > Union[Flatten[ > If[StringFreeQ[#, "#" ~~ DigitCharacter ...], # <> ".nb", > StringCases[#, (y__ ~~ "#" ~~ DigitCharacter ...) :> > y <> ".nb"]] & /@ links]]; > (* ... and their filenames *) > > allTutorials = > Flatten[StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, > 1]] + 1, -1}] & /@ > FileNames["*.nb", > ToFileName[{$InstallationDirectory, "Documentation", "English", > "System", "Tutorials"}]]]; > (* all tutorials in the tutorial directory *) > > notUsed = Complement[allTutorials, linkedFiles]; > (* all tutorials not linked to in "The Book" so far (in alphabetical \ > order); these are 76 tutorial notebooks *) > > nameList = {StringTake[#, {1, -4}], > "paclet:tutorial/" <> StringTake[#, {1, -4}], > ToFileName[{$InstallationDirectory, "Documentation", "English", > "System", "Tutorials"}] <> #} & /@ notUsed; > (*create a list of strings needed for future code*) > > GettingStarted = {21, 18, 75}; GraphPlotting = {27, 28, 36, > 71}; MathematicaReferenceGuide = {7, 31, 64, 19, 57, 20, 37, 33, > 30}; MatrixAndVectorOperations = {10, 26, 6, 3, 73, 16, 42, 45, 62, > 52, 65, 69}; Statistics = {11, 15, 13, 58}; DynamicFeatures = {35, > 2, 34, 1}; SystemSpecificTopics = {17, 32, 60, 50, 51, 53, 41, 44, > 38, 39, 40}; FurtherNDSolveTutorials = {46, 47, 48, > 49}; FrontendAndFormattingTopics = {5, 22, 24, 25, 29, 67, 70, 74}; > topics = {GettingStarted, MathematicaReferenceGuide, GraphPlotting, > MatrixAndVectorOperations, Statistics, DynamicFeatures, > SystemSpecificTopics, FurtherNDSolveTutorials, > FrontendAndFormattingTopics}; > FurtherTopics = Complement[Range[Length[notUsed]], Flatten[topics]]; > topics = Join[topics, {FurtherTopics}]; > (* trying to get some order into these tutorials *) > > topicNames = {"Getting Started", "Mathematica Reference Guide", > "Graph Plotting", "Matrix And Vector Operations", "Statistics", > "Dynamic Features", "System Specific Topics", > "Further NDSolve Tutorials", "FrontEnd and Formatting Topics", > "Others"}; > > NotebookFind[nb, "Section1", After, CellTags]; SelectionMove[nb, \ > After, Cell]; > Do[NotebookWrite[nb, > d[nameList[[i]], "Subsection", {{48, 0}, Inherited}]], {i, > GettingStarted}]; > (* Add links to "getting Started" topics *) > > NotebookFind[nb, "Section5", After, CellTags]; SelectionMove[nb, \ > After, Cell]; > Do[NotebookWrite[nb, > d[nameList[[i]], "Subsection", {{48, 0}, Inherited}]], {i, > MathematicaReferenceGuide}]; > (* Add links to "Refrence Guides" topics *) > > NotebookFind[nb, "Section6", After, CellTags]; SelectionMove[nb, \ > After, Cell]; > Do[NotebookWrite[nb, > Cell[topicNames[[i]], "Section", CellDingbat -> None, > ShowGroupOpener -> True, CellMargins -> {{36, 0}, {5, 5}}]]; > Do[NotebookWrite[nb, > d[nameList[[k]], "Subsection", {{48, 0}, Inherited}]], > {k, topics[[i]]}], > {i, 3, Length[topics]}]; > (* Add links to all other topics *) > > (* -==- Add links to Packages -==- *) > > fnpdir = FileNames["*", > ToFileName[{$InstallationDirectory, "Documentation", "English", > "Packages"}]]; > (* Directory names of the Packages *) > > fnptut = FileNames["*.nb", > ToFileName[{#, "Documentation", "English", "Tutorials"}], > Infinity] & /@ fnpdir; > (* tutorial notebooks of the Packages *) > > fnpguid = > FileNames["*.nb", > ToFileName[{#, "Documentation", "English", "Guides"}], > Infinity] & /@ fnpdir; > (* guide notebooks of the Packages *) > > NotebookFind[nb, "Section7", After, CellTags]; SelectionMove[nb, \ > After, Cell]; > Do[ > With[ > {packageName = > StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, 1]] + > 1, -1}] &@fnpdir[[package]]}, > NotebookWrite[nb, > Cell[beautify@packageName, "Section", CellDingbat -> None, > ShowGroupOpener -> True, CellMargins -> {{36, 0}, {5, 5}}]]; > If[Length[fnptut[[package]]] > 0, > level = > If[StringTake[ > fnptut[[package]], {1, -1} + (Take[#[[1]], {-2, -1}] &@ > Transpose[StringPosition[#, $PathnameSeparator]] & /@ > fnptut[[package]])[[1]]][[1]] == "Tutorials", 1, 2]; > nameList = {"Tutorial: " <> > StringTake[#, {StringPosition[#, $PathnameSeparator][[-level, > 1]] + 1, -4}], > "paclet:" <> packageName <> "/tutorial/" <> > StringReplace[ > StringTake[#, {StringPosition[#, \ > $PathnameSeparator][[-level, 1]] + 1, -4}], "\\" -> "/"]} & /@ > fnptut[[package]]; > Do[NotebookWrite[nb, > d[nameList[[k]], "Subsection", {{48, 0}, Inherited}]], > {k, Length[fnptut[[package]]]}] > ]; > If[Length[fnpguid[[package]]] > 0, > level = > If[StringTake[ > fnpguid[[ > package]], {1, -1} + (Take[#[[1]], {-2, -1}] &@ > Transpose[StringPosition[#, $PathnameSeparator]] & /@ > fnpguid[[package]])[[1]]][[1]] == "Guides", 1, 2]; > nameList = {"Guide: " <> > StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, > 1]] + 1, -4}], > "paclet:" <> packageName <> "/guide/" <> > StringReplace[ > StringTake[#, {StringPosition[#, \ > $PathnameSeparator][[-level, 1]] + 1, -4}], "\\" -> "/"]} & /@ > fnpguid[[package]]; > Do[NotebookWrite[nb, > d[nameList[[k]], "Subsection", {{48, 0}, Inherited}]], > {k, Length[fnpguid[[package]]]}] > ] > ], {package, Length[fnpdir]}]; > (* Add links to package tutorials and guides *) > > SelectionMove[nb, All, Notebook]; FrontEndExecute[ > FrontEndToken["SelectionCloseAllGroups"]]; > FrontEndExecute[FrontEndToken["OpenCloseGroup"]]; > >
- References:
- Version 6 "Mathematica Book" - updated and expanded
- From: thomas <thomas.muench@gmail.com>
- Version 6 "Mathematica Book" - updated and expanded