
html:={};
html[["0"]]:="HTML";

book:={};
book[["0"]]:="H1";

chapter:={};
chapter[["0"]]:="H2";

section:={};
section[["0"]]:="H3";

subsection:={};
subsection[["0"]]:="H4";


body:={};
body[["0"]]:="BODY";
body[["BGCOLOR"]]:="ffffff";
body[["LINK"]]:="0000ff";
body[["VLINK"]]:="0000ff";

indexbody:={};
indexbody[["0"]]:="BODY";
indexbody[["BGCOLOR"]]:="f08040";
indexbody[["LINK"]]:="0000ff";
indexbody[["VLINK"]]:="0000ff";

ShowHtmlResult(input):=
[
 Local(l);

/* l:=*/
 Secure(
 HtmlCommand(
    ToString()
    If(input != ";",
    [
     Local(result,statement);
      statement:=FromString(input)Read();
      Apply("EvalFormula",{statement});
    ]
    ,
    "")
 ));
];


CalcForm(title,input,formtoshow):=
[
  HtmlTag(html,
          HtmlTitle(title) :
          HtmlTag(body,
  HtmlTag(book,title):
  ShowHtmlResult(input:";"):
  "<BR>" :
  formtoshow
) );
];


WithVariable(var):=
[
  If (Not(Apply("IsBound",{var})),MacroSet(var,""));
];
HoldArg("WithVariable",var);


AddExample(examples,name,vars):=
[
  Local(n);
  n:={};
  n[["vars"]]:= vars;
  examples[[name]] := n;
];

FetchNextExample(examples):=
[
  Local(tuple,varset);
  tuple:=examples[[ex]];

  [
    Local(ai,newind);
    ai:= DestructiveReverse(AssocIndices(examples));
    newind:=Find(ai,ex)-1;
    If(newind < 1,newind:=Length(ai));
    extitle:=examples[[newind ]][[1]];
  ];
  ForEach(varset,tuple[["vars"]])
  [
    MacroSet(Atom(varset[[1]]),varset[[2]]);
  ];
];

HtmlCommand(command):=
[
HtmlTable(3,"100%",
"<TR>" : "<TD WIDTH=100% bgcolor=c2c2c2>" : "<PRE>" : command : "</PRE>"
         );
];


