[Date Index]
[Thread Index]
[Author Index]
Re: Version 6 "Mathematica Book" - updated and expanded
*To*: mathgroup at smc.vnet.net
*Subject*: [mg79983] Re: [mg79937] Version 6 "Mathematica Book" - updated and expanded
*From*: Fred Simons <f.h.simons at tue.nl>
*Date*: Fri, 10 Aug 2007 01:44:58 -0400 (EDT)
*References*: <200708090918.FAA21022@smc.vnet.net>
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
Prev by Date:
**Re: Version 6 "Mathematica Book" - updated and expanded**
Next by Date:
**Re: Version 6 "Mathematica Book" - updated and expanded**
Previous by thread:
**Re: Version 6 "Mathematica Book" - updated and expanded**
Next by thread:
**Re: Re: Version 6 "Mathematica Book" - updated**
| |