(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook 
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[     70630,       1631]*)
(*NotebookOutlinePosition[     71342,       1656]*)
(*  CellTagsIndexPosition[     71298,       1652]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[GraphicsData["Bitmap", "\<\
CF5dJ6E]HGAYHf4PAg9QL6QYHg<PAVmbKF5d0`40005N000061000`40O003h00OogooGgoo003oOomO
Ool00?mooemoo`00ogooGgoo000026jjL[aZ_7:kJ[ab_6ZkL[`3K[/01g:lK[a^^fjkK[a^^g:l00=^
^`09K[ab_6jlK[aZ_7;LK[a^^fjl009^^`03L[aZ_7:k009^^`05K[ab_6kKK[a^^`03K[`026jkK[a^
^fjlK]]^^fjlK[/2K[`01VjkL[a^^fjlK[]b_09^^`04K]ab^fZlL[`2K[/2K[`01fjjL]aZ_6jlK[]b
_6jk009^_009K[]b_6jlK[]^g6jkJ[]^_6jk009^_0A^^`08L[a^_6ZkK[a^^fkLK[ab_09^^`0;K]a^
_6kKL[]Z_6kKK[]^_7;LK[a^^`02K[`02FjkK]a^_6jkK[aZ_7:kK]a^_002K[/00fjlL[a^_002K[/0
1FkLL[a^^fjlL_d00W;l00YboGLML_ac7G<LLaeg77<lMaec?0=g?@08Mcig?GLmMeig?GMMNeigG@9g
GP0ENgmkGG]NMgikGG]oMgekOW]NNgikWW]nNeikWW]nNiikOg^NOgigWWnN009kWP0;Ogik_WnNNkik
WWnONiio_gnnNimoW`02Okl02G^nOkmo_gnoOmmo_g^nOkmog`02Okl2Oml2Okl2Oml2Okl6Oml01Woo
OmmoggooOmmoo`9og`03Oomoggoo009oo`03Ommoogoo06eoo`0000=44dPCB1<00TPC00I44dPCA1=8
4dPDA1<2B1<00d@CB1=84`02A1<2B1<014@CB1=44dPB0TPC01Q44dPBB1A84d@CB1=44dPCA1A84d@C
B1=44dPCA1=84dPBA1=84dPDB1=44dPCB1@2B1<01d@CB1=44dPCA1=44TPC00944`984`09A1=84dPC
A1=854PCA1=84d@C00=84`07A1984d@CB1=44dPCA1<00TPC00E44dPCB1=84d@C00984`04A1=84d@C
A1<2B1<01D@CB1<l4C`A@1000S`A00A043`A?150408l4@04@14l4C`@@142?1403D0@?14l4D0A?10l
4D0A?10l4D0A?10l4D0B00904@07@1944T@CA19@54`ED9@00U1e00=@]EBeD;H00UCf0UDG01II5eEG
FCMM>5UgFEMMUefHGGQM^5fgGKUQ^5gHHMQUf67IHOQQnF8IIQUR6@9V6@0OISYVFVHjISYZFVIjJUYZ
NVIjJWYZNfZJKY]ZNVjKJY]Z^fjKJY]^^fjlK]]^_6jkK[a^nfkLL[]^g7;lL]`00Vkl02YboG;lLaeb
o7<MMaac7G<LLaec?7<nMcag?G<lMeegGWMLMeig?G]NNeegGWMmMeikGG]nNgmgWG]nNeigWWmnNimk
OW^oNgio_W^nOimkggnONmh2Okl01GoOOkmoogoOOkl00WoO00=oogoOOml0G7oo00003U3fE?ED]UCg
E=EDmUBeE?I@mUCeE?I@]ECfD?H2E?H01UBfE?ED]UCgE?I@]@=DmP0@E;EDee3fE;IDm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ag?G<mMcegGWML
MeigGGMNMcekGWMmNcigO@9kOP0LNeikOgMmNgikWW]NNiikOW^NNgik_W]nNkmoWW^NNkioWg^oOkmo
WWoONkioggnoOmmo_gooOkl2Oml017ooOmmoogoO0Woo00=oggooOol0G7oo00002E2eE;IDmD`ELaeQ
f51fC1Ag?P02Ool03T`DD7A@5GooL]a<4dPDOom<5D`CA1=boGooB1@2D;D0K52DOomV>D`EE;ED]TPD
OimoodPDE;ID]DPDOom^g4`DE;I84gooL]a<4e2fFAI<5E2EC1=kOU1fC1A^W7ooOkm@5DPCL_eoodPD
C1EbffXjB1=855BfOomQnE0DE;I<57]nOom84eCfE;EDmTPCOomo_d0BNgiood@CE?ID]EBfC1=MfD`D
Omm@5D`D@1=foGooB1AD]E3hE?ID]UCgE;EDmeBfE?ID]UCgD;EDmeBfE?I@]UCfE;IDme2eE?MD]UCf
D;IDmUBfF=M@mECeF=MI5UTHFCIIE`9I=`0XGGQMMeVHGIMMV5fGHKQM^67HHKUQn67HHMUQn67iIOQR
6VGjIQUVFFHJHSYZNVHjJUUVNfIJJWYZNfZJKW]ZNfZjKW]^VfZkKY]ZVfjlK]/2K[/03FklK[]^g7;K
K]abg6kLL]]bo7;mLaa^o7<L009c7@05Maabo7<MLaeg7002Lad05WLlMcig?G<mMcecGGLmMcigG7MN
NeegGWMMNeicOG]NMeigOWMmNgikOg]M0W^N015kOW^ONgikWWmoNkikOW^oOimk_WnNNkmk_W^oOiio
ggnn009o_`04Oomo_gooOkl4Oml01GooOmmoogooOml0GGoo000025CfE;I@]U1eHOQc?50DB1@2Ool0
36HIL_a<54PDOomkGT`DD1EQf7ooMeikG@9oo`1:B1=@mUBeB1AoofjLC1ADmU2eC1Ag7Goo@19<550E
A19oognNB1ADeDPDOomg?T0BC1AoOd`CE;I@5G:lHMQ44goOOomI5WLmA1=^VgooB1=DMD`EOomgGW]M
Ommooe2eD9ED]D`DK]aoodPDE;ED]U2eB1Ao_goo@15o_gooB1A@]EBfD;E@mUBEC1EQf7ooMeekG@9o
o`09B1=@]U3HE?I@]U2eE;I@mUBe009@]P06E?ED]U2eE;IDmU2e0UBf00a@mEBfE;E@]UBfE;E@mU2f
E?ED]UCfE?D2EAL03EUGFAII=eeHFGIIF5egGIQIUf6hGIQQ^5fi009Qf003HMUQn68I009Qn@0<ISUR
6FIIIQYV>FYJISUZFVIJJU]ZFVYj0VYk00IZNVZKKW]ZVfZkKYX2KY/02VkKJ[]b^f[LK[]b_6kKK[]^
o7;L0Vkl01eboG;LL_abo7<LM_ac77;mLaac7GLLLaec?GLlLaeg?G<mMcegGGLMMcegGGMNMcegGWMM
MeigOW]N009gG@=kOP0@NeegWg]NMiikWW]mNimkWW^nOgik_WnNNkmoWW^oOih2Okl01G_ONimoggno
Oml00gno00AoggooOmmoo`=ogf1oo`0000i@]EBeE;I@]E0EOim854PCOomoWT0BOom<5DPC0Woo00U8
55BfB1Aoge0EB1Aoog<MC1@00UBf00e44gooOim84eBfE?I<56HkOomZ>VZKKY]V>P02Ool0?DPDE;I8
57^NOomb_7oOOom855BeD9EIUg<M@15oog]n@15o_dPDHKQooe1eD;E<57<MIQU857MNOom855BfD?I<
56HIOom@UE1fE?ED]T`DK]aooc`AMcioodPCE;IDmUBfE;E@]EBfB1Aooe0EB1AoogLMC1=@mU2g009D
]@0BE?ID]E2fE;IDmEBfD;ID]E3fE;E@]UBfD?ED]U2fE;E@mUBe0UBf00A@]EBfE;IDm@9De`0GEAEI
5eTFECMIEeTfGGQIMeUHFIMQN5VHGKQM]f6hGKUQf67iHMUUnF7iISUQn@02IQT03FHiIU]V>FHjIUYZ
NVHiJWYZFVIkJWYZVfij009ZV`0LKY]ZVfZkK[]^Vg:LJ[]b^fjlK]]^g7;LK]]^g7;kL_a^ng;mL_a^
o7;lLaec77;lLaec77<MMa`2Lad09GLlLceg?GLmLcag?WMMMcegGG/nMeekGWMMNeigGG]oMgigGG]m
MemkOW]mNimoGWNNNiikOW]oNiik_gmoNiioWW^oOimkggnO009o_P04Omm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7EDeE2fB1<2Ool06DPCC1EooeSgA1=D]WooE;I855CfOolh
47ooOim04eBeC1E857ooIQY8550EB1Aoof6i00984`05C1Aooe2fE7Dl4002Ool0GT`DD;ED]TPDNeeo
og;LA1=D]U2eB1AkGWooE?I<57<lNem44T0AOomogd@CA19ogf7H>11oog;LA1=04WoOOom<54`EC1AQ
^7ooB1AD]DPCOomogeVGOomQ^52EE;EDmU2fE;ED]U3fE;ED]U2eE?ID]U2eE;IDmU2eE;ID]E3fE;ID
mE2fE?ID]E2fE;I@mUCfF=II5eDeEAMI=eUFFCMIN5UgHGQIMefHHIQM]efhHKQQ^EgHHOQQnF8H0V7i
00=V6F8iIQX00VHi0VHj00eZFVIJJUYZNVYJJW]VNVikJYY^VfYkKY]ZV`02K[/04FjKK[]^_6kKK[a^
nfjkK]abnfkLK]]c76kML_]c77;mL_/00W<M0W<L00Ic7G<LLaeg?G<LMcd2Lcd3Mcd03gMMLcegGGMN
NeegGW]MMeigOG]nLeekOg]NNgigOP02Ngh05WMnNiikOWNNOiikOW^OOiik_gnONkioWWoONimoggno
Nkmo_WoONkmo_goO0Wno00=oggooOml00WoO00=oogoOOol0GWoo0002E;H01E2eD;ID]U0DFGP00Woo
00E84eBfE?I<568I009oo`0CEEM<55BfE;I857KlOmm854`DK[]oog;LMceoogoOK[]oogoOJWX00Woo
00Ag?ECfFEMoW`9oo`03J_]I=gnN009oo`07L_aboGooOom84eTFMch00Woo00E855BfD=I@M5UG009o
o`09LaeDmEBfD9A@]WooC1=@]T`D009oo`08L[aoogooKYYkWgooE;Ig7@9oo`07LaeDeD@BMeioofYj
ISX00Woo04I<55BfC1Abg7^NHKUoof8ID1A@mU2fE;E@]U3fE;E@]U2eE?I@]U2eE;I@mU2eE;I@]E3f
E;I@]E2fE;I@]E3fE;E@mUBfE=EDmUDFEAMI=eTFFEMM>5UfGGQIEefHFIMMV5fhHKQMf5fhHMQQfFGI
HOQR6FHJHQUV6FHiIQYV>VIIJSYV>FYJIW]VFP9Z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`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l
43`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l43`A?10l4C`@?14l
43`A?10l4D0A?1504D0BA1400T@C02U44T@CB1=84dPDB1=<54PCC1E@54adD7E@M52eD;I@eECeD=II
5UDFECMI=UDfFGIIEeUgFIIIMefGFKMMN5fgGMQM^67HGMQQn67iHOQQnF8H009R6@0?IQUR>FHiISYV
>FHjIUYZFVIJJUYVFVYjIWYZNVYk009ZVP9ZV`04JYY^VfZkJ[X2K[/036kKK[]^ffkKK]a^ffklK_]^
o7;lK_abo0Ec7009Lcac?G<lMcag7G=MMcecG7Lm00=gG@04Mgeg?GMmNeh2Mgd027]mMgikOGNNNiik
OW^NMih2Nih02W^ONkikWW^oOkmk_WoONkmogg_O0WoO00=oogoOOol0Egoo0000\
\>"], "HeaderCell",
  ShowCellBracket->False,
  CellMargins->{{0, 0}, {Inherited, 0}},
  Evaluatable->False,
  ImageSize->{350, 24},
  ImageMargins->{{0, 0}, {0, 0}},
  ImageRegion->{{0, 1}, {0, 1}}],

Cell["Notebook Manipulation: Making a Calendar", "Title"],

Cell[TextData[{
  "The new capabilities of ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " add many possibilities for notebook manipulation and interface design. \
This notebook describes a few of those tools by way of a calendar program."
}], "Text"],

Cell[TextData[{
  "Press ",
  ButtonBox["here",
    ButtonFunction:>FrontEndExecute[ {
        FrontEnd`FrontEndToken[ 
          ButtonNotebook[ ], "EvaluateInitialization"]}],
    Active->True,
    ButtonStyle->"Hyperlink"],
  " to do the evaluations immediately that are needed to generate a calendar \
window. "
}], "DisplayText"],

Cell[CellGroupData[{

Cell["Laying Out the Months", "Section"],

Cell[TextData[{
  "The first step doesn't involve notebook manipulation at all. We need to \
write the basic code to lay out the days of the month in a grid. Luckily, \
much of what we need can be found in the standard ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " package ",
  StyleBox["Miscellaneous`Calendar`", "InlineInput",
    FontWeight->"Plain"],
  "."
}], "Text"],

Cell[BoxData[
    \(Needs["\<Miscellaneous`Calendar`\>"]\)], "Input",
  InitializationCell->True],

Cell[TextData[
"We first ask, \[OpenCurlyDoubleQuote]What day of the week is the first day \
of the month?\[CloseCurlyDoubleQuote]. It will be convenient for us to number \
the days from 0 to 6."], "Text"],

Cell[BoxData[
    \(monthstart[month_, \ year_]\  := \n\t
      DayOfWeek[{year, month, 1}] /. {Sunday\  \[Rule] \ 0, 
          Monday\  \[Rule] \ 1, Tuesday\  \[Rule] \ 2, 
          Wednesday\  \[Rule] \ 3, Thursday\  \[Rule] \ 4, 
          Friday\  \[Rule] \ 5, Saturday\  \[Rule] \ 6}\)], "Input",
  InitializationCell->True],

Cell[TextData[
"Next ask, \[OpenCurlyDoubleQuote]How many days are in a month?\
\[CloseCurlyDoubleQuote] We could of course write a look\[Dash]up table based \
on the famous ditty, but to make certain we handle leap years and oddities \
correctly, let us write a function."], "Text"],

Cell[BoxData[
    \(dayspermonth[month_, \ year_]\  := \n\t
      DaysBetween[{year, month, 1}, \n
        \t\t{If[month \[Equal] 12, year + 1, year], \n\t\t\t
          If[month \[Equal] 12, 1, month + 1], 1}]\)], "Input",
  InitializationCell->True],

Cell["\<\
A month can now be laid out by prepending and appending nulls to fill out the \
weeks at the beginning and end of the month, and partitioning the entire list \
of days in chunks of seven.\
\>", "Text"],

Cell[BoxData[
    \(monthlayout[month_, \ year_]\  := \n\t
      Module[{begins = monthstart[month, year], 
          days = dayspermonth[month, year]}, \n\t\t
        Partition[
          Join[Table["\<\>", {begins}], Range[days], 
            Table["\<\>", {
                7 - \((Mod[begins + days, 7] /. \((0 \[Rule] 7)\))\)}]], 7]]
        \)], "Input",
  InitializationCell->True],

Cell[TextData["Let\[CloseCurlyQuote]s try this out."], "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    \(monthlayout[1, 1996] // TableForm\)], "Input"],

Cell[BoxData[
    TagBox[GridBox[{
          {\(""\), "1", "2", "3", "4", "5", "6"},
          {"7", "8", "9", "10", "11", "12", "13"},
          {"14", "15", "16", "17", "18", "19", "20"},
          {"21", "22", "23", "24", "25", "26", "27"},
          {"28", "29", "30", "31", \(""\), \(""\), \(""\)}
          },
        RowSpacings->1,
        ColumnSpacings->3,
        RowAlignments->Baseline,
        ColumnAlignments->{Left}],
      (TableForm[ #]&)]], "Output"]
}, Open  ]],

Cell[TextData[
"Looks good! We\[CloseCurlyQuote]re most of the way there\[Ellipsis]"], "Text"]
}, Closed]],

Cell[CellGroupData[{

Cell["Creating the Grid", "Section"],

Cell[TextData[{
  "With the grid we\[CloseCurlyQuote]ve already created, we have the elements \
necessary for a bare\[Dash]bones calendar. It would be nice to improve the \
appearance a bit, however. For instance, we might give it a 3D look with \
colored backgrounds, as well as names for the days and the months. To do \
this, it is convenient to work with ",
  StyleBox["GridBox", "InlineInput",
    FontWeight->"Plain"],
  " objects."
}], "Text"],

Cell["\<\
A handy tactic while working with formatted objects is to direct the output \
of your test functions to either the current notebook, or a scratch notebook \
of your choice. In fact, it is good for your final functions to allow their \
output to be directed to any notebook specified by a notebook object.\
\>", "Text"],

Cell[TextData[{
  "Continuing on, we note that a ",
  StyleBox["GridBox", "InlineInput",
    FontWeight->"Plain"],
  " accepts a list of lists for its argument; precisely what our layout \
function generates. Note that this grid must be rectangular. For irregular \
numbers of columns, we must nest grid boxes. For instance, we can say:"
}], "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], 
      Cell[BoxData[
          GridBox[{{"\<January 1996\>"}, {
                GridBox[
                  Prepend[
                    monthlayout[1, 1996], {"\<Sun\>", "\<Mon\>", "\<Tue\>", 
                      "\<Wed\>", "\<Thu\>", "\<Fri\>", "\<Sat\>"}]]}}]], \ 
        "\<Output\>"]]\)], "Input"],

Cell[BoxData[GridBox[{
        {\(January\ 1996\)},
        {GridBox[{
              {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
              {"", "1", "2", "3", "4", "5", "6"},
              {"7", "8", "9", "10", "11", "12", "13"},
              {"14", "15", "16", "17", "18", "19", "20"},
              {"21", "22", "23", "24", "25", "26", "27"},
              {"28", "29", "30", "31", "", "", ""}
              }]}
        }]], "Output"]
}, Open  ]],

Cell[TextData[{
  "Here we see the first use of notebook functions. We write into the \
notebook that is performing the current evaluation some data in box form in a \
cell, where those boxes are the nested grids containing our calendar. Some of \
the standard notebooks include the ",
  StyleBox["SelectedNotebook[]", "InlineInput",
    FontWeight->"Plain"],
  ", the ",
  StyleBox["ButtonNotebook[]", "InlineInput",
    FontWeight->"Plain"],
  ", the ",
  StyleBox["EvaluationNotebook[]", "InlineInput",
    FontWeight->"Plain"],
  ", and the ",
  StyleBox["InputNotebook[]", "InlineInput",
    FontWeight->"Plain"],
  ". If you know the specific notebook object (for instance, returned by ",
  StyleBox["NotebookPut", "InlineInput",
    FontWeight->"Plain"],
  " or selected from the list returned by ",
  StyleBox["Notebooks", "InlineInput",
    FontWeight->"Plain"],
  "), you can use that in the same place as one of these notebooks. Some \
operations on notebooks include putting or getting entire notebook \
expressions (",
  StyleBox["NotebookPut", "InlineInput",
    FontWeight->"Plain"],
  ", ",
  StyleBox["NotebookGet", "InlineInput",
    FontWeight->"Plain"],
  "), writing to or reading from existing notebooks (",
  StyleBox["NotebookWrite", "InlineInput",
    FontWeight->"Plain"],
  ", ",
  StyleBox["NotebookRead", "InlineInput",
    FontWeight->"Plain"],
  "), as well as a host of other operations."
}], "Text"],

Cell[TextData[
"We can tell that we will need the abbreviations of the days of the week \
again; we will probably also need the names of the months. Let\
\[CloseCurlyQuote]s assign them to handy symbols."], "Text"],

Cell[BoxData[
    \(\(alldays\  = 
      \ {"\<Sun\>", \ "\<Mon\>", \ "\<Tue\>", \ "\<Wed\>", \ "\<Thu\>", 
        "\<Fri\>", "\<Sat\>"}; \)\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(allmonths\  = 
      \ {"\<January\>", \ "\<February\>", \ "\<March\>", \ "\<April\>", \ 
        "\<May\>", \ "\<June\>", "\<July\>", \ "\<August\>", \ 
        "\<September\>", \ "\<October\>", \ "\<November\>", "\<December\>"}; 
    \)\)], "Input",
  InitializationCell->True],

Cell[TextData[{
  "Now let\[CloseCurlyQuote]s enhance the appearance of our grid. We do this \
in two ways: by use of button boxes and by use of style boxes. ",
  StyleBox["ButtonBox", "InlineInput",
    FontWeight->"Plain"],
  " objects are normally used to attach an action that is triggered by a \
mouse click to some box expression. We will see an example of this later. \
However, button boxes also have an appealing 3D visual aspect. We will use \
that here by setting each button\[CloseCurlyQuote]s function to ",
  StyleBox["Null", "InlineInput",
    FontWeight->"Plain"],
  ". ",
  StyleBox["StyleBox", "InlineInput",
    FontWeight->"Plain"],
  " wrappers, in contrast, generically apply options to the enclosed boxes. \
Here, we will be concerned with those options controlling aspects of style: \
fonts, colors, and the like. Finally, we can use various options to the grid \
boxes that affect display to improve the look of the calendar."
}], "Text"],

Cell["\<\
For example, we can place button boxes around the various pieces and control \
their colors.\
\>", "Text"],

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], 
      BoxData[GridBox[
          {{ButtonBox["\<January 1996\>", 
                Background \[Rule] RGBColor[0.4, \ 0, \ 0.4], 
                ButtonFunction \[Rule] Null]}, 
            {GridBox[
                Prepend[
                  monthlayout[1, 1996] /. 
                    i : \((_Integer\  | \ _String)\) \[RuleDelayed] 
                      ButtonBox[i, 
                        Background \[Rule] RGBColor[1, \ 0.6, \ 0.8], \ 
                        ButtonFunction \[Rule] Null], 
                  alldays /. 
                    s_String \[RuleDelayed] 
                      ButtonBox[s, 
                        Background \[Rule] RGBColor[0.8, \ 0.2, \ 0.6], 
                        ButtonFunction \[Rule] Null]]]}}]]]\)], "Input"],

Cell[BoxData[GridBox[{
        {
          ButtonBox[\(January\ 1996\),
            ButtonFunction:>None,
            Background->RGBColor[0.4, 0, 0.4]]},
        {GridBox[{
              {
                ButtonBox["Sun",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Mon",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Tue",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Wed",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Thu",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Fri",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]], 
                ButtonBox["Sat",
                  ButtonFunction:>None,
                  Background->RGBColor[0.8, 0.2, 0.6]]},
              {
                ButtonBox["",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["1",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["2",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["3",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["4",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["5",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["6",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]]},
              {
                ButtonBox["7",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["8",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["9",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["10",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["11",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["12",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["13",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]]},
              {
                ButtonBox["14",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["15",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["16",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["17",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["18",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["19",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["20",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]]},
              {
                ButtonBox["21",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["22",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["23",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["24",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["25",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["26",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["27",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]]},
              {
                ButtonBox["28",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["29",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["30",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["31",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]], 
                ButtonBox["",
                  ButtonFunction:>None,
                  Background->RGBColor[1, 0.6, 0.8]]}
              }]}
        }]], "Input"],

Cell[TextData[{
  "This will look better if we eliminate the space between the rows and \
columns; it will also help to change the colors of the fonts in the headers. \
Finally, this will probably look better if we use the Helvetica font. Font \
changes can be handled by ",
  StyleBox["StyleBox", "InlineInput",
    FontWeight->"Plain"],
  " wrappers, while the grid alignment is handled by ",
  StyleBox["GridBox", "InlineInput",
    FontWeight->"Plain"],
  " options. Let\[CloseCurlyQuote]s also not draw the empty boxes."
}], "Text"],

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], 
      BoxData[StyleBox[
          GridBox[{{ButtonBox[
                  StyleBox["\<January 1996\>", FontWeight \[Rule] "\<Bold\>", 
                    FontColor \[Rule] GrayLevel[1]], 
                  Background \[Rule] RGBColor[0.4, \ 0, \ 0.4], 
                  ButtonFunction \[Rule] Null]}, 
              {GridBox[
                  Prepend[
                    monthlayout[1, 1996] /. 
                      i : \((_Integer\  | \ _String)\) \[RuleDelayed] 
                        ButtonBox[i, 
                          Background \[Rule] RGBColor[1, \ 0.6, \ 0.8], \ 
                          ButtonFunction \[Rule] Null], 
                    alldays /. 
                      s_String \[RuleDelayed] 
                        ButtonBox[
                          StyleBox[s, FontWeight \[Rule] "\<Bold\>", 
                            FontColor \[Rule] GrayLevel[0.8]], 
                          Background \[Rule] RGBColor[0.8, \ 0.2, \ 0.6], 
                          ButtonFunction \[Rule] Null]], \ 
                  ColumnSpacings\  \[Rule] \ 0, \ RowSpacings\  \[Rule] \ 0, 
                  ColumnWidths \[Rule] 3, 
                  RowMinHeight \[Rule] 1.5]}}, \n\t\t\t\tRowSpacings \[Rule] 
              0], FontFamily \[Rule] "\<Helvetica\>", 
          FontWeight \[Rule] "\<Plain\>"]]]\)], "Input"],

Cell[BoxData[
    StyleBox[GridBox[{
          {
            ButtonBox[
              StyleBox[\(January\ 1996\),
                FontWeight->"Bold",
                FontColor->GrayLevel[1]],
              ButtonFunction:>None,
              Background->RGBColor[0.4, 0, 0.4]]},
          {GridBox[{
                {
                  ButtonBox[
                    StyleBox["Sun",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Mon",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Tue",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Wed",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Thu",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Fri",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Sat",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]]},
                {
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["1",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["2",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["3",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["4",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["5",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["6",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["7",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["8",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["9",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["10",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["11",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["12",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["13",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["14",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["15",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["16",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["17",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["18",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["19",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["20",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["21",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["22",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["23",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["24",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["25",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["26",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["27",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["28",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["29",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["30",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["31",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]}
                },
              RowSpacings->0,
              ColumnSpacings->0,
              ColumnWidths->3,
              RowMinHeight->1.5]}
          },
        RowSpacings->0],
      FontFamily->"Helvetica",
      FontWeight->"Plain"]], "Input"],

Cell[TextData[{
  "This progression of successively adding features to the layout as you \
develop the format you want is natural to ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  ". It is very easy to test modifications by interactively adjusting the \
inputs. For instance, suppose we wanted a different color set; it is a matter \
of instants to change the RGB values in the preceding expression to test \
different possibilities. The incremental structure also allows us to test the \
core of our layout before adding less essential aspects (such as color and \
font) to the expression."
}], "Text"],

Cell[TextData[
"Now that we have a grid we like, let\[CloseCurlyQuote]s put it in a \
function."], "Text"],

Cell[BoxData[
    \(monthgrid[month_, \ year_]\  := \n\t
      StyleBox[GridBox[
          {{ButtonBox[
                StyleBox[
                  allmonths\[LeftDoubleBracket]month\[RightDoubleBracket]<>
                    ToString[year], FontWeight \[Rule] "\<Bold\>", 
                  FontColor \[Rule] GrayLevel[1]], 
                Background \[Rule] RGBColor[0.4, \ 0, \ 0.4], 
                ButtonFunction \[Rule] Null]}, 
            {GridBox[
                Prepend[
                  monthlayout[month, year] /. 
                    i : \((_Integer\  | \ _String)\) \[RuleDelayed] 
                      ButtonBox[i, 
                        Background \[Rule] RGBColor[1, \ 0.6, \ 0.8], \ 
                        ButtonFunction \[Rule] Null], 
                  alldays /. 
                    s_String \[RuleDelayed] 
                      ButtonBox[
                        StyleBox[s, FontWeight \[Rule] "\<Bold\>", 
                          FontColor \[Rule] GrayLevel[0.8]], 
                        Background \[Rule] RGBColor[0.8, \ 0.2, \ 0.6], 
                        ButtonFunction \[Rule] Null]], \ 
                ColumnSpacings\  \[Rule] \ 0, \ RowSpacings\  \[Rule] \ 0, 
                ColumnWidths \[Rule] 3, 
                RowMinHeight \[Rule] 1.5]}}, \n\t\t\t\tRowSpacings \[Rule] 
            0], FontFamily \[Rule] "\<Helvetica\>", 
        FontWeight \[Rule] "\<Plain\>"]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], \ BoxData[monthgrid[3, 1997]]]\)], 
  "Input"],

Cell[BoxData[
    StyleBox[GridBox[{
          {
            ButtonBox[
              StyleBox["March1997",
                FontWeight->"Bold",
                FontColor->GrayLevel[1]],
              ButtonFunction:>None,
              Background->RGBColor[0.4, 0, 0.4]]},
          {GridBox[{
                {
                  ButtonBox[
                    StyleBox["Sun",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Mon",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Tue",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Wed",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Thu",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Fri",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]], 
                  ButtonBox[
                    StyleBox["Sat",
                      FontWeight->"Bold",
                      FontColor->GrayLevel[0.8]],
                    ButtonFunction:>None,
                    Background->RGBColor[0.8, 0.2, 0.6]]},
                {
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["1",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["2",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["3",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["4",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["5",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["6",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["7",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["8",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["9",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["10",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["11",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["12",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["13",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["14",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["15",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["16",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["17",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["18",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["19",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["20",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["21",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["22",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["23",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["24",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["25",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["26",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["27",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["28",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["29",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]},
                {
                  ButtonBox["30",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["31",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]], 
                  ButtonBox["",
                    ButtonFunction:>None,
                    Background->RGBColor[1, 0.6, 0.8]]}
                },
              RowSpacings->0,
              ColumnSpacings->0,
              ColumnWidths->3,
              RowMinHeight->1.5]}
          },
        RowSpacings->0],
      FontFamily->"Helvetica",
      FontWeight->"Plain"]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Making Cells and Notebooks", "Section"],

Cell[TextData[{
  "The basic arrangement of a ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " document, or notebook, is a hierarchical nesting of cells (chunks of \
text, typesetting, graphics, etc.). This is easily representable as a ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " expression, and in fact, this is how the front end stores a notebook. For \
example:"
}], "Text"],

Cell[TextData[{
  "Notebook[{\n\tCell[CellGroupData[{\n\t\tCell[",
  StyleBox["cell contents",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["style",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["cell options",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  "],\n\t\tCell[",
  StyleBox["cell contents",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["style",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["cell options",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  "]\n\t\t}, ",
  StyleBox["group state",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  "]\n\t],\n\tCell[",
  StyleBox["cell contents",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["style",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  ", ",
  StyleBox["cell options",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  "]\n}, ",
  StyleBox["notebook options",
    FontFamily->"Times",
    FontWeight->"Plain",
    FontSlant->"Italic"],
  "]"
}], "DisplayText",
  Evaluatable->False,
  FontFamily->"Courier"],

Cell[TextData[{
  "If we create an expression of this form, we can direct the front end to \
turn it into a window with the command ",
  StyleBox["NotebookPut", "InlineInput",
    FontWeight->"Plain"],
  ". Alternately, we could create an empty notebook window with ",
  StyleBox["NotebookCreate", "InlineInput",
    FontWeight->"Plain"],
  ", then fill it by writing into it with ",
  StyleBox["NotebookWrite", "InlineInput",
    FontWeight->"Plain"],
  " and setting its options with ",
  StyleBox["SetOptions", "InlineInput",
    FontWeight->"Plain"],
  "."
}], "Text"],

Cell[TextData[
"In this case, we would like to create a palette\[Dash]style window, and fill \
it as much as possible with the grid specifying the month. We do this by \
creating a notebook with one cell, setting the options of that cell and the \
notebook to control the overall appearance."], "Text"],

Cell["For example, in the simplest form, we can say:", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    \(NotebookPut[
      Notebook[{Cell[BoxData[monthgrid[1, 1996]], \ NotebookDefault]}]]\)], 
  "Input"],

Cell[BoxData[
    InterpretationBox[
      \(\[SkeletonIndicator]  NotebookObject  \[SkeletonIndicator]\),
      NotebookObject[ 
        FrontEndObject[ 
          LinkObject[ "FM32410599", 1, 1]], 16],
      Editable->False]], "Output"]
}, Open  ]],

Cell[TextData[
"Here, all the cell and notebook options take on default values. We even \
specify a default style for the cell (which means that we don\
\[CloseCurlyQuote]t care to adopt any values from an existing cell style; \
this won\[CloseCurlyQuote]t always be the case)."], "Text"],

Cell["\<\
We can write a variant of this that changes the appearance a bit.\
\>", "Text"],

Cell[BoxData[
    \(\((nb\  = \ 
        NotebookPut[
          Notebook[{
              Cell[BoxData[monthgrid[1, 1996]], \ NotebookDefault, 
                CellMargins\  \[Rule] {{0, 0}, {0, 0}}, 
                ShowCellBracket \[Rule] False]}, WindowElements \[Rule] {}, 
            WindowFrameElements \[Rule] "\<CloseBox\>", 
            WindowSize \[Rule] {252, 134}, WindowFrame \[Rule] "\<Palette\>", 
            WindowTitle \[Rule] "\<Calendar\>", 
            Background \[Rule] RGBColor[0.4, \ 0, \ 0.4]]]; \n\t
      SelectionMove[nb, \ Before, \ Notebook])\)\)], "Input"],

Cell[TextData[{
  "Most of these options are fairly simple. The ",
  StyleBox["CellMargins", "InlineInput",
    FontWeight->"Plain"],
  " option gives the space around the cell, expressed in points, in the order \
{{",
  StyleBox["left",
    FontSlant->"Italic"],
  ", ",
  StyleBox["right",
    FontSlant->"Italic"],
  "}, {",
  StyleBox["bottom",
    FontSlant->"Italic"],
  ", ",
  StyleBox["top",
    FontSlant->"Italic"],
  "}}. The ",
  StyleBox["WindowElements", "InlineInput",
    FontWeight->"Plain"],
  " option controls things at the notebook level like scroll bars and the \
status area, while the ",
  StyleBox["WindowFrameElements", "InlineInput",
    FontWeight->"Plain"],
  " are items that appear in the frame, such as the close box, resize area, \
and zoom box."
}], "Text"],

Cell["\<\
We will put these concepts into a function after one more issue is handled: \
controlling the calendar.\
\>", "Text"]
}, Closed]],

Cell[CellGroupData[{

Cell["Actions in the Interface", "Section"],

Cell[TextData[{
  "As intimated previously, buttons are commonly used to ",
  StyleBox["do",
    FontSlant->"Italic"],
  " things, not sit around looking pretty. One thing that we might like to do \
in this calendar is to change to different months. The simplest interface for \
this would let us scroll to the next or the previous month from the one \
currently displayed. So, we might create a \[OpenCurlyDoubleQuote]Next\
\[CloseCurlyDoubleQuote] and a \[OpenCurlyDoubleQuote]Previous\
\[CloseCurlyDoubleQuote] button."
}], "Text"],

Cell[TextData[{
  "A button is a box expression with a function attached to it. That function \
is in an option, called, naturally enough, ",
  StyleBox["ButtonFunction", "InlineInput",
    FontWeight->"Plain"],
  ". That function can be any ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " function. Another option, called ",
  StyleBox["ButtonEvaluator", "InlineInput",
    FontWeight->"Plain"],
  ", tells the button where to evaluate the function. A very limited set of \
functions (consisting solely of notebook operations) can be evaluated \
entirely in the front end, but most need to go to the current ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  "  kernel to be effective. (Others might be directed to a dedicated kernel, \
or to another application connected via ",
  StyleBox["MathLink",
    FontSlant->"Italic"],
  ".) For example, here we use the technique demonstrated in the section on \
writing grids to write out a button that pops up our calendar."
}], "Text"],

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], \ 
      Cell[BoxData[
          ButtonBox[
            "\<Calendar for January 1997\>", \n\t\t\tButtonEvaluator\  
              \[Rule] Automatic, \ 
            Active \[Rule] True, \n\t\t\tButtonFunction \[RuleDelayed] 
              NotebookPut[
                Notebook[
                  {Cell[BoxData[monthgrid[1, 1997]], \ NotebookDefault, 
                      CellMargins\  \[Rule] {{0, 0}, {0, 0}}, 
                      ShowCellBracket \[Rule] False]}, 
                  WindowElements \[Rule] {}, 
                  WindowFrameElements \[Rule] "\<CloseBox\>", 
                  WindowSize \[Rule] {252, 134}, 
                  WindowFrame \[Rule] "\<Palette\>", 
                  WindowTitle \[Rule] "\<Calendar\>", 
                  Background \[Rule] RGBColor[0.4, \ 0, \ 0.4]]]]], 
        "\<Output\>", CellEditDuplicate \[Rule] False]\ ]\)], "Input"],

Cell[TextData[{
  "A button function can actually be a ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " pure function, whose arguments come from the contents of the button box, \
the ",
  StyleBox["ButtonData", "InlineInput",
    FontWeight->"Plain"],
  " option, or a location specified by the ",
  StyleBox["ButtonSource", "InlineInput",
    FontWeight->"Plain"],
  " option. However, for our purposes, we can work with a simpler model, and \
take the data from global variables."
}], "Text"],

Cell["\<\
Actually, it is, properly speaking, poor form to store the program state in \
global variables when it might be stored in the notebook. Caching information \
in the notebook allows you to save it and reopen it between sessions without \
losing the state of the notebook. However, for simplicity, we will work on an \
example using global variables in the kernel.\
\>", "Text"],

Cell["\<\
What portion of the state do we want to preserve? Well, the month and the \
year seem the logical canidates.\
\>", "Text"],

Cell[BoxData[
    \($CurrentCalendarMakerYear\  = \ 1996; 
    \n$CurrentCalendarMakerMonth\  = \ 9; \)], "Input"],

Cell["\<\
Then, one button increments the month and displays a calender, while the \
other decrements (both wrapping appropriately at year boundaries).\
\>", "Text"],

Cell[BoxData[
    \(NotebookWrite[EvaluationNotebook[], 
      BoxData[RowBox[{
            ButtonBox["\<Previous\>", \n\t\t\t
              ButtonEvaluator\  \[Rule] Automatic, \ Active \[Rule] True, \n
              \t\t\tButtonFunction \[RuleDelayed] 
                \((\(--$CurrentCalendarMakerMonth\); 
                  If[$CurrentCalendarMakerMonth \[Equal] 
                      0, $CurrentCalendarMakerMonth = 12; 
                    \(--$CurrentCalendarMakerYear\)\n\t\t\t\t\t\t\t\t\t\t]; \n
                  \t\t\t\t\t\t\t
                  NotebookPut[
                    Notebook[{
                        Cell[BoxData[
                            monthgrid[$CurrentCalendarMakerMonth, \
$CurrentCalendarMakerYear]], \ NotebookDefault, 
                          CellMargins\  \[Rule] {{0, 0}, {0, 0}}, 
                          ShowCellBracket \[Rule] False]}, 
                      WindowElements \[Rule] {}, 
                      WindowFrameElements \[Rule] "\<CloseBox\>", 
                      WindowSize \[Rule] {252, 134}, 
                      WindowFrame \[Rule] "\<Palette\>", 
                      WindowTitle \[Rule] "\<Calendar\>", 
                      Background \[Rule] RGBColor[0.4, \ 0, \ 0.4]]])\)], 
            ButtonBox["\<Next\>", \n\t\t\t
              ButtonEvaluator\  \[Rule] Automatic, \ Active \[Rule] True, \n
              \t\t\tButtonFunction \[RuleDelayed] 
                \((\(++$CurrentCalendarMakerMonth\); 
                  If[$CurrentCalendarMakerMonth \[Equal] 
                      13, $CurrentCalendarMakerMonth = 1; 
                    \(++$CurrentCalendarMakerYear\)\n\t\t\t\t\t\t\t\t\t\t]; \n
                  \t\t\t\t\t\t\t
                  NotebookPut[
                    Notebook[{
                        Cell[BoxData[
                            monthgrid[$CurrentCalendarMakerMonth, \
$CurrentCalendarMakerYear]], \ NotebookDefault, 
                          CellMargins\  \[Rule] {{0, 0}, {0, 0}}, 
                          ShowCellBracket \[Rule] False]}, 
                      WindowElements \[Rule] {}, 
                      WindowFrameElements \[Rule] "\<CloseBox\>", 
                      WindowSize \[Rule] {252, 134}, 
                      WindowFrame \[Rule] "\<Palette\>", 
                      WindowTitle \[Rule] "\<Calendar\>", 
                      Background \[Rule] RGBColor[0.4, \ 0, \ 0.4]]])\)]}]]]
      \)], "Input"],

Cell[TextData[
"Well, notwithstanding the redundant code, the principle is sound; but we are \
getting a new window with each button click! This is not good\[Ellipsis] \
However, we can resolve that issue and tie together all the pieces in the \
final section."], "Text"]
}, Closed]],

Cell[CellGroupData[{

Cell["Making the Calendar", "Section"],

Cell[TextData[{
  "We now have most of the pieces we need to make our calendar application. \
The only remaining tool is one to ",
  StyleBox["replace",
    FontSlant->"Italic"],
  " the current calendar grid with a new one, rather than creating a new \
window. Several techniques are possible. For instance, ",
  StyleBox["NotebookPut", "InlineInput",
    FontWeight->"Plain"],
  " can take an additional argument that is a notebook object; in that case, \
the named notebook will be replaced ",
  StyleBox["in toto",
    FontSlant->"Italic"],
  ". Another method is to move the current location to the top of the \
notebook, then select the first cell in the notebook. This will work if you \
can guarantee the structure of the notebook, but it is usually better (more \
robust) to use a third technique: tag the target cell when it is created, \
then locate it by the ",
  StyleBox["NotebookFind", "InlineInput",
    FontWeight->"Plain"],
  " command. ",
  StyleBox["NotebookFind", "InlineInput",
    FontWeight->"Plain"],
  " is used in general to search a notebook, but with the specific form ",
  StyleBox["NotebookFind[", "InlineInput",
    FontWeight->"Plain"],
  StyleBox["notebook object",
    FontSlant->"Italic"],
  StyleBox[", ", "InlineInput"],
  StyleBox["tag",
    FontSlant->"Italic"],
  StyleBox[", ", "InlineInput"],
  StyleBox["All, CellTags]", "InlineInput",
    FontWeight->"Plain"],
  ", it will select the tagged cell(s). Use the ",
  StyleBox["CellTags \[Rule] \"", "InlineInput",
    FontWeight->"Plain"],
  StyleBox["tag",
    FontSlant->"Italic"],
  StyleBox["\"", "InlineInput",
    FontWeight->"Plain"],
  " option at the cell level to specify a tag."
}], "Text"],

Cell[TextData[{
  "Now, putting everything together in a modular fashion, we start with a \
function that creates the grid cell. We add a fillip to color the current \
date red; we also place the buttons that change the month with the title. In \
principle, we should simply recode ",
  StyleBox["monthgrid", "InlineInput",
    FontWeight->"Plain"],
  ", but as an example of working from an existing code base, we will \
transform our current result."
}], "Text"],

Cell[BoxData[
    \(monthcell[month_, \ year_]\  := \n\t
      Cell[BoxData[
          monthgrid[month, year] /. 
            Join[{{ButtonBox[title_, ___]}\  :> 
                  {GridBox[
                      {{ButtonBox[
                            AdjustmentBox[
                              StyleBox["\<\[DoubleLongLeftArrow]\>", 
                                FontColor \[Rule] GrayLevel[1]], 
                              BoxMargins\  \[Rule] \ {{0.2, 3}, {0.8, 0.8}}], 
                            ButtonFrame \[Rule] None, Active \[Rule] True, 
                            ButtonEvaluator \[Rule] Automatic, 
                            ButtonFunction \[RuleDelayed] 
                              changemonth[
                                Decrement]], \n\t\t\t\t\t\t\t\t\t\t\t\
AdjustmentBox[title, BoxMargins\  -> \ 
                              {{0, 0}, 
                                {0.7, 
                                  0.7}}], \n\t\t\t\t\t\t\t\t\t\t\tButtonBox[
                            AdjustmentBox[
                              StyleBox["\<\[DoubleLongRightArrow]\>", 
                                FontColor \[Rule] GrayLevel[1]], 
                              BoxMargins\  \[Rule] \ {{3, 0.2}, {0.8, 0.8}}], 
                            ButtonFrame \[Rule] None, Active \[Rule] True, 
                            ButtonEvaluator \[Rule] Automatic, 
                            ButtonFunction \[RuleDelayed] 
                              changemonth[Increment]]}}, 
                      ColumnWidths\  \[Rule] 
                        {5, 9, 5}]}}, \n\t\t\t\t\t\t\t\t\t\t\tIf[
                {year, month}\  === \ Take[Date[], 2], 
                {ButtonBox[
                      d : Evaluate[
                          \(Date[]\)\[LeftDoubleBracket]3\[RightDoubleBracket]\
], opts___] \[RuleDelayed] 
                    ButtonBox[d, opts, 
                      Background \[Rule] RGBColor[1. , \ 0.2, \ 0.4]]}, 
                {}]]], \ NotebookDefault, 
        CellMargins\  \[Rule] {{0, 0}, {0, 0}}, 
        ShowCellBracket \[Rule] False, Active \[Rule] True, 
        CellTags \[Rule] "\<TheCalendarMakerMonth\>"]\)], "Input",
  InitializationCell->True],

Cell[TextData[{
  "The button functions for incrementing and decrementing the current month \
can be combined into one function. Here, let ",
  StyleBox["op", "InlineInput",
    FontWeight->"Plain"],
  " be ",
  StyleBox["Increment", "InlineInput",
    FontWeight->"Plain"],
  " or ",
  StyleBox["Decrement", "InlineInput",
    FontWeight->"Plain"],
  ", depending on which way you want to go."
}], "Text"],

Cell[BoxData[
    \(changemonth[op_]\  := \n\t
      \((op[FE`Private`$CurrentCalendarMakerMonth]; 
        Switch[FE`Private`$CurrentCalendarMakerMonth, 0, 
          FE`Private`$CurrentCalendarMakerMonth = 12; 
          op[FE`Private`$CurrentCalendarMakerYear], \n\t\t\t13, 
          FE`Private`$CurrentCalendarMakerMonth = 1; 
          op[FE`Private`$CurrentCalendarMakerYear]]; \n\t\tNotebookFind[
          ButtonNotebook[], \ "\<TheCalendarMakerMonth\>", \ All, \ 
          CellTags]; \[IndentingNewLine]NotebookWrite[ButtonNotebook[], 
          monthcell[FE`Private`$CurrentCalendarMakerMonth, 
            FE`Private`$CurrentCalendarMakerYear], AutoScroll \[Rule] False])
        \)\)], "Input",
  InitializationCell->True],

Cell[TextData[
"Now we write the user\[Dash]level function that initializes the state and \
creates the notebook."], "Text"],

Cell[BoxData[
    \(MakeCalendar[month_, \ year_]\  := \n\t
      \((FE`Private`$CurrentCalendarMakerYear\  = \ year; 
        FE`Private`$CurrentCalendarMakerMonth\  = \ 
          month; \n\t\tFE`Private`nb\  = \ 
          NotebookPut[
            Notebook[{monthcell[month, year]}, WindowElements \[Rule] {}, 
              WindowFrameElements \[Rule] "\<CloseBox\>", 
              WindowSize \[Rule] {Fit, 165}, WindowClickSelect \[Rule] False, 
              WindowFrame \[Rule] "\<Palette\>", 
              WindowTitle \[Rule] "\<Calendar\>", \n\t\t\t\t\tActive \[Rule] 
                True, Background \[Rule] 
                RGBColor[0.4, \ 0, \ 0.4]]]; \n\t\tSelectionMove[
          FE`Private`nb, \ Before, \ Notebook]; \n\t\tFE`Private`nb)\)\)], 
  "Input",
  InitializationCell->True],

Cell[TextData[{
  "MakeCalendar should accept the standard ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  " date format."
}], "Text"],

Cell[BoxData[
    \(MakeCalendar[{y_, m_, ___}] := MakeCalendar[m, y]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(MakeCalendar[] := MakeCalendar[Date[]]\)], "Input",
  InitializationCell->True],

Cell[TextData["Let\[CloseCurlyQuote]s try it out!"], "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    \(MakeCalendar[]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    InterpretationBox[
      \(\[SkeletonIndicator]  NotebookObject  \[SkeletonIndicator]\),
      NotebookObject[ 
        FrontEndObject[ 
          LinkObject[ "FM32411f40", 1, 1]], 23],
      Editable->False]], "Output"]
}, Open  ]],

Cell[TextData[
"Of course, a very large number of variants are possible. For instance, since \
each day is a button, those buttons could be made to call up a scheduler; \
alternately, they could access data relevant to the date. The days could be \
color\[Dash]coded for your favorite data set, e.g., stock performance or \
maximum temperature."], "Text"],

Cell["\<\
Many other notebook manipulation techniques exist, but this example hopefully \
gives a sense of a few of the tools that are available.\
\>", "Text"]
}, Closed]]
},
FrontEndVersion->"4.0 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 712}},
AutoGeneratedPackage->None,
WindowSize->{453, 325},
WindowMargins->{{1, Automatic}, {Automatic, 5}},
StyleDefinitions -> "Demo.nb"
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1717, 49, 14635, 185, 24, 14455, 179, "GraphicsData", 
"Bitmap", "HeaderCell",
  Evaluatable->False],
Cell[16355, 236, 57, 0, 79, "Title"],
Cell[16415, 238, 262, 6, 60, "Text"],
Cell[16680, 246, 334, 10, 63, "DisplayText"],

Cell[CellGroupData[{
Cell[17039, 260, 40, 0, 72, "Section"],
Cell[17082, 262, 385, 10, 90, "Text"],
Cell[17470, 274, 97, 2, 34, "Input",
  InitializationCell->True],
Cell[17570, 278, 205, 3, 60, "Text"],
Cell[17778, 283, 331, 6, 114, "Input",
  InitializationCell->True],
Cell[18112, 291, 283, 4, 75, "Text"],
Cell[18398, 297, 251, 5, 94, "Input",
  InitializationCell->True],
Cell[18652, 304, 211, 4, 75, "Text"],
Cell[18866, 310, 387, 9, 174, "Input",
  InitializationCell->True],
Cell[19256, 321, 62, 0, 30, "Text"],

Cell[CellGroupData[{
Cell[19343, 325, 66, 1, 34, "Input"],
Cell[19412, 328, 470, 12, 107, "Output"]
}, Open  ]],
Cell[19897, 343, 94, 1, 30, "Text"]
}, Closed]],

Cell[CellGroupData[{
Cell[20028, 349, 36, 0, 41, "Section"],
Cell[20067, 351, 450, 9, 90, "Text"],
Cell[20520, 362, 328, 5, 90, "Text"],
Cell[20851, 369, 349, 7, 75, "Text"],

Cell[CellGroupData[{
Cell[21225, 380, 360, 8, 154, "Input"],
Cell[21588, 390, 448, 10, 140, "Output"]
}, Open  ]],
Cell[22051, 403, 1432, 37, 195, "Text"],
Cell[23486, 442, 214, 3, 60, "Text"],
Cell[23703, 447, 182, 4, 54, "Input",
  InitializationCell->True],
Cell[23888, 453, 301, 6, 94, "Input",
  InitializationCell->True],
Cell[24192, 461, 963, 18, 165, "Text"],
Cell[25158, 481, 116, 3, 45, "Text"],
Cell[25277, 486, 813, 17, 334, "Input"],
Cell[26093, 505, 5646, 139, 169, "Input"],
Cell[31742, 646, 537, 11, 105, "Text"],
Cell[32282, 659, 1390, 26, 534, "Input"],
Cell[33675, 687, 7104, 171, 153, "Input"],
Cell[40782, 860, 613, 11, 135, "Text"],
Cell[41398, 873, 106, 2, 30, "Text"],
Cell[41507, 877, 1459, 29, 514, "Input",
  InitializationCell->True],
Cell[42969, 908, 102, 2, 54, "Input"],
Cell[43074, 912, 8033, 193, 171, "Input"]
}, Closed]],

Cell[CellGroupData[{
Cell[51144, 1110, 45, 0, 41, "Section"],
Cell[51192, 1112, 402, 10, 75, "Text"],
Cell[51597, 1124, 1373, 59, 175, "DisplayText",
  Evaluatable->False],
Cell[52973, 1185, 572, 15, 90, "Text"],
Cell[53548, 1202, 302, 4, 75, "Text"],
Cell[53853, 1208, 62, 0, 30, "Text"],

Cell[CellGroupData[{
Cell[53940, 1212, 120, 3, 94, "Input"],
Cell[54063, 1217, 238, 6, 48, "Output"]
}, Open  ]],
Cell[54316, 1226, 288, 4, 75, "Text"],
Cell[54607, 1232, 89, 2, 30, "Text"],
Cell[54699, 1236, 588, 11, 274, "Input"],
Cell[55290, 1249, 792, 26, 105, "Text"],
Cell[56085, 1277, 127, 3, 45, "Text"]
}, Closed]],

Cell[CellGroupData[{
Cell[56249, 1285, 43, 0, 41, "Section"],
Cell[56295, 1287, 534, 10, 105, "Text"],
Cell[56832, 1299, 1000, 22, 165, "Text"],
Cell[57835, 1323, 932, 18, 414, "Input"],
Cell[58770, 1343, 504, 13, 90, "Text"],
Cell[59277, 1358, 386, 6, 105, "Text"],
Cell[59666, 1366, 132, 3, 45, "Text"],
Cell[59801, 1371, 114, 2, 54, "Input"],
Cell[59918, 1375, 165, 3, 45, "Text"],
Cell[60086, 1380, 2427, 45, 974, "Input"],
Cell[62516, 1427, 271, 4, 75, "Text"]
}, Closed]],

Cell[CellGroupData[{
Cell[62824, 1436, 38, 0, 41, "Section"],
Cell[62865, 1438, 1693, 42, 241, "Text"],
Cell[64561, 1482, 464, 9, 90, "Text"],
Cell[65028, 1493, 2209, 41, 714, "Input",
  InitializationCell->True],
Cell[67240, 1536, 406, 12, 60, "Text"],
Cell[67649, 1550, 736, 13, 314, "Input",
  InitializationCell->True],
Cell[68388, 1565, 124, 2, 45, "Text"],
Cell[68515, 1569, 802, 15, 374, "Input",
  InitializationCell->True],
Cell[69320, 1586, 143, 5, 30, "Text"],
Cell[69466, 1593, 110, 2, 34, "Input",
  InitializationCell->True],
Cell[69579, 1597, 99, 2, 34, "Input",
  InitializationCell->True],
Cell[69681, 1601, 60, 0, 30, "Text"],

Cell[CellGroupData[{
Cell[69766, 1605, 75, 2, 34, "Input",
  InitializationCell->True],
Cell[69844, 1609, 238, 6, 48, "Output"]
}, Open  ]],
Cell[70097, 1618, 355, 5, 90, "Text"],
Cell[70455, 1625, 159, 3, 45, "Text"]
}, Closed]]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

