
Book(title) :=
[
WriteString("Reading index entry for book ");
WriteString(title);NewLine();

 plain["Title"] := title;
];

Bodied("ChapterIntro", 60000);


Blurb(text):=
[
  plain["Blurb"]:=text;
];

Bodied("Enumerate",2);

Bodied("Itemize",2);

Bodied("Item",1);

Bodied("Book",60000);

Bodied("Title",60000);
Bodied("Author",60000);

Bodied("Chapter",60000);

Bodied("Section",60000);
Bodied("SubSection",60000);
Bodied("Topical",60000);
Bodied("Text",60000);

Bodied("Blurb",60000);
Bodied("DocumentationComment",60000);


RuleBase("WriteItem",{item});
Rule("WriteItem",1,1,IsString(item)) WriteString(item);
Rule("WriteItem",1,2,True) Write(item);

WriteList(list):=
[
  ForEach(item,list)
  [
    WriteItem(item);
  ];
];


InitBooks():=
[
  site["Books"]:={};
];

SelectBook(book):=
[
  plain:=site["Books"][book];
];

InitBook(basename):=
[
  /* create a new book */
  site["Books"][basename]:={};
  SelectBook(basename);
  plain["BaseName"]:=basename;
  plain["Chapters"] := {};
  plain["Body"]:="";
  plain["Blurb"]:="";
  currentChapterIndex:=0;
  currentSectionIndex:=0;
];

GroupBooks(first,second):=
[
  site["Books"][first]["Chapters"] :=
    Concat(site["Books"][second]["Chapters"], site["Books"][first]["Chapters"]);
];

BookList():=
[
  Local(book,books,bl);
  bl:="";
  books:=AssocIndices(site["Books"]);
  ForEach(book,books)
  [
    Local(bookinfo);
    bookinfo:=site["Books"][book];

    bl:= bl : 
     "<TR>" : "<TD bgcolor=e0e0e0><FONT face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"3\">
     " : HtmlLink(bookinfo["Title"],book:"manual.html","","_top") :
     " (here a " : HtmlLink("no-frames version", bookinfo["BaseName"]:".html", "", "_top") : "in a single file)
" :
     "</TR><TR>" : "<TD bgcolor=ffffff><FONT face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"3\">
     " : bookinfo["Blurb"] :"</TR>";
    // this line prevents a crash :)
  ];
  bl;
];


EmitBookIndex():=
[
WriteString("Creating book index"); NewLine();
  ToFile(HtmlFile("books.html"))
  [
    WriteString(
      HtmlTag(html,
              HtmlTitle("Yacas documentation") :
              HtmlTag(font,
              "<center><H1>Yacas documentation</H1></center>":
              HtmlTag(body,HtmlTable(3,"",
/*              HtmlCaption("Yacas documentation"): */
              BookList()))) /*hier*/
             )
    );
  ];
  True;
];

// do not load any chapter files
IncludeFile(x) := True;

/* mathematical expressions */
RuleBase("TeXMath", {x});
RuleBase("TeXMathD", {x});
RuleBase("TeXMathD", {x,y});

HoldArg("TeXMath",x);
HoldArg("TeXMathD",x);

// Prepare the index
GenerateIndex() :=
[

	SetHtmlDirectory("");
	Use("styleplain");
	
	ToFile("manicon.html")
	WriteString("<HTML>
	<BODY BGCOLOR=ffffff>
	<A HREF=\"books.html\" TARGET=\"_parent\">
	  <img src=\"yacaslogo.gif\" BORDER=0>
	</A>
	</BODY>
	</HTML>
	");

	SetHtmlDirectory("");
	Use("styleplain");  /* style sheet for the documentation */
//	Use("indexmaker"); /* engine that renders book to html */

	InitBooks();        /* Initialize book building */

	InitBook("intro");
	Load("intro.book");

//	  GarbageCollect();

	InitBook("coding");
	Load("coding.book");

//	  GarbageCollect();

	InitBook("essays");
	Load("essays.book");

//	  GarbageCollect();

	InitBook("ref");
	Load("ref.book");

	InitBook("refprog");
	Load("refprog.book");

//	  GarbageCollect();

	InitBook("Algo");
	Load("Algo.book");	// note: manualmaker crashes mysteriously when trying to emit a book that was not loaded

//	  GarbageCollect();

	InitBook("NewDesign");
	Load("NewDesign.book");

	InitBook("LispProgramming");
	Load("LispProgramming.book");	// note: manualmaker crashes mysteriously when trying to emit a book that was not loaded


//	  GarbageCollect();

	/* make the index of framed books */
	EmitBookIndex();

];
