Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Version 6 "Mathematica Book" - updated and expanded

27 views
Skip to first unread message

thomas

unread,
Aug 9, 2007, 5:29:49 AM8/9/07
to
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"]];


Tim Brophy

unread,
Aug 10, 2007, 1:44:50 AM8/10/07
to
Thomas,

Thank you very much.

This works perfectly on a Mac.

Tim Brophy

Fred Simons

unread,
Aug 10, 2007, 1:51:56 AM8/10/07
to
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


Thomas Muench

unread,
Aug 10, 2007, 1:54:05 AM8/10/07
to
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

David Bailey

unread,
Aug 10, 2007, 2:01:27 AM8/10/07
to
Thanks for your continuing work - I am amazed that WRI have not offered
to place your notebook on their website and add it to 6.02!

In a way, it is frightening - it reminds me of how much I don't know.....

David Bailey
http://www.dbaileyconsultancy.co.uk


John Browne

unread,
Aug 12, 2007, 7:40:18 AM8/12/07
to
Thomas,

Thank you very much for your Virtual Mathematica Book. It works
beautifully on my Mac.

I do hope Wolfram take note and give you credit for this.

John

Murray Eisenberg

unread,
Aug 13, 2007, 4:41:24 AM8/13/07
to
We can really appreciate the efforts of all, the latest being Fred, to
construct a virtual table of contents for the the non-existent "The
Mathematica Book 5th Edition".

This message compares Fred's contribution with thomas' earlier contribution.

Fred's code is much shorter because of the different method he used, but
the part that does all the actual writing is one huge Do expression that
begs to be modularized. In Fred's code, several of the global names
seem better ("overviews" instead of "fn", "mmabook" instead of "nb").

The two codes give somewhat different results. It's easy to hack
thomas' code to fix up the couple of things in the results that I
disliked there, especially the several "New" section titles. It would
be nice, though, if we could somehow use, overall Fred's method, which
seems simpler (but with modularizing that big Do loop).

COMPREHENSIVENESS:

* thomas includes parts Getting Started, Reference Guide, Further
Tutorials, and Packages that Fred does not.

ORGANIZATION:

* In the Principles of Mathematica part, for the sections on "System
Administration for Network Licenses" and "System Administration for
Single User Licenses" both codes seem to get it a bit wrong. Thomas'
code gets the hierarchy better than does Fred's code. However, thomas'
code results in an unnecessary leading text cell being included directly
in the Virtual Book notebook.

* In the Advanced Mathematics in Mathematica part, Fred's code seems to
get the hierarchy wrong in the section "Differential Equation Solving
with DSolve".

NAMING:

* thomas' code includes the unnecessary "New: " at the start of certain
section titles. OK, I can live with that. However, Fred's code gives
better titles, I think, for three of these:

thomas: New: DSolve
Fred: Differential Equation Solving with DSolve

thomas: New: NDSolve
Fred: Advanced Numerical Differential Equation Solving in Mathematica

thomas: New: NIntegrate
Fred: Advanced Numerical Integration in Mathematica

Aside from the "New:", the differences here seem to be a result of the
underlying methods used for determining section titles.

BEAUTY:

* thomas' alignment of left margins of subsection headings is better
nicer than Fred's

* thomas includes the nice "spikey" with the title, Fred doesn't

* thomas uses a pleasant blue color for all the actual hyperlinks, i.e.,
all sections, subsections,..., below the subtitle-style parts

* both codes fail properly to italicize "Mathematica" when it is the
last word in a heading.

* both codes fail to italicize "Mathematica" in the title and in the
explanatory text of the cell that follows. (Easily fixed after the fact
or in the code -- use a StyleBox in the code that does that.)

* Even though the paragraph at the top, beginning "A collection of links
to the tutorials...", is not itself a hyperlink, it looks better to my
eye in the results of Fred's code, where it appears blue because he uses
the Author style for that cell.

> 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 \

> SelectionMove[mmabook, All, Notebook]; FrontEndExecute[


> FrontEndToken["SelectionCloseAllGroups"]]; FrontEndExecute[
> FrontEndToken["OpenCloseGroup"]];

> SelectionMove[mmabook, Before, Notebook];
>
> Fred Simons
> Eindhoven University of Technology
>
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Raj

unread,
Aug 13, 2007, 4:55:38 AM8/13/07
to

Thanks Very much Thomas.
It works perfectly on a Mac.

Regards,
Raj


David Reiss

unread,
Aug 13, 2007, 4:57:40 AM8/13/07
to
This is because the CellStyle of a Cell is not an Option, but rather,
it is an argument. Here are two ways to do what you want to do.
Assume that you have the cell selected in the notebook nb (and that it
is editable) and the the new styls is a String called newstyle

SelectionMove[nb, All, Cell]

cell = NotebookRead[nb]

cell = cell /. Cell[x_, style_, y___] :> Cell[x, newstyle, y];

NotebookWrite[nb, cell]

Here is another approach using FronEnd functions

SelectionMove[nb, All, Cell]

FrontEndExecute[{FrontEnd`FrontEndToken[nb, "Style", newstyle]}]

--David
http://scientificarts.com/worklife
A WorkLife FrameWork
E x t e n d i n g MATHEMATICA's=AE Reach...=99

On Aug 10, 1:54 am, "Thomas Muench" <thomas.mue...@gmail.com> wrote:
> 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.sim...@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=

> > 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 \

> > SelectionMove[mmabook, All, Notebook]; FrontEndExecute[


> > FrontEndToken["SelectionCloseAllGroups"]]; FrontEndExecute[
> > FrontEndToken["OpenCloseGroup"]];

thomas

unread,
Aug 14, 2007, 7:17:16 AM8/14/07
to
On Aug 13, 10:41 am, Murray Eisenberg <mur...@math.umass.edu> wrote:

> NAMING:
>
> * thomas' code includes the unnecessary "New: " at the start of certain
> section titles. OK, I can live with that.

The main reason I included the "New: " was that I myself decided where
to put these chapters within "The Book", since these were not present
in the v5.2 book. I wanted to give people an easy way to spot these
chapters and move them to different places if it seems more
appropriate that way. So far, nobody complained, so my choice wasn't
that bad, it seems.

This brings up another issue, however, which is the section I named
"Further Tutorials" between "The Book" and the section with the
"Package" documentation. Obviously, these tutorials fit somewhere
within the natural flow of "The Book", but I didn't feel like going to
the trouble to figure out where. Instead, I at least tried to divide
them into topics. Some of these tutorials are quite basic, while some
of them are very sophisticated indeed (like the ones about dynamic
interactivity, or the one about Random Number Generation).

In fact, I feel it should not be anybody's job to figure out the
outline of where to place these tutorials, that should be done by the
folks at WRI. Obviously somebody wrote those documents, it should not
be too hard for the authors to place them appropriately within "The
Book".

So, maybe the next version of Mathematica Documentation Center will
have "The Book" again, with proper placement of all tutorials. I have
to say, I really do like the new documentation center with its many
examples, it is just a shame that it hides these tutorials, which are
really excellent documents, and obfuscates the natural order in which
they were written and supposed to be read in (i.e. the order of "The
Book").

Thomas


Murray Eisenberg

unread,
Aug 15, 2007, 4:08:31 AM8/15/07
to
My comments interspersed below.

thomas wrote:
>
> This brings up another issue, however, which is the section I named
> "Further Tutorials" between "The Book" and the section with the
> "Package" documentation. Obviously, these tutorials fit somewhere
> within the natural flow of "The Book", but I didn't feel like going to
> the trouble to figure out where. Instead, I at least tried to divide
> them into topics. Some of these tutorials are quite basic, while some
> of them are very sophisticated indeed (like the ones about dynamic
> interactivity, or the one about Random Number Generation).
>
> In fact, I feel it should not be anybody's job to figure out the
> outline of where to place these tutorials, that should be done by the
> folks at WRI. Obviously somebody wrote those documents, it should not
> be too hard for the authors to place them appropriately within "The
> Book".

Of course that's precisely the complaint I and others have made: WRI (or
at least Stephen Wolfram) seems to have abandoned the idea of a
linear/spiral organization of all this tutorial material.

Some of those tutorials clearly should go into the first part, "A
Practical Introduction to Mathematica", and others into the 2nd part,
"Principles of Mathematica".


>
> So, maybe the next version of Mathematica Documentation Center will
> have "The Book" again, with proper placement of all tutorials.

Well, at a Mathematica conference (where no confidentiality agreement
was required) it was stated quite clearly that no new version of "The
Mathematica Book" would be appearing.

> ...I really do like the new documentation center with its many


> examples, it is just a shame that it hides these tutorials, which are
> really excellent documents, and obfuscates the natural order in which
> they were written and supposed to be read in (i.e. the order of "The
> Book").

Amen!

Fred Simons

unread,
Aug 15, 2007, 4:20:48 AM8/15/07
to
Thomas,

My feeling is that the tutorials in your chapter Further Tutorials are
just waiting to be adapted to the overall stucture of documentation
tutorials or to be removed. Your three main chapters are based on
overview notebook files that have links to other tutorials, all of them
having a TOCTitle cell and lower level links in TOCSection,
TOCSubsection, TOCSubsubsections cells. All these tutorials are found in
the three main chapters of your virtual book.

The further tutorials have a different structure. First, there is no
overview notebook containing a link to them. Then the relevant cells do
not have a TOC-structure. When there is a title cell at all, the type is
just Title. Moreover, when opened, some of them show the heading
obsolete tutorial.

As far as I know, WRI is working very hard on the documentation an I
expect that already in the next release we will have more overview
notebooks on more topics (stylesheets!) than we have now. That will have
an impact on your very useful virtual Mathematica book. But if that
release will have THE Mathematica book again is another question.
Personally, I feel no need for it and, like you, I am very happy with
the new documentation center.

Fred Simons
Eindhoven University of Technology

thomas wrote:
> On Aug 13, 10:41 am, Murray Eisenberg <mur...@math.umass.edu> wrote:
>
>
>> NAMING:
>>
>> * thomas' code includes the unnecessary "New: " at the start of certain
>> section titles. OK, I can live with that.
>>
>
> The main reason I included the "New: " was that I myself decided where
> to put these chapters within "The Book", since these were not present
> in the v5.2 book. I wanted to give people an easy way to spot these
> chapters and move them to different places if it seems more
> appropriate that way. So far, nobody complained, so my choice wasn't
> that bad, it seems.
>

> This brings up another issue, however, which is the section I named
> "Further Tutorials" between "The Book" and the section with the
> "Package" documentation. Obviously, these tutorials fit somewhere
> within the natural flow of "The Book", but I didn't feel like going to
> the trouble to figure out where. Instead, I at least tried to divide
> them into topics. Some of these tutorials are quite basic, while some
> of them are very sophisticated indeed (like the ones about dynamic
> interactivity, or the one about Random Number Generation).
>
> In fact, I feel it should not be anybody's job to figure out the
> outline of where to place these tutorials, that should be done by the
> folks at WRI. Obviously somebody wrote those documents, it should not
> be too hard for the authors to place them appropriately within "The
> Book".
>

> So, maybe the next version of Mathematica Documentation Center will

> have "The Book" again, with proper placement of all tutorials. I have

> to say, I really do like the new documentation center with its many


> examples, it is just a shame that it hides these tutorials, which are
> really excellent documents, and obfuscates the natural order in which
> they were written and supposed to be read in (i.e. the order of "The
> Book").
>

> Thomas
>
>
>
>


John Jowett

unread,
Sep 4, 2007, 3:46:05 AM9/4/07
to
Hello,
I think it may be useful to give another scheme that will cover
some common cases and, I think, fill a hole in the present
documentation for Mathematica 6. I would say it is complementary to
Thomas Muench's. I base the example on one an earlier thread between
Robert Pigeon and "dh" in May this year.


Needs["PlotLegends`"]

(* Define two lists of points *)

data1 = Table[{x, Sin[x]}, {x, 1, 5}];
data2 = Table[{x, x^Sin[x]}, {x, 1, 5}];

(* Define the style and labels for them *)

style12 = {
{{Red, Thick, Line[{{0.05, .7}, {0.25, .7}}]}, "Sin[x]"},
{{Blue, Thick, Line[{{0.05, .7}, {0.25, .7}}]}, "x^Sin[x]"}
};

(* Make the plot without the legend *)
plot12 = ListLinePlot[{data1, data2}, PlotStyle -> First /@ style12]

(* Include the legend, choose its position, etc. *)
ShowLegend[plot12, {style12, LegendPosition -> {.2, .3},
LegendSize -> {.62, .3}}]

I find it helpful to group the style definitions and captions in the
list style12 at the beginning.

John Jowett


On Aug 22, 10:48 am, "Muench, Thomas" <thomas.mue...@fmi.ch> wrote:
> Hello, Arek
>
> When Mathematica automatically chooses colors for plotting inListPLot
> or ListLinePlot, it takes colors defined in ColorData[1], in the order
> defined there. That means, your first line (or set of points) is plotted
> in ColorData[1,1], the second in ColorData[1,2], and so on. I don't
> think that this is mentioned anywhere in the Help system.
>
> Once you know this, it is straight foreward to make your own legends,
> with not need for the PlotLegend package.
>
> Here are two examples; the first one plots thelegendas part of the
> Plot itself (as Epilog), the second shows thelegendas a separate
> element next to the Plot.
>
> data = Table[RandomReal[], {4}, {5}];
>
> legend= Framed@
> Column[Table[
> Style["data " <> ToString[i], ColorData[1, i], Bold, "Graphics",
> 15], {i, Length[data]}]];
>
> (* Example 1 *)
> ListLinePlot[data, ImageSize -> 300,
> Epilog -> Inset[legend, {.5, .5}]]
>
> (* Example 2 *)
> Row[{ListLinePlot[data, ImageSize -> 300],legend}]
>
> Hope that helps,
> Thomas
>
> On 8/14/07, Arkadiusz.Ma...@gmail.com <Arkadiusz.Ma...@gmail.com> wrote:
>
> Hi,
>
> I know that there has been at least one post on this topic but I still
> can't drawlegendinsideListPlot.
>
> When i plot several curves, colors for them are chosen automaticaly
> by Mathematica. How can I plot alegendfor them?
>
> May I ask for an example, please? Why quite good solution existed in
> MultipleListPlot in Mathv5.2 just vanished????
>
> Arek

John Jowett

unread,
Sep 4, 2007, 4:06:23 AM9/4/07
to
I apologise for an error in my last post. The definition of style12
should have been either

style12 = {
{Directive[{Red, Thick}], "Sin[x]"},
{Directive[{Blue, Thick}], "x^Sin[x]"}
};

in which case the rest of the example works (but the legend may not be
quite what one wants ... ) or

style12 = {
{Graphics[{Red, Thick, Line[{{0.05, .7}, {0.25, .7}}]}],
"Sin[x]"},
{Graphics[{Blue, Thick,Line[{{0.05, .7}, {0.25, .7}}]}],
"x^Sin[x]"}
};

in which case the plot should be made with

plot12 = ListLinePlot[{data1, data2}, PlotStyle -> style12[[All, 1,
1]] ]

0 new messages