src/Pure/Thy/present.ML
changeset 67197 b335e255ebcc
parent 67194 1c0a6a957114
child 67263 449a989f42cd
equal deleted inserted replaced
67196:eb29f4868d14 67197:b335e255ebcc
   186     end;
   186     end;
   187 
   187 
   188 
   188 
   189 (* isabelle tool wrappers *)
   189 (* isabelle tool wrappers *)
   190 
   190 
   191 fun isabelle_document {verbose, purge} format name tags dir =
   191 fun isabelle_document {verbose} format name tags dir =
   192   let
   192   let
   193     val script =
   193     val script =
   194       "isabelle document -d " ^ File.bash_path dir ^ " -o " ^ Bash.string format ^
   194       "isabelle document -d " ^ File.bash_path dir ^ " -o " ^ Bash.string format ^
   195         " -n " ^ Bash.string name ^ " -t " ^ Bash.string tags;
   195         " -n " ^ Bash.string name ^ " -t " ^ Bash.string tags;
   196     val doc_path = Path.appends [dir, Path.parent, Path.basic name |> Path.ext format];
   196     val doc_path = Path.appends [dir, Path.parent, Path.basic name |> Path.ext format];
   197     val _ = if purge then Isabelle_System.rm_tree dir else ();
       
   198     val _ = if verbose then writeln script else ();
   197     val _ = if verbose then writeln script else ();
   199     val {out, err, rc, ...} = Bash.process script;
   198     val {out, err, rc, ...} = Bash.process script;
   200     val _ = if verbose then writeln (trim_line (normalize_lines out)) else ();
   199     val _ = if verbose then writeln (trim_line (normalize_lines out)) else ();
   201     val _ = if not (File.exists doc_path) orelse rc <> 0 then error (trim_line err) else ();
   200     val _ = if not (File.exists doc_path) orelse rc <> 0 then error (trim_line err) else ();
   202     val _ = if purge then Isabelle_System.rm_tree dir else ();
       
   203   in doc_path end;
   201   in doc_path end;
   204 
   202 
   205 
   203 
   206 (* finish session -- output all generated text *)
   204 (* finish session -- output all generated text *)
   207 
   205 
   240       else ();
   238       else ();
   241 
   239 
   242     fun document_job doc_prefix backdrop (doc_name, tags) =
   240     fun document_job doc_prefix backdrop (doc_name, tags) =
   243       let
   241       let
   244         val doc_dir = Path.append doc_prefix (Path.basic doc_name);
   242         val doc_dir = Path.append doc_prefix (Path.basic doc_name);
       
   243         fun purge () = if backdrop then Isabelle_System.rm_tree doc_dir else ();
       
   244         val _ = purge ();
   245         val _ = Isabelle_System.mkdirs doc_dir;
   245         val _ = Isabelle_System.mkdirs doc_dir;
   246         val _ =
   246         val _ =
   247           Isabelle_System.bash ("isabelle latex -o sty " ^
   247           Isabelle_System.bash ("isabelle latex -o sty " ^
   248             File.bash_path (Path.append doc_dir (Path.basic "root.tex")));
   248             File.bash_path (Path.append doc_dir (Path.basic "root.tex")));
   249         val _ = List.app (fn file => Isabelle_System.copy_file_base file doc_dir) doc_files;
   249         val _ = List.app (fn file => Isabelle_System.copy_file_base file doc_dir) doc_files;
   252         val _ =
   252         val _ =
   253           List.app (fn (a, {tex_source, ...}) =>
   253           List.app (fn (a, {tex_source, ...}) =>
   254             write_tex (Buffer.add tex_source Buffer.empty) a doc_dir) thys;
   254             write_tex (Buffer.add tex_source Buffer.empty) a doc_dir) thys;
   255       in
   255       in
   256         fn () =>
   256         fn () =>
   257           (isabelle_document {verbose = true, purge = backdrop} doc_format doc_name tags doc_dir,
   257           (isabelle_document {verbose = true} doc_format doc_name tags doc_dir before purge (),
   258             fn doc =>
   258             fn doc =>
   259               if verbose orelse not backdrop then
   259               if verbose orelse not backdrop then
   260                 Output.physical_stderr ("Document at " ^ show_path doc ^ "\n")
   260                 Output.physical_stderr ("Document at " ^ show_path doc ^ "\n")
   261               else ())
   261               else ())
   262       end;
   262       end;
   357       Symbol.explode txt
   357       Symbol.explode txt
   358       |> Latex.symbol_source (known_syms, known_ctrls) (Path.implode base)
   358       |> Latex.symbol_source (known_syms, known_ctrls) (Path.implode base)
   359       |> File.write (Path.append doc_path (tex_path name)));
   359       |> File.write (Path.append doc_path (tex_path name)));
   360     val _ = write_tex_index tex_index doc_path;
   360     val _ = write_tex_index tex_index doc_path;
   361 
   361 
   362     val result =
   362     val result = isabelle_document {verbose = false} "pdf" documentN "" doc_path;
   363       isabelle_document {verbose = false, purge = true} "pdf" documentN "" doc_path;
       
   364 
   363 
   365     val target_dir = Path.explode "$ISABELLE_HOME_USER/tmp";
   364     val target_dir = Path.explode "$ISABELLE_HOME_USER/tmp";
   366     val target = Path.explode "$ISABELLE_HOME_USER/tmp/drafts.pdf"
   365     val target = Path.explode "$ISABELLE_HOME_USER/tmp/drafts.pdf"
   367     val _ = Isabelle_System.mkdirs target_dir;
   366     val _ = Isabelle_System.mkdirs target_dir;
   368     val _ = Isabelle_System.copy_file result target;
   367     val _ = Isabelle_System.copy_file result target;