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