src/Pure/Thy/present.ML
author wenzelm
Thu Mar 27 14:41:21 2008 +0100 (2008-03-27)
changeset 26433 9c2cdf28ecec
parent 26323 73efc70edeef
child 26957 e3f04fdd994d
permissions -rw-r--r--
eliminated theory ProtoPure;
renamed ML_Context.the_context to ML_Context.the_global_context;
     1 (*  Title:      Pure/Thy/present.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
     4 
     5 Theory presentation: HTML, graph files, (PDF)LaTeX documents.
     6 *)
     7 
     8 signature BASIC_PRESENT =
     9 sig
    10   val no_document: ('a -> 'b) -> 'a -> 'b
    11   val section: string -> unit
    12 end;
    13 
    14 signature PRESENT =
    15 sig
    16   include BASIC_PRESENT
    17   val session_name: theory -> string
    18   val write_graph: {name: string, ID: string, dir: string, unfold: bool,
    19    path: string, parents: string list} list -> Path.T -> unit
    20   val display_graph: {name: string, ID: string, dir: string, unfold: bool,
    21    path: string, parents: string list} list -> unit
    22   val init: bool -> bool -> string -> bool -> string list -> string list ->
    23     string -> (bool * Path.T) option -> Url.T option * bool -> bool -> theory list -> unit
    24   val finish: unit -> unit
    25   val init_theory: string -> unit
    26   val verbatim_source: string -> (unit -> Symbol.symbol list) -> unit
    27   val theory_output: string -> string -> unit
    28   val begin_theory: int -> Path.T -> (Path.T * bool) list -> theory -> theory
    29   val add_hook: (string -> (string * thm list) list -> unit) -> unit
    30   val results: string -> (string * thm list) list -> unit
    31   val theorem: string -> thm -> unit
    32   val theorems: string -> thm list -> unit
    33   val chapter: string -> unit
    34   val subsection: string -> unit
    35   val subsubsection: string -> unit
    36   val drafts: string -> Path.T list -> Path.T
    37 end;
    38 
    39 structure Present: PRESENT =
    40 struct
    41 
    42 
    43 (** paths **)
    44 
    45 val output_path = Path.variable "ISABELLE_BROWSER_INFO";
    46 
    47 val tex_ext = Path.ext "tex";
    48 val tex_path = tex_ext o Path.basic;
    49 val html_ext = Path.ext "html";
    50 val html_path = html_ext o Path.basic;
    51 val index_path = Path.basic "index.html";
    52 val readme_html_path = Path.basic "README.html";
    53 val readme_path = Path.basic "README";
    54 val documentN = "document";
    55 val document_path = Path.basic documentN;
    56 val doc_indexN = "session";
    57 val graph_path = Path.basic "session.graph";
    58 val graph_pdf_path = Path.basic "session_graph.pdf";
    59 val graph_eps_path = Path.basic "session_graph.eps";
    60 
    61 val session_path = Path.basic ".session";
    62 val session_entries_path = Path.explode ".session/entries";
    63 val pre_index_path = Path.explode ".session/pre-index";
    64 
    65 fun mk_rel_path [] ys = Path.make ys
    66   | mk_rel_path xs [] = Path.appends (replicate (length xs) Path.parent)
    67   | mk_rel_path (ps as x :: xs) (qs as y :: ys) = if x = y then mk_rel_path xs ys else
    68       Path.appends (replicate (length ps) Path.parent @ [Path.make qs]);
    69 
    70 fun show_path path = Path.implode (Path.append (File.pwd ()) path);
    71 
    72 
    73 
    74 (** additional theory data **)
    75 
    76 structure BrowserInfoData = TheoryDataFun
    77 (
    78   type T = {name: string, session: string list, is_local: bool};
    79   val empty = {name = "", session = [], is_local = false}: T;
    80   val copy = I;
    81   fun extend _ = empty;
    82   fun merge _ _ = empty;
    83 );
    84 
    85 fun get_info thy =
    86   if member (op =) [Context.PureN, Context.CPureN] (Context.theory_name thy)
    87   then {name = Context.PureN, session = [], is_local = false}
    88   else BrowserInfoData.get thy;
    89 
    90 val session_name = #name o get_info;
    91 
    92 
    93 
    94 (** graphs **)
    95 
    96 type graph_node =
    97   {name: string, ID: string, dir: string, unfold: bool,
    98    path: string, parents: string list};
    99 
   100 fun write_graph gr path =
   101   File.write path (cat_lines (map (fn {name, ID, dir, unfold, path, parents} =>
   102     "\"" ^ name ^ "\" \"" ^ ID ^ "\" \"" ^ dir ^ (if unfold then "\" + \"" else "\" \"") ^
   103     path ^ "\" > " ^ space_implode " " (map Library.quote parents) ^ " ;") gr));
   104 
   105 fun display_graph gr =
   106   let
   107     val _ = writeln "Displaying graph ...";
   108     val path = File.tmp_path (Path.explode "tmp.graph");
   109     val _ = write_graph gr path;
   110     val _ = File.isatool ("browser -c " ^ File.shell_path path ^ " &");
   111   in () end;
   112 
   113 
   114 fun ID_of sess s = space_implode "/" (sess @ [s]);
   115 fun ID_of_thy thy = ID_of (#session (get_info thy)) (Context.theory_name thy);
   116 
   117 
   118 (*retrieve graph data from initial collection of theories*)
   119 fun init_graph remote_path curr_sess = rev o map (fn thy =>
   120   let
   121     val name = Context.theory_name thy;
   122     val {name = sess_name, session, is_local} = get_info thy;
   123     val path' = Path.append (Path.make session) (html_path name);
   124     val entry =
   125      {name = name, ID = ID_of session name, dir = sess_name,
   126       path =
   127         if null session then "" else
   128         if is_some remote_path andalso not is_local then
   129           Url.implode (Url.append (the remote_path) (Url.File
   130             (Path.append (Path.make session) (html_path name))))
   131         else Path.implode (Path.append (mk_rel_path curr_sess session) (html_path name)),
   132       unfold = false,
   133       parents = map ID_of_thy (Theory.parents_of thy)};
   134   in (0, entry) end);
   135 
   136 fun ins_graph_entry (i, entry as {ID, ...}) (gr: (int * graph_node) list) =
   137   (i, entry) :: filter_out (fn (_, entry') => #ID entry' = ID) gr;
   138 
   139 
   140 
   141 (** global browser info state **)
   142 
   143 (* type theory_info *)
   144 
   145 type theory_info = {tex_source: Buffer.T, html_source: Buffer.T, html: Buffer.T};
   146 
   147 fun make_theory_info (tex_source, html_source, html) =
   148   {tex_source = tex_source, html_source = html_source, html = html}: theory_info;
   149 
   150 val empty_theory_info = make_theory_info (Buffer.empty, Buffer.empty, Buffer.empty);
   151 
   152 fun map_theory_info f {tex_source, html_source, html} =
   153   make_theory_info (f (tex_source, html_source, html));
   154 
   155 
   156 (* type browser_info *)
   157 
   158 type browser_info = {theories: theory_info Symtab.table, files: (Path.T * string) list,
   159   tex_index: (int * string) list, html_index: (int * string) list, graph: (int * graph_node) list};
   160 
   161 fun make_browser_info (theories, files, tex_index, html_index, graph) =
   162   {theories = theories, files = files, tex_index = tex_index, html_index = html_index,
   163     graph = graph}: browser_info;
   164 
   165 val empty_browser_info = make_browser_info (Symtab.empty, [], [], [], []);
   166 
   167 fun init_browser_info remote_path curr_sess thys = make_browser_info
   168   (Symtab.empty, [], [], [], init_graph remote_path curr_sess thys);
   169 
   170 fun map_browser_info f {theories, files, tex_index, html_index, graph} =
   171   make_browser_info (f (theories, files, tex_index, html_index, graph));
   172 
   173 
   174 (* state *)
   175 
   176 val browser_info = ref empty_browser_info;
   177 fun change_browser_info f = CRITICAL (fn () => change browser_info (map_browser_info f));
   178 
   179 val suppress_tex_source = ref false;
   180 fun no_document f x = setmp_noncritical suppress_tex_source true f x;
   181 
   182 fun init_theory_info name info =
   183   change_browser_info (fn (theories, files, tex_index, html_index, graph) =>
   184     (Symtab.update (name, info) theories, files, tex_index, html_index, graph));
   185 
   186 fun change_theory_info name f =
   187   change_browser_info (fn (info as (theories, files, tex_index, html_index, graph)) =>
   188     (case Symtab.lookup theories name of
   189       NONE => (warning ("Browser info: cannot access theory document " ^ quote name); info)
   190     | SOME info => (Symtab.update (name, map_theory_info f info) theories, files,
   191         tex_index, html_index, graph)));
   192 
   193 
   194 fun add_file file =
   195   change_browser_info (fn (theories, files, tex_index, html_index, graph) =>
   196     (theories, file :: files, tex_index, html_index, graph));
   197 
   198 fun add_tex_index txt =
   199   change_browser_info (fn (theories, files, tex_index, html_index, graph) =>
   200     (theories, files, txt :: tex_index, html_index, graph));
   201 
   202 fun add_html_index txt =
   203   change_browser_info (fn (theories, files, tex_index, html_index, graph) =>
   204     (theories, files, tex_index, txt :: html_index, graph));
   205 
   206 fun add_graph_entry entry =
   207   change_browser_info (fn (theories, files, tex_index, html_index, graph) =>
   208     (theories, files, tex_index, html_index, ins_graph_entry entry graph));
   209 
   210 fun add_tex_source name txt =
   211   if ! suppress_tex_source then ()
   212   else change_theory_info name (fn (tex_source, html_source, html) =>
   213     (Buffer.add txt tex_source, html_source, html));
   214 
   215 fun add_html_source name txt = change_theory_info name (fn (tex_source, html_source, html) =>
   216   (tex_source, Buffer.add txt html_source, html));
   217 
   218 fun add_html name txt = change_theory_info name (fn (tex_source, html_source, html) =>
   219   (tex_source, html_source, Buffer.add txt html));
   220 
   221 
   222 
   223 (** global session state **)
   224 
   225 (* session_info *)
   226 
   227 type session_info =
   228   {name: string, parent: string, session: string, path: string list, html_prefix: Path.T,
   229     info: bool, doc_format: string, doc_graph: bool, documents: (string * string) list,
   230     doc_prefix1: (Path.T * Path.T) option, doc_prefix2: (bool * Path.T) option,
   231     remote_path: Url.T option, verbose: bool, readme: Path.T option};
   232 
   233 fun make_session_info
   234   (name, parent, session, path, html_prefix, info, doc_format, doc_graph, documents,
   235     doc_prefix1, doc_prefix2, remote_path, verbose, readme) =
   236   {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix,
   237     info = info, doc_format = doc_format, doc_graph = doc_graph, documents = documents,
   238     doc_prefix1 = doc_prefix1, doc_prefix2 = doc_prefix2, remote_path = remote_path,
   239     verbose = verbose, readme = readme}: session_info;
   240 
   241 
   242 (* state *)
   243 
   244 val session_info = ref (NONE: session_info option);
   245 
   246 fun with_session x f = (case ! session_info of NONE => x | SOME info => f info);
   247 fun with_context f = f (Context.theory_name (ML_Context.the_global_context ()));
   248 
   249 
   250 
   251 (** document preparation **)
   252 
   253 (* maintain index *)
   254 
   255 val session_entries =
   256   HTML.session_entries o
   257     map (fn name => (Url.File (Path.append (Path.basic name) index_path), name));
   258 
   259 fun get_entries dir =
   260   split_lines (File.read (Path.append dir session_entries_path));
   261 
   262 fun put_entries entries dir =
   263   File.write (Path.append dir session_entries_path) (cat_lines entries);
   264 
   265 
   266 fun create_index dir =
   267   File.read (Path.append dir pre_index_path) ^
   268     session_entries (get_entries dir) ^ HTML.end_index
   269   |> File.write (Path.append dir index_path);
   270 
   271 fun update_index dir name = CRITICAL (fn () =>
   272   (case try get_entries dir of
   273     NONE => warning ("Browser info: cannot access session index of " ^ quote (Path.implode dir))
   274   | SOME es => (put_entries ((remove (op =) name es) @ [name]) dir; create_index dir)));
   275 
   276 
   277 (* document versions *)
   278 
   279 fun read_version str =
   280   (case space_explode "=" str of
   281     [name] => (name, "")
   282   | [name, tags] => (name, tags)
   283   | _ => error ("Malformed document version specification: " ^ quote str));
   284 
   285 fun read_versions strs =
   286   rev (distinct (eq_fst (op =)) (rev ((documentN, "") :: map read_version strs)))
   287   |> filter_out (equal "-" o #2);
   288 
   289 
   290 (* init session *)
   291 
   292 fun name_of_session elems = space_implode "/" ("Isabelle" :: elems);
   293 
   294 fun init build info doc doc_graph doc_versions path name doc_prefix2
   295     (remote_path, first_time) verbose thys = CRITICAL (fn () =>
   296   if not build andalso not info andalso doc = "" andalso is_none doc_prefix2 then
   297     (browser_info := empty_browser_info; session_info := NONE)
   298   else
   299     let
   300       val parent_name = name_of_session (Library.take (length path - 1, path));
   301       val session_name = name_of_session path;
   302       val sess_prefix = Path.make path;
   303       val html_prefix = Path.append (Path.expand output_path) sess_prefix;
   304 
   305       val (doc_prefix1, documents) =
   306         if doc = "" then (NONE, [])
   307         else if not (File.exists document_path) then
   308           (if verbose then Output.std_error "Warning: missing document directory\n" else ();
   309             (NONE, []))
   310         else (SOME (Path.append html_prefix document_path, html_prefix),
   311           read_versions doc_versions);
   312 
   313       val parent_index_path = Path.append Path.parent index_path;
   314       val index_up_lnk = if first_time then
   315           Url.append (the remote_path) (Url.File (Path.append sess_prefix parent_index_path))
   316         else Url.File parent_index_path;
   317       val readme =
   318         if File.exists readme_html_path then SOME readme_html_path
   319         else if File.exists readme_path then SOME readme_path
   320         else NONE;
   321 
   322       val docs =
   323         (case readme of NONE => [] | SOME p => [(Url.File p, "README")]) @
   324         map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents;
   325       val index_text = HTML.begin_index (index_up_lnk, parent_name)
   326         (Url.File index_path, session_name) docs (Url.explode "medium.html");
   327     in
   328       session_info := SOME (make_session_info (name, parent_name, session_name, path, html_prefix,
   329       info, doc, doc_graph, documents, doc_prefix1, doc_prefix2, remote_path, verbose, readme));
   330       browser_info := init_browser_info remote_path path thys;
   331       add_html_index (0, index_text)
   332     end);
   333 
   334 
   335 (* isatool wrappers *)
   336 
   337 fun isatool_document verbose format name tags path result_path =
   338   let
   339     val s = "\"$ISATOOL\" document -c -o '" ^ format ^ "' \
   340       \-n '" ^ name ^ "' -t '" ^ tags ^ "' " ^ File.shell_path path ^
   341       " 2>&1" ^ (if verbose then "" else " >/dev/null");
   342     val doc_path = Path.append result_path (Path.ext format (Path.basic name));
   343   in
   344     if verbose then writeln s else ();
   345     system s;
   346     File.exists doc_path orelse
   347       error ("No document: " ^ quote (show_path doc_path));
   348     doc_path
   349   end;
   350 
   351 fun isatool_browser graph =
   352   let
   353     val pdf_path = File.tmp_path graph_pdf_path;
   354     val eps_path = File.tmp_path graph_eps_path;
   355     val gr_path = File.tmp_path graph_path;
   356     val s = "browser -o " ^ File.shell_path pdf_path ^ " " ^ File.shell_path gr_path;
   357   in
   358     write_graph graph gr_path;
   359     if File.isatool s <> 0 orelse not (File.exists eps_path) orelse not (File.exists pdf_path)
   360     then error "Failed to prepare dependency graph"
   361     else
   362       let val pdf = File.read pdf_path and eps = File.read eps_path
   363       in File.rm pdf_path; File.rm eps_path; File.rm gr_path; (pdf, eps) end
   364   end;
   365 
   366 
   367 (* finish session -- output all generated text *)
   368 
   369 fun sorted_index index = map snd (sort (int_ord o pairself fst) (rev index));
   370 fun index_buffer index = Buffer.add (implode (sorted_index index)) Buffer.empty;
   371 
   372 fun write_tex src name path =
   373   Buffer.write (Path.append path (tex_path name)) src;
   374 
   375 fun write_tex_index tex_index path =
   376   write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path;
   377 
   378 
   379 fun finish () = CRITICAL (fn () =>
   380     with_session () (fn {name, info, html_prefix, doc_format, doc_graph,
   381       documents, doc_prefix1, doc_prefix2, path, verbose, readme, ...} =>
   382   let
   383     val {theories, files, tex_index, html_index, graph} = ! browser_info;
   384     val thys = Symtab.dest theories;
   385     val parent_html_prefix = Path.append html_prefix Path.parent;
   386 
   387     fun finish_tex path (a, {tex_source, ...}: theory_info) = write_tex tex_source a path;
   388     fun finish_html (a, {html, ...}: theory_info) =
   389       Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html);
   390 
   391     val sorted_graph = sorted_index graph;
   392     val opt_graphs =
   393       if doc_graph andalso (is_some doc_prefix1 orelse is_some doc_prefix2) then
   394         SOME (isatool_browser sorted_graph)
   395       else NONE;
   396 
   397     fun prepare_sources cp path =
   398      (File.mkdir path;
   399       if cp then File.copy_dir document_path path else ();
   400       File.isatool ("latex -o sty " ^ File.shell_path (Path.append path (Path.basic "root.tex")));
   401       (case opt_graphs of NONE => () | SOME (pdf, eps) =>
   402         (File.write (Path.append path graph_pdf_path) pdf;
   403           File.write (Path.append path graph_eps_path) eps));
   404       write_tex_index tex_index path;
   405       List.app (finish_tex path) thys);
   406   in
   407     if info then
   408      (File.mkdir (Path.append html_prefix session_path);
   409       Buffer.write (Path.append html_prefix pre_index_path) (index_buffer html_index);
   410       File.write (Path.append html_prefix session_entries_path) "";
   411       create_index html_prefix;
   412       if length path > 1 then update_index parent_html_prefix name else ();
   413       (case readme of NONE => () | SOME path => File.copy path html_prefix);
   414       write_graph sorted_graph (Path.append html_prefix graph_path);
   415       File.copy (Path.explode "~~/lib/browser/GraphBrowser.jar") html_prefix;
   416       List.app (fn (a, txt) => File.write (Path.append html_prefix (Path.basic a)) txt)
   417         (HTML.applet_pages name (Url.File index_path, name));
   418       File.copy (Path.explode "~~/lib/html/isabelle.css") html_prefix;
   419       List.app finish_html thys;
   420       List.app (uncurry File.write) files;
   421       if verbose then Output.std_error ("Browser info at " ^ show_path html_prefix ^ "\n") else ())
   422     else ();
   423 
   424     (case doc_prefix2 of NONE => () | SOME (cp, path) =>
   425      (prepare_sources cp path;
   426       if verbose then Output.std_error ("Document sources at " ^ show_path path ^ "\n") else ()));
   427 
   428     (case doc_prefix1 of NONE => () | SOME (path, result_path) =>
   429       documents |> List.app (fn (name, tags) =>
   430        let
   431          val _ = prepare_sources true path;
   432          val doc_path = isatool_document true doc_format name tags path result_path;
   433        in
   434          if verbose then Output.std_error ("Document at " ^ show_path doc_path ^ "\n") else ()
   435        end));
   436 
   437     browser_info := empty_browser_info;
   438     session_info := NONE
   439   end));
   440 
   441 
   442 (* theory elements *)
   443 
   444 fun init_theory name = with_session () (fn _ => init_theory_info name empty_theory_info);
   445 
   446 fun verbatim_source name mk_text =
   447   with_session () (fn _ => add_html_source name (HTML.verbatim_source (mk_text ())));
   448 
   449 fun theory_output name s =
   450   with_session () (fn _ => add_tex_source name (Latex.isabelle_file name s));
   451 
   452 
   453 fun parent_link remote_path curr_session thy =
   454   let
   455     val {name = _, session, is_local} = get_info thy;
   456     val name = Context.theory_name thy;
   457     val link =
   458       if null session then NONE
   459       else SOME
   460        (if is_some remote_path andalso not is_local then
   461          Url.append (the remote_path) (Url.File (Path.append (Path.make session) (html_path name)))
   462         else Url.File (Path.append (mk_rel_path curr_session session) (html_path name)));
   463   in (link, name) end;
   464 
   465 fun begin_theory update_time dir files thy =
   466     with_session thy (fn {name = sess_name, session, path, html_prefix, remote_path, ...} =>
   467   let
   468     val name = Context.theory_name thy;
   469     val parents = Theory.parents_of thy;
   470     val parent_specs = map (parent_link remote_path path) parents;
   471 
   472     fun prep_file (raw_path, loadit) =
   473       (case ThyLoad.check_ml dir raw_path of
   474         SOME (path, _) =>
   475           let
   476             val base = Path.base path;
   477             val base_html = html_ext base;
   478             val _ = add_file (Path.append html_prefix base_html,
   479               HTML.ml_file (Url.File base) (File.read path));
   480           in (SOME (Url.File base_html), Url.File raw_path, loadit) end
   481       | NONE =>
   482           (warning ("Browser info: expected to find ML file" ^ quote (Path.implode raw_path));
   483             (NONE, Url.File raw_path, loadit)));
   484 
   485     fun prep_html_source (tex_source, html_source, html) =
   486       let
   487         val txt = HTML.begin_theory (Url.File index_path, session)
   488           name parent_specs (map prep_file files) (Buffer.content html_source)
   489       in (tex_source, Buffer.empty, Buffer.add txt html) end;
   490 
   491     val entry =
   492      {name = name, ID = ID_of path name, dir = sess_name, unfold = true,
   493       path = Path.implode (html_path name),
   494       parents = map ID_of_thy parents};
   495   in
   496     change_theory_info name prep_html_source;
   497     add_graph_entry (update_time, entry);
   498     add_html_index (update_time, HTML.theory_entry (Url.File (html_path name), name));
   499     add_tex_index (update_time, Latex.theory_entry name);
   500     BrowserInfoData.put {name = sess_name, session = path, is_local = is_some remote_path} thy
   501   end);
   502 
   503 
   504 val hooks = ref ([]: (string -> (string * thm list) list -> unit) list);
   505 fun add_hook f = CRITICAL (fn () => change hooks (cons f));
   506 
   507 fun results k xs =
   508  (List.app (fn f => (try (fn () => f k xs) (); ())) (! hooks);
   509   with_session () (fn _ => with_context add_html
   510     (HTML.results (ML_Context.the_local_context ()) k xs)));
   511 
   512 fun theorem a th = results Thm.theoremK [(a, [th])];
   513 fun theorems a ths = results Thm.theoremK [(a, ths)];
   514 fun chapter s = with_session () (fn _ => with_context add_html (HTML.chapter s));
   515 fun section s = with_session () (fn _ => with_context add_html (HTML.section s));
   516 fun subsection s = with_session () (fn _ => with_context add_html (HTML.subsection s));
   517 fun subsubsection s = with_session () (fn _ => with_context add_html (HTML.subsubsection s));
   518 
   519 
   520 
   521 (** draft document output **)
   522 
   523 fun drafts doc_format src_paths =
   524   let
   525     fun prep_draft path i =
   526       let
   527         val base = Path.base path;
   528         val name =
   529           (case Path.implode (#1 (Path.split_ext base)) of
   530             "" => "DUMMY" ^ serial_string ()
   531           | s => s);
   532       in
   533         if File.exists path then
   534           (((name, base, File.read path), (i, Latex.theory_entry name)), i + 1)
   535         else error ("Bad file: " ^ quote (Path.implode path))
   536       end;
   537     val (srcs, tex_index) = split_list (fst (fold_map prep_draft src_paths 0));
   538 
   539     val doc_path = File.tmp_path document_path;
   540     val result_path = Path.append doc_path Path.parent;
   541     val _ = File.mkdir doc_path;
   542     val root_path = Path.append doc_path (Path.basic "root.tex");
   543     val _ = File.copy (Path.explode "~~/lib/texinputs/draft.tex") root_path;
   544     val _ = File.isatool ("latex -o sty " ^ File.shell_path root_path);
   545     val _ = File.isatool ("latex -o syms " ^ File.shell_path root_path);
   546 
   547     fun known name =
   548       let val ss = split_lines (File.read (Path.append doc_path (Path.basic name)))
   549       in member (op =) ss end;
   550     val known_syms = known "syms.lst";
   551     val known_ctrls = known "ctrls.lst";
   552 
   553     val _ = srcs |> List.app (fn (name, base, txt) =>
   554       Symbol.explode txt
   555       |> Latex.symbol_source (known_syms, known_ctrls) (Path.implode base)
   556       |> File.write (Path.append doc_path (tex_path name)));
   557     val _ = write_tex_index tex_index doc_path;
   558   in isatool_document false doc_format documentN "" doc_path result_path end;
   559 
   560 
   561 end;
   562 
   563 structure BasicPresent: BASIC_PRESENT = Present;
   564 open BasicPresent;