##  this creates the documentation, needs: GAPDoc package, latex, pdflatex,
##  mkindex, dvips
##  
##  $Id:$
##  
LoadPackage("GAPDoc");
# temporarily overload handling of BibTeX file
Reread("BibTeX.gi");

# The manual of the package is referenced, avoid the ``not loaded'' remark.
LoadPackage( "atlasrep" );

MakeGAPDocDoc( "doc", "main", [
                 "../lib/atlasbrowse.g",
                 "../lib/browse.gd",
                 "../lib/browse.gi",
                 "../lib/ctbldisp.g",
                 "../lib/demo.g",
                 "../lib/gapbibl.g",
                 "../lib/knight.g",
                 "../lib/manual.g",
                 "../lib/ncurses.gd",
                 "../lib/ncurses.gi",
                 "../lib/puzzle.g",
                 "../lib/rubik.g",
                 "../lib/solitair.g",
                 "../lib/sudoku.g",
                 "../lib/tomdisp.g",
               ], "Browse", "../../.." );;

GAPDocManualLab("Browse");;

# Create the necessary `png' files.
CreatePictures:= function( filenames )
  local filename, str, pos, pos2, sub, nam;

  for filename in filenames do
    str:= StringFile( filename );
    pos:= PositionSublist( str, "<!-- BP" );
    pos2:= PositionSublist( str, "]]>\n##  <!-- EP" );
    while pos <> fail and pos2 <> fail do
      sub:= str{ [ pos + 8 .. pos2-1 ] };
      nam:= sub{ [ 1 .. Position( sub, ' ' ) - 1 ] };
      pos:= Position( sub, '\n' );
      pos:= Position( sub, '\n', pos );
      sub:= sub{ [ pos .. Length( sub ) ] };
      PrintTo( nam, "\\batchmode\\documentclass{article}\n",
                    "\\usepackage{graphicx}\\usepackage{epsfig}\n",
                    "\\pagestyle{empty}\\begin{document}\n",
                    ReplacedString( sub, "\n##  ", "\n" ),
                    "\n\\end{document}\n" );
      Exec( Concatenation( "latex ", nam ) );
      Exec( Concatenation( "dvips -o ", nam, ".ps ", nam ) );
      Exec( Concatenation( "gs -sDEVICE=ppmraw -sOutputFile=- -sNOPAUSE -q ",
                nam, ".ps -c showpage -c quit | pnmcrop| pnmmargin ",
                "-white 10 | pnmtopng > ", nam, ".png" ) );
      Exec( Concatenation( "rm -rf ", nam, " ", nam, ".aux ", nam, ".dvi ",
                nam, ".log ", nam, ".ps" ) );
      Exec( Concatenation( "mv ", nam, ".png doc" ) );

      pos:= PositionSublist( str, "<!-- BP", pos2 );
      pos2:= PositionSublist( str, "]]>\n##  <!-- EP", pos2 );
    od;
  od;
end;

CreatePictures( [ "lib/rubik.g", "lib/solitair.g" ] );

