src/Pure/Thy/present.ML
changeset 67263 449a989f42cd
parent 67197 b335e255ebcc
child 67285 e67abae0e1ca
equal deleted inserted replaced
67262:46540a2ead4b 67263:449a989f42cd
    12   val init: HTML.symbols -> bool -> bool -> Path.T -> string -> string -> (string * string) list ->
    12   val init: HTML.symbols -> bool -> bool -> Path.T -> string -> string -> (string * string) list ->
    13     (Path.T * Path.T) list -> Path.T -> string * string -> bool -> unit
    13     (Path.T * Path.T) list -> Path.T -> string * string -> bool -> unit
    14   val finish: unit -> unit
    14   val finish: unit -> unit
    15   val theory_output: Position.T -> theory -> Latex.text list -> unit
    15   val theory_output: Position.T -> theory -> Latex.text list -> unit
    16   val begin_theory: int -> (unit -> HTML.text) -> theory -> theory
    16   val begin_theory: int -> (unit -> HTML.text) -> theory -> theory
    17   val display_drafts: Path.T list -> int
       
    18 end;
    17 end;
    19 
    18 
    20 structure Present: PRESENT =
    19 structure Present: PRESENT =
    21 struct
    20 struct
    22 
    21 
   318           (add_html_index (update_time, HTML.theory_entry symbols (Url.File (html_path name), name));
   317           (add_html_index (update_time, HTML.theory_entry symbols (Url.File (html_path name), name));
   319            add_tex_index (update_time, Latex.theory_entry name))
   318            add_tex_index (update_time, Latex.theory_entry name))
   320         else ();
   319         else ();
   321     in Browser_Info.put {chapter = chapter, name = session_name} thy end);
   320     in Browser_Info.put {chapter = chapter, name = session_name} thy end);
   322 
   321 
   323 
       
   324 
       
   325 (** draft document output **)
       
   326 
       
   327 fun display_drafts src_paths = Isabelle_System.with_tmp_dir "drafts" (fn dir =>
       
   328   let
       
   329     fun prep_draft path i =
       
   330       let
       
   331         val base = Path.base path;
       
   332         val name =
       
   333           (case Path.implode (#1 (Path.split_ext base)) of
       
   334             "" => "DUMMY"
       
   335           | s => s)  ^ serial_string ();
       
   336       in
       
   337         if File.exists path then
       
   338           (((name, base, File.read path), (i, Latex.theory_entry name)), i + 1)
       
   339         else error ("Bad file: " ^ Path.print path)
       
   340       end;
       
   341     val (srcs, tex_index) = split_list (fst (fold_map prep_draft src_paths 0));
       
   342 
       
   343     val doc_path = Path.append dir document_path;
       
   344     val _ = Isabelle_System.mkdirs doc_path;
       
   345     val root_path = Path.append doc_path (Path.basic "root.tex");
       
   346     val _ = Isabelle_System.copy_file (Path.explode "~~/lib/texinputs/draft.tex") root_path;
       
   347     val _ = Isabelle_System.bash ("isabelle latex -o sty " ^ File.bash_path root_path);
       
   348     val _ = Isabelle_System.bash ("isabelle latex -o syms " ^ File.bash_path root_path);
       
   349 
       
   350     fun known name =
       
   351       let val ss = split_lines (File.read (Path.append doc_path (Path.basic name)))
       
   352       in member (op =) ss end;
       
   353     val known_syms = known "syms.lst";
       
   354     val known_ctrls = known "ctrls.lst";
       
   355 
       
   356     val _ = srcs |> List.app (fn (name, base, txt) =>
       
   357       Symbol.explode txt
       
   358       |> Latex.symbol_source (known_syms, known_ctrls) (Path.implode base)
       
   359       |> File.write (Path.append doc_path (tex_path name)));
       
   360     val _ = write_tex_index tex_index doc_path;
       
   361 
       
   362     val result = isabelle_document {verbose = false} "pdf" documentN "" doc_path;
       
   363 
       
   364     val target_dir = Path.explode "$ISABELLE_HOME_USER/tmp";
       
   365     val target = Path.explode "$ISABELLE_HOME_USER/tmp/drafts.pdf"
       
   366     val _ = Isabelle_System.mkdirs target_dir;
       
   367     val _ = Isabelle_System.copy_file result target;
       
   368   in Isabelle_System.bash ("isabelle display " ^ File.bash_path target ^ " &") end);
       
   369 
       
   370 end;
   322 end;