src/Pure/Thy/present.ML
author wenzelm
Sun Jan 25 22:11:06 2015 +0100 (2015-01-25)
changeset 59446 4427f04fca57
parent 59445 2c27c3d1fd3b
child 59448 149d2bc5ddb6
permissions -rw-r--r--
discontinued obsolete option "document_graph";
wenzelm@6203
     1
(*  Title:      Pure/Thy/present.ML
wenzelm@9416
     2
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
wenzelm@6203
     3
wenzelm@9416
     4
Theory presentation: HTML, graph files, (PDF)LaTeX documents.
wenzelm@6203
     5
*)
wenzelm@6203
     6
wenzelm@6203
     7
signature PRESENT =
wenzelm@6203
     8
sig
wenzelm@24561
     9
  val session_name: theory -> string
wenzelm@56614
    10
  val document_enabled: string -> bool
wenzelm@56612
    11
  val document_variants: string -> (string * string) list
wenzelm@59446
    12
  val init: bool -> bool -> Path.T -> string -> string -> (string * string) list ->
wenzelm@59445
    13
    (Path.T * Path.T) list -> Path.T -> string * string -> bool -> theory list -> unit
wenzelm@59445
    14
  val finish: unit -> unit
wenzelm@9136
    15
  val theory_output: string -> string -> unit
wenzelm@54456
    16
  val begin_theory: int -> (unit -> HTML.text) -> theory -> theory
wenzelm@52549
    17
  val display_drafts: Path.T list -> int
wenzelm@6203
    18
end;
wenzelm@6203
    19
wenzelm@7685
    20
structure Present: PRESENT =
wenzelm@7685
    21
struct
wenzelm@7685
    22
wenzelm@7727
    23
wenzelm@7727
    24
(** paths **)
wenzelm@7727
    25
wenzelm@7727
    26
val tex_ext = Path.ext "tex";
wenzelm@7727
    27
val tex_path = tex_ext o Path.basic;
wenzelm@7727
    28
val html_ext = Path.ext "html";
wenzelm@7727
    29
val html_path = html_ext o Path.basic;
wenzelm@7727
    30
val index_path = Path.basic "index.html";
wenzelm@11856
    31
val readme_html_path = Path.basic "README.html";
wenzelm@17082
    32
val documentN = "document";
wenzelm@17082
    33
val document_path = Path.basic documentN;
wenzelm@8196
    34
val doc_indexN = "session";
wenzelm@11856
    35
val graph_path = Path.basic "session.graph";
wenzelm@11856
    36
val graph_pdf_path = Path.basic "session_graph.pdf";
wenzelm@7727
    37
wenzelm@51415
    38
fun show_path path = Path.implode (Path.expand (Path.append (File.pwd ()) path));
wenzelm@11856
    39
wenzelm@7727
    40
wenzelm@14922
    41
wenzelm@7727
    42
(** additional theory data **)
wenzelm@7727
    43
wenzelm@42008
    44
structure Browser_Info = Theory_Data
wenzelm@22846
    45
(
wenzelm@51399
    46
  type T = {chapter: string, name: string};
wenzelm@51567
    47
  val empty = {chapter = "Unsorted", name = "Unknown"}: T;
wenzelm@16503
    48
  fun extend _ = empty;
wenzelm@33522
    49
  fun merge _ = empty;
wenzelm@22846
    50
);
wenzelm@7727
    51
wenzelm@53171
    52
val _ = Theory.setup
wenzelm@53171
    53
  (Browser_Info.put {chapter = Context.PureN, name = Context.PureN});
wenzelm@51567
    54
wenzelm@51399
    55
val session_name = #name o Browser_Info.get;
wenzelm@51399
    56
val session_chapter_name = (fn {chapter, name} => [chapter, name]) o Browser_Info.get;
wenzelm@24561
    57
wenzelm@7727
    58
wenzelm@7727
    59
wenzelm@7727
    60
(** graphs **)
wenzelm@7727
    61
wenzelm@59209
    62
fun ident_of sess s = space_implode "/" (sess @ [s]);
wenzelm@59209
    63
fun ident_of_thy thy = ident_of (session_chapter_name thy) (Context.theory_name thy);
wenzelm@7727
    64
wenzelm@51400
    65
fun theory_link (curr_chapter, curr_session) thy =
wenzelm@51399
    66
  let
wenzelm@51400
    67
    val {chapter, name = session} = Browser_Info.get thy;
wenzelm@51400
    68
    val link = html_path (Context.theory_name thy);
wenzelm@51399
    69
  in
wenzelm@51400
    70
    if curr_session = session then SOME link
wenzelm@51400
    71
    else if curr_chapter = chapter then
wenzelm@51400
    72
      SOME (Path.appends [Path.parent, Path.basic session, link])
wenzelm@51400
    73
    else if chapter = Context.PureN then NONE
wenzelm@51400
    74
    else SOME (Path.appends [Path.parent, Path.parent, Path.basic chapter, Path.basic session, link])
wenzelm@51399
    75
  end;
wenzelm@23899
    76
wenzelm@59210
    77
fun init_graph_entry session thy =
wenzelm@7727
    78
  let
wenzelm@59210
    79
    val ident = ident_of_thy thy;
wenzelm@59210
    80
    val parents = map ident_of_thy (Theory.parents_of thy);
wenzelm@59210
    81
    val node =
wenzelm@59210
    82
      Graph_Display.session_node
wenzelm@59210
    83
       {name = Context.theory_name thy,
wenzelm@59210
    84
        unfold = false,
wenzelm@59210
    85
        directory = session_name thy,
wenzelm@59210
    86
        path =
wenzelm@59210
    87
          (case theory_link session thy of
wenzelm@59210
    88
            NONE => ""
wenzelm@59210
    89
          | SOME p => Path.implode p)};
wenzelm@59210
    90
  in ((ident, node), parents) end;
wenzelm@7727
    91
wenzelm@7727
    92
wenzelm@7727
    93
wenzelm@7727
    94
(** global browser info state **)
wenzelm@7727
    95
wenzelm@7727
    96
(* type theory_info *)
wenzelm@7727
    97
wenzelm@54456
    98
type theory_info = {tex_source: string, html_source: string};
wenzelm@7727
    99
wenzelm@54456
   100
fun make_theory_info (tex_source, html_source) =
wenzelm@54456
   101
  {tex_source = tex_source, html_source = html_source}: theory_info;
wenzelm@7727
   102
wenzelm@54456
   103
fun map_theory_info f {tex_source, html_source} =
wenzelm@54456
   104
  make_theory_info (f (tex_source, html_source));
wenzelm@7727
   105
wenzelm@7727
   106
wenzelm@7727
   107
(* type browser_info *)
wenzelm@7727
   108
wenzelm@54455
   109
type browser_info =
wenzelm@54455
   110
 {theories: theory_info Symtab.table,
wenzelm@54455
   111
  tex_index: (int * string) list,
wenzelm@54455
   112
  html_index: (int * string) list,
wenzelm@59244
   113
  graph: Graph_Display.entry list};
wenzelm@7727
   114
wenzelm@54455
   115
fun make_browser_info (theories, tex_index, html_index, graph) : browser_info =
wenzelm@54455
   116
  {theories = theories, tex_index = tex_index, html_index = html_index, graph = graph};
wenzelm@7727
   117
wenzelm@54455
   118
val empty_browser_info = make_browser_info (Symtab.empty, [], [], []);
wenzelm@7727
   119
wenzelm@51400
   120
fun init_browser_info session thys =
wenzelm@59210
   121
  make_browser_info (Symtab.empty, [], [], map (init_graph_entry session) thys);
wenzelm@7727
   122
wenzelm@54455
   123
fun map_browser_info f {theories, tex_index, html_index, graph} =
wenzelm@54455
   124
  make_browser_info (f (theories, tex_index, html_index, graph));
wenzelm@7727
   125
wenzelm@7727
   126
wenzelm@7727
   127
(* state *)
wenzelm@7727
   128
wenzelm@59173
   129
val browser_info = Synchronized.var "browser_info" empty_browser_info;
wenzelm@59173
   130
fun change_browser_info f = Synchronized.change browser_info (map_browser_info f);
wenzelm@7727
   131
wenzelm@7727
   132
fun init_theory_info name info =
wenzelm@54455
   133
  change_browser_info (fn (theories, tex_index, html_index, graph) =>
wenzelm@54455
   134
    (Symtab.update (name, info) theories, tex_index, html_index, graph));
wenzelm@7727
   135
wenzelm@7727
   136
fun change_theory_info name f =
wenzelm@54455
   137
  change_browser_info (fn (theories, tex_index, html_index, graph) =>
wenzelm@17412
   138
    (case Symtab.lookup theories name of
wenzelm@27491
   139
      NONE => error ("Browser info: cannot access theory document " ^ quote name)
wenzelm@54455
   140
    | SOME info =>
wenzelm@54455
   141
        (Symtab.update (name, map_theory_info f info) theories, tex_index, html_index, graph)));
wenzelm@7727
   142
wenzelm@7727
   143
wenzelm@7727
   144
fun add_tex_index txt =
wenzelm@54455
   145
  change_browser_info (fn (theories, tex_index, html_index, graph) =>
wenzelm@54455
   146
    (theories, txt :: tex_index, html_index, graph));
wenzelm@7727
   147
wenzelm@7727
   148
fun add_html_index txt =
wenzelm@54455
   149
  change_browser_info (fn (theories, tex_index, html_index, graph) =>
wenzelm@54455
   150
    (theories, tex_index, txt :: html_index, graph));
wenzelm@7727
   151
wenzelm@24150
   152
fun add_graph_entry entry =
wenzelm@54455
   153
  change_browser_info (fn (theories, tex_index, html_index, graph) =>
wenzelm@59210
   154
    (theories, tex_index, html_index, update Graph_Display.eq_entry entry graph));
wenzelm@7727
   155
wenzelm@7727
   156
wenzelm@7727
   157
wenzelm@7727
   158
(** global session state **)
wenzelm@7727
   159
wenzelm@7727
   160
(* session_info *)
wenzelm@7727
   161
wenzelm@7727
   162
type session_info =
wenzelm@59446
   163
  {name: string, chapter: string, info_path: Path.T, info: bool, doc_format: string,
wenzelm@59446
   164
    doc_output: Path.T option, doc_files: (Path.T * Path.T) list, graph_file: Path.T,
wenzelm@59446
   165
    documents: (string * string) list, verbose: bool, readme: Path.T option};
wenzelm@7727
   166
wenzelm@9416
   167
fun make_session_info
wenzelm@59446
   168
  (name, chapter, info_path, info, doc_format, doc_output, doc_files,
wenzelm@59446
   169
    graph_file, documents, verbose, readme) =
wenzelm@59446
   170
  {name = name, chapter = chapter, info_path = info_path, info = info, doc_format = doc_format,
wenzelm@59446
   171
    doc_output = doc_output, doc_files = doc_files, graph_file = graph_file,
wenzelm@59446
   172
    documents = documents, verbose = verbose, readme = readme}: session_info;
wenzelm@7685
   173
wenzelm@7685
   174
wenzelm@7727
   175
(* state *)
wenzelm@7727
   176
wenzelm@32738
   177
val session_info = Unsynchronized.ref (NONE: session_info option);
wenzelm@7727
   178
wenzelm@51399
   179
fun with_session_info x f = (case ! session_info of NONE => x | SOME info => f info);
wenzelm@7727
   180
wenzelm@7727
   181
wenzelm@7727
   182
wenzelm@14922
   183
(** document preparation **)
wenzelm@7727
   184
wenzelm@56614
   185
(* options *)
wenzelm@56614
   186
wenzelm@56614
   187
fun document_enabled s = s <> "" andalso s <> "false";
wenzelm@17082
   188
wenzelm@56612
   189
fun document_variants str =
wenzelm@56612
   190
  let
wenzelm@56612
   191
    fun read_variant s =
wenzelm@56612
   192
      (case space_explode "=" s of
wenzelm@56612
   193
        [name] => (name, "")
wenzelm@56612
   194
      | [name, tags] => (name, tags)
wenzelm@56612
   195
      | _ => error ("Malformed document variant specification: " ^ quote s));
wenzelm@56612
   196
    val variants = map read_variant (space_explode ":" str);
wenzelm@56612
   197
    val _ =
wenzelm@56612
   198
      (case duplicates (op =) (map #1 variants) of
wenzelm@56612
   199
        [] => ()
wenzelm@56612
   200
      | dups => error ("Duplicate document variants: " ^ commas_quote dups));
wenzelm@56612
   201
  in variants end;
wenzelm@17082
   202
wenzelm@17082
   203
wenzelm@7727
   204
(* init session *)
wenzelm@7727
   205
wenzelm@59446
   206
fun init build info info_path doc document_output doc_variants doc_files graph_file
wenzelm@56530
   207
    (chapter, name) verbose thys =
wenzelm@56530
   208
  if not build andalso not info andalso doc = "" then
wenzelm@59173
   209
    (Synchronized.change browser_info (K empty_browser_info); session_info := NONE)
wenzelm@11856
   210
  else
wenzelm@11856
   211
    let
wenzelm@51399
   212
      val doc_output =
wenzelm@51399
   213
        if document_output = "" then NONE else SOME (Path.explode document_output);
wenzelm@7727
   214
wenzelm@42007
   215
      val documents =
wenzelm@42007
   216
        if doc = "" then []
wenzelm@56533
   217
        else if null doc_files andalso not (can File.check_dir document_path) then
wenzelm@44389
   218
          (if verbose then Output.physical_stderr "Warning: missing document directory\n"
wenzelm@44389
   219
           else (); [])
wenzelm@48804
   220
        else doc_variants;
wenzelm@7727
   221
wenzelm@51419
   222
      val readme = if File.exists readme_html_path then SOME readme_html_path else NONE;
wenzelm@7727
   223
wenzelm@17082
   224
      val docs =
wenzelm@17082
   225
        (case readme of NONE => [] | SOME p => [(Url.File p, "README")]) @
wenzelm@42007
   226
          map (fn (name, _) => (Url.File (Path.ext doc (Path.basic name)), name)) documents;
wenzelm@11856
   227
    in
wenzelm@42007
   228
      session_info :=
wenzelm@51399
   229
        SOME (make_session_info (name, chapter, info_path, info, doc,
wenzelm@59446
   230
          doc_output, doc_files, graph_file, documents, verbose, readme));
wenzelm@59173
   231
      Synchronized.change browser_info (K (init_browser_info (chapter, name) thys));
wenzelm@51401
   232
      add_html_index (0, HTML.begin_session_index name docs (Url.explode "medium.html"))
wenzelm@42008
   233
    end;
wenzelm@7727
   234
wenzelm@7727
   235
wenzelm@28496
   236
(* isabelle tool wrappers *)
wenzelm@17082
   237
wenzelm@48805
   238
fun isabelle_document {verbose, purge} format name tags dir =
wenzelm@17082
   239
  let
wenzelm@48805
   240
    val s = "\"$ISABELLE_TOOL\" document" ^ (if purge then " -c" else "") ^ " -o '" ^ format ^ "' \
wenzelm@48805
   241
      \-n '" ^ name ^ "' -t '" ^ tags ^ "' " ^ File.shell_path dir ^ " 2>&1";
wenzelm@48805
   242
    val doc_path = Path.appends [dir, Path.parent, Path.basic name |> Path.ext format];
wenzelm@33682
   243
    val _ = if verbose then writeln s else ();
wenzelm@43850
   244
    val (out, rc) = Isabelle_System.bash_output s;
wenzelm@33682
   245
    val _ =
wenzelm@33682
   246
      if not (File.exists doc_path) orelse rc <> 0 then
wenzelm@33682
   247
        cat_error out ("Failed to build document " ^ quote (show_path doc_path))
wenzelm@33682
   248
      else if verbose then writeln out
wenzelm@33682
   249
      else ();
wenzelm@33682
   250
  in doc_path end;
wenzelm@17082
   251
wenzelm@17082
   252
wenzelm@11856
   253
(* finish session -- output all generated text *)
wenzelm@11856
   254
wenzelm@59058
   255
fun sorted_index index = map snd (sort (int_ord o apply2 fst) (rev index));
wenzelm@24150
   256
fun index_buffer index = Buffer.add (implode (sorted_index index)) Buffer.empty;
wenzelm@24150
   257
wenzelm@14922
   258
fun write_tex src name path =
wenzelm@28027
   259
  File.write_buffer (Path.append path (tex_path name)) src;
wenzelm@14922
   260
wenzelm@14922
   261
fun write_tex_index tex_index path =
wenzelm@24150
   262
  write_tex (index_buffer tex_index |> Buffer.add Latex.tex_trailer) doc_indexN path;
wenzelm@14922
   263
wenzelm@42008
   264
fun finish () =
wenzelm@59446
   265
  with_session_info () (fn {name, chapter, info, info_path, doc_format,
wenzelm@59445
   266
    doc_output, doc_files, graph_file, documents, verbose, readme, ...} =>
wenzelm@7727
   267
  let
wenzelm@59173
   268
    val {theories, tex_index, html_index, graph} = Synchronized.value browser_info;
wenzelm@11856
   269
    val thys = Symtab.dest theories;
wenzelm@59445
   270
    val sorted_graph = Graph_Display.sort_graph graph;
wenzelm@51399
   271
wenzelm@51399
   272
    val chapter_prefix = Path.append info_path (Path.basic chapter);
wenzelm@51399
   273
    val session_prefix = Path.append chapter_prefix (Path.basic name);
wenzelm@7727
   274
wenzelm@54456
   275
    fun finish_html (a, {html_source, ...}: theory_info) =
wenzelm@54456
   276
      File.write (Path.append session_prefix (html_path a)) html_source;
wenzelm@11856
   277
wenzelm@42007
   278
    val _ =
wenzelm@42007
   279
      if info then
wenzelm@51399
   280
       (Isabelle_System.mkdirs session_prefix;
wenzelm@51399
   281
        File.write_buffer (Path.append session_prefix index_path)
wenzelm@51399
   282
          (index_buffer html_index |> Buffer.add HTML.end_document);
wenzelm@56533
   283
        (case readme of NONE => () | SOME path => Isabelle_System.copy_file path session_prefix);
wenzelm@59210
   284
        Graph_Display.write_graph_browser (Path.append session_prefix graph_path) sorted_graph;
wenzelm@42007
   285
        Isabelle_System.isabelle_tool "browser" "-b";
wenzelm@56533
   286
        Isabelle_System.copy_file (Path.explode "~~/lib/browser/GraphBrowser.jar") session_prefix;
wenzelm@51399
   287
        List.app (fn (a, txt) => File.write (Path.append session_prefix (Path.basic a)) txt)
wenzelm@42007
   288
          (HTML.applet_pages name (Url.File index_path, name));
wenzelm@56533
   289
        Isabelle_System.copy_file (Path.explode "~~/etc/isabelle.css") session_prefix;
wenzelm@42007
   290
        List.app finish_html thys;
wenzelm@54455
   291
        if verbose
wenzelm@54455
   292
        then Output.physical_stderr ("Browser info at " ^ show_path session_prefix ^ "\n")
wenzelm@42007
   293
        else ())
wenzelm@42007
   294
      else ();
wenzelm@42007
   295
wenzelm@56533
   296
    fun document_job doc_prefix backdrop (doc_name, tags) =
wenzelm@48935
   297
      let
wenzelm@56533
   298
        val doc_dir = Path.append doc_prefix (Path.basic doc_name);
wenzelm@56531
   299
        val _ = Isabelle_System.mkdirs doc_dir;
wenzelm@56531
   300
        val _ =
wenzelm@56531
   301
          Isabelle_System.isabelle_tool "latex"
wenzelm@56531
   302
            ("-o sty " ^ File.shell_path (Path.append doc_dir (Path.basic "root.tex")));
wenzelm@57885
   303
        val _ = List.app (fn file => Isabelle_System.copy_file_base file doc_dir) doc_files;
wenzelm@59445
   304
        val _ = Isabelle_System.copy_file graph_file (Path.append doc_dir graph_pdf_path);
wenzelm@56531
   305
        val _ = write_tex_index tex_index doc_dir;
wenzelm@56531
   306
        val _ =
wenzelm@56531
   307
          List.app (fn (a, {tex_source, ...}) =>
wenzelm@56531
   308
            write_tex (Buffer.add tex_source Buffer.empty) a doc_dir) thys;
wenzelm@48935
   309
      in
wenzelm@48935
   310
        fn () =>
wenzelm@56533
   311
          (isabelle_document {verbose = true, purge = backdrop} doc_format doc_name tags doc_dir,
wenzelm@56531
   312
            fn doc =>
wenzelm@56531
   313
              if verbose orelse not backdrop then
wenzelm@56531
   314
                Output.physical_stderr ("Document at " ^ show_path doc ^ "\n")
wenzelm@56531
   315
              else ())
wenzelm@48935
   316
      end;
wenzelm@48935
   317
wenzelm@48935
   318
    val jobs =
wenzelm@48935
   319
      (if info orelse is_none doc_output then
wenzelm@51399
   320
        map (document_job session_prefix true) documents
wenzelm@48935
   321
       else []) @
wenzelm@48935
   322
      (case doc_output of
wenzelm@48935
   323
        NONE => []
wenzelm@48935
   324
      | SOME path => map (document_job path false) documents);
wenzelm@48935
   325
wenzelm@48935
   326
    val _ = jobs |> Par_List.map (fn job => job ()) |> List.app (op |>);
wenzelm@7727
   327
  in
wenzelm@59173
   328
    Synchronized.change browser_info (K empty_browser_info);
skalberg@15531
   329
    session_info := NONE
wenzelm@42008
   330
  end);
wenzelm@7727
   331
wenzelm@7727
   332
wenzelm@7727
   333
(* theory elements *)
wenzelm@7727
   334
wenzelm@9136
   335
fun theory_output name s =
wenzelm@54458
   336
  with_session_info () (fn _ =>
wenzelm@58870
   337
    change_theory_info name (fn (_, html_source) => (Latex.isabelle_theory name s, html_source)));
wenzelm@7727
   338
wenzelm@54456
   339
fun begin_theory update_time mk_text thy =
wenzelm@54456
   340
  with_session_info thy (fn {name = session_name, chapter, ...} =>
wenzelm@54456
   341
    let
wenzelm@54456
   342
      val name = Context.theory_name thy;
wenzelm@54456
   343
      val parents = Theory.parents_of thy;
wenzelm@54456
   344
wenzelm@54456
   345
      val parent_specs = parents |> map (fn parent =>
wenzelm@54456
   346
        (Option.map Url.File (theory_link (chapter, session_name) parent),
wenzelm@54456
   347
          (Context.theory_name parent)));
wenzelm@54456
   348
      val html_source = HTML.theory name parent_specs (mk_text ());
wenzelm@7727
   349
wenzelm@54456
   350
      val graph_entry =
wenzelm@59210
   351
        ((ident_of [chapter, session_name] name,
wenzelm@59210
   352
          Graph_Display.session_node
wenzelm@59210
   353
           {name = name,
wenzelm@59210
   354
            directory = session_name,
wenzelm@59210
   355
            unfold = true,
wenzelm@59210
   356
            path = Path.implode (html_path name)}),
wenzelm@59210
   357
          map ident_of_thy parents);
wenzelm@54456
   358
    in
wenzelm@54456
   359
      init_theory_info name (make_theory_info ("", html_source));
wenzelm@59210
   360
      add_graph_entry graph_entry;
wenzelm@54456
   361
      add_html_index (update_time, HTML.theory_entry (Url.File (html_path name), name));
wenzelm@54456
   362
      add_tex_index (update_time, Latex.theory_entry name);
wenzelm@54456
   363
      Browser_Info.put {chapter = chapter, name = session_name} thy
wenzelm@54456
   364
    end);
wenzelm@7727
   365
wenzelm@7727
   366
wenzelm@7727
   367
wenzelm@42127
   368
(** draft document output **)
wenzelm@14922
   369
wenzelm@52549
   370
fun display_drafts src_paths = Isabelle_System.with_tmp_dir "drafts" (fn dir =>
wenzelm@14922
   371
  let
wenzelm@24150
   372
    fun prep_draft path i =
wenzelm@14935
   373
      let
wenzelm@14935
   374
        val base = Path.base path;
wenzelm@14972
   375
        val name =
wenzelm@24829
   376
          (case Path.implode (#1 (Path.split_ext base)) of
wenzelm@44986
   377
            "" => "DUMMY"
wenzelm@44986
   378
          | s => s)  ^ serial_string ();
wenzelm@14935
   379
      in
wenzelm@14935
   380
        if File.exists path then
wenzelm@24150
   381
          (((name, base, File.read path), (i, Latex.theory_entry name)), i + 1)
wenzelm@41944
   382
        else error ("Bad file: " ^ Path.print path)
wenzelm@14935
   383
      end;
wenzelm@24150
   384
    val (srcs, tex_index) = split_list (fst (fold_map prep_draft src_paths 0));
wenzelm@14935
   385
wenzelm@42127
   386
    val doc_path = Path.append dir document_path;
wenzelm@40743
   387
    val _ = Isabelle_System.mkdirs doc_path;
wenzelm@14922
   388
    val root_path = Path.append doc_path (Path.basic "root.tex");
wenzelm@56533
   389
    val _ = Isabelle_System.copy_file (Path.explode "~~/lib/texinputs/draft.tex") root_path;
wenzelm@40743
   390
    val _ = Isabelle_System.isabelle_tool "latex" ("-o sty " ^ File.shell_path root_path);
wenzelm@40743
   391
    val _ = Isabelle_System.isabelle_tool "latex" ("-o syms " ^ File.shell_path root_path);
wenzelm@14922
   392
wenzelm@14922
   393
    fun known name =
wenzelm@14922
   394
      let val ss = split_lines (File.read (Path.append doc_path (Path.basic name)))
wenzelm@20664
   395
      in member (op =) ss end;
wenzelm@14922
   396
    val known_syms = known "syms.lst";
wenzelm@14922
   397
    val known_ctrls = known "ctrls.lst";
wenzelm@14922
   398
skalberg@15570
   399
    val _ = srcs |> List.app (fn (name, base, txt) =>
wenzelm@14935
   400
      Symbol.explode txt
wenzelm@21858
   401
      |> Latex.symbol_source (known_syms, known_ctrls) (Path.implode base)
wenzelm@14935
   402
      |> File.write (Path.append doc_path (tex_path name)));
wenzelm@14922
   403
    val _ = write_tex_index tex_index doc_path;
wenzelm@14922
   404
wenzelm@48805
   405
    val result =
wenzelm@52743
   406
      isabelle_document {verbose = false, purge = true} "pdf" documentN "" doc_path;
wenzelm@54683
   407
wenzelm@54683
   408
    val target_dir = Path.explode "$ISABELLE_HOME_USER/tmp";
wenzelm@54683
   409
    val target = Path.explode "$ISABELLE_HOME_USER/tmp/drafts.pdf"
wenzelm@54683
   410
    val _ = Isabelle_System.mkdirs target_dir;
wenzelm@56533
   411
    val _ = Isabelle_System.copy_file result target;
wenzelm@52549
   412
  in
wenzelm@54683
   413
    Isabelle_System.isabelle_tool "display" (File.shell_path target ^ " &")
wenzelm@52549
   414
  end);
wenzelm@14922
   415
wenzelm@7685
   416
end;
wenzelm@7685
   417