author | wenzelm |
Sat, 22 Sep 2018 14:24:53 +0200 | |
changeset 69033 | c5db368833b1 |
parent 68704 | 71aa5a9128c2 |
child 69255 | 800b1ce96fce |
permissions | -rw-r--r-- |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Thy/present.scala |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
3 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
4 |
Theory presentation: HTML. |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
6 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
8 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
9 |
|
61372 | 10 |
import java.io.{File => JFile} |
11 |
||
51402 | 12 |
import scala.collection.immutable.SortedMap |
13 |
||
14 |
||
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
15 |
object Present |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
16 |
{ |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
17 |
/* maintain chapter index -- NOT thread-safe */ |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
18 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
19 |
private val sessions_path = Path.basic(".sessions") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
20 |
|
51402 | 21 |
private def read_sessions(dir: Path): List[(String, String)] = |
22 |
{ |
|
51416 | 23 |
val path = dir + sessions_path |
24 |
if (path.is_file) { |
|
25 |
import XML.Decode._ |
|
65344
b99283eed13c
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65089
diff
changeset
|
26 |
list(pair(string, string))(Symbol.decode_yxml(File.read(path))) |
51416 | 27 |
} |
28 |
else Nil |
|
51402 | 29 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
30 |
|
51402 | 31 |
private def write_sessions(dir: Path, sessions: List[(String, String)]) |
32 |
{ |
|
33 |
import XML.Encode._ |
|
34 |
File.write(dir + sessions_path, YXML.string_of_body(list(pair(string, string))(sessions))) |
|
35 |
} |
|
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
36 |
|
61372 | 37 |
def update_chapter_index(browser_info: Path, chapter: String, new_sessions: List[(String, String)]) |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
38 |
{ |
61372 | 39 |
val dir = browser_info + Path.basic(chapter) |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
40 |
Isabelle_System.mkdirs(dir) |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
41 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
42 |
val sessions0 = |
51406
950b897f95bb
proper path -- I/O was hidden due to permissiveness;
wenzelm
parents:
51402
diff
changeset
|
43 |
try { read_sessions(dir) } |
51987 | 44 |
catch { case _: XML.Error => Nil } |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
45 |
|
51402 | 46 |
val sessions = (SortedMap.empty[String, String] ++ sessions0 ++ new_sessions).toList |
65988 | 47 |
write_sessions(dir, sessions) |
51402 | 48 |
|
65988 | 49 |
val title = "Isabelle/" + chapter + " sessions" |
50 |
HTML.write_document(dir, "index.html", |
|
51 |
List(HTML.title(title + " (" + Distribution.version + ")")), |
|
52 |
HTML.chapter(title) :: |
|
53 |
(if (sessions.isEmpty) Nil |
|
54 |
else |
|
65992 | 55 |
List(HTML.div("sessions", |
56 |
List(HTML.description( |
|
65988 | 57 |
sessions.map({ case (name, description) => |
65989 | 58 |
(List(HTML.link(name + "/index.html", HTML.text(name))), |
59 |
if (description == "") Nil |
|
66038 | 60 |
else HTML.break ::: List(HTML.pre(HTML.text(description)))) }))))))) |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
61 |
} |
61372 | 62 |
|
63 |
def make_global_index(browser_info: Path) |
|
64 |
{ |
|
65 |
if (!(browser_info + Path.explode("index.html")).is_file) { |
|
66 |
Isabelle_System.mkdirs(browser_info) |
|
67 |
File.copy(Path.explode("~~/lib/logo/isabelle.gif"), |
|
68 |
browser_info + Path.explode("isabelle.gif")) |
|
69 |
File.write(browser_info + Path.explode("index.html"), |
|
70 |
File.read(Path.explode("~~/lib/html/library_index_header.template")) + |
|
71 |
File.read(Path.explode("~~/lib/html/library_index_content.template")) + |
|
72 |
File.read(Path.explode("~~/lib/html/library_index_footer.template"))) |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
||
77 |
/* finish session */ |
|
78 |
||
79 |
def finish( |
|
80 |
progress: Progress, |
|
81 |
browser_info: Path, |
|
82 |
graph_file: JFile, |
|
62631 | 83 |
info: Sessions.Info, |
61372 | 84 |
name: String) |
85 |
{ |
|
86 |
val session_prefix = browser_info + Path.basic(info.chapter) + Path.basic(name) |
|
65089 | 87 |
val session_fonts = session_prefix + Path.explode("fonts") |
61372 | 88 |
|
89 |
if (info.options.bool("browser_info")) { |
|
65089 | 90 |
Isabelle_System.mkdirs(session_fonts) |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
91 |
|
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
92 |
val session_graph = session_prefix + Path.basic("session_graph.pdf") |
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
93 |
File.copy(graph_file, session_graph.file) |
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
94 |
Isabelle_System.bash("chmod a+r " + File.bash_path(session_graph)) |
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
95 |
|
66000 | 96 |
HTML.write_isabelle_css(session_prefix) |
61500 | 97 |
|
65083 | 98 |
for (font <- Isabelle_System.fonts(html = true)) |
65089 | 99 |
File.copy(font, session_fonts) |
61372 | 100 |
} |
101 |
} |
|
66040 | 102 |
|
103 |
||
67253 | 104 |
/** preview **/ |
105 |
||
67260
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
106 |
sealed case class Preview(title: String, content: String) |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
107 |
|
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
108 |
def preview(snapshot: Document.Snapshot, |
67262 | 109 |
plain_text: Boolean = false, |
67260
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
110 |
fonts_url: String => String = HTML.fonts_url()): Preview = |
67253 | 111 |
{ |
112 |
require(!snapshot.is_outdated) |
|
113 |
||
67264 | 114 |
def output_document(title: String, body: XML.Body): String = |
115 |
HTML.output_document( |
|
116 |
List( |
|
117 |
HTML.style(HTML.fonts_css(fonts_url) + File.read(HTML.isabelle_css)), |
|
118 |
HTML.title(title)), |
|
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
119 |
List(HTML.source(body)), css = "", structural = false) |
67264 | 120 |
|
67253 | 121 |
val name = snapshot.node_name |
67264 | 122 |
if (plain_text) { |
123 |
val title = "File " + quote(name.path.base_name) |
|
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67264
diff
changeset
|
124 |
val content = output_document(title, HTML.text(snapshot.node.source)) |
67264 | 125 |
Preview(title, content) |
126 |
} |
|
127 |
else if (name.is_bibtex) { |
|
67256 | 128 |
val title = "Bibliography " + quote(name.path.base_name) |
67260
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
129 |
val content = |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
130 |
Isabelle_System.with_tmp_file("bib", "bib") { bib => |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
131 |
File.write(bib, snapshot.node.source) |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
132 |
Bibtex.html_output(List(bib), style = "unsort", title = title) |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
133 |
} |
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
134 |
Preview(title, content) |
67256 | 135 |
} |
67253 | 136 |
else { |
67264 | 137 |
val title = |
138 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
139 |
else "File " + quote(name.path.base_name) |
|
140 |
val content = output_document(title, pide_document(snapshot)) |
|
67260
ecd607631bc7
uniform preview for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
67256
diff
changeset
|
141 |
Preview(title, content) |
67253 | 142 |
} |
143 |
} |
|
144 |
||
145 |
||
67264 | 146 |
/* PIDE document */ |
66040 | 147 |
|
67336 | 148 |
private val document_elements = |
149 |
Rendering.foreground_elements ++ Rendering.text_color_elements ++ Rendering.markdown_elements + |
|
150 |
Markup.NUMERAL + Markup.COMMENT + Markup.LANGUAGE |
|
151 |
||
152 |
private val div_elements = |
|
153 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.enum.name, |
|
154 |
HTML.descr.name) |
|
155 |
||
156 |
private def html_div(html: XML.Body): Boolean = |
|
157 |
html exists { |
|
158 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
159 |
case XML.Text(_) => false |
|
160 |
} |
|
161 |
||
162 |
private def html_class(c: String, html: XML.Body): XML.Tree = |
|
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
163 |
if (html.forall(_ == HTML.no_text)) HTML.no_text |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
164 |
else if (html_div(html)) HTML.div(c, html) |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
165 |
else HTML.span(c, html) |
66040 | 166 |
|
66075 | 167 |
private def make_html(xml: XML.Body): XML.Body = |
66040 | 168 |
xml map { |
67336 | 169 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(Markup.Language.DOCUMENT)), body) => |
170 |
html_class(Markup.Language.DOCUMENT, make_html(body)) |
|
171 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => HTML.par(make_html(body)) |
|
172 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => HTML.item(make_html(body)) |
|
173 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), _) => HTML.no_text |
|
174 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
|
175 |
if (kind == Markup.ENUMERATE) HTML.enum(make_html(body)) else HTML.list(make_html(body)) |
|
66040 | 176 |
case XML.Elem(markup, body) => |
66044 | 177 |
val name = markup.name |
178 |
val html = |
|
179 |
markup.properties match { |
|
180 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
67336 | 181 |
List(html_class(kind, make_html(body))) |
66044 | 182 |
case _ => |
183 |
make_html(body) |
|
184 |
} |
|
66075 | 185 |
Rendering.foreground.get(name) orElse Rendering.text_color.get(name) match { |
67336 | 186 |
case Some(c) => html_class(c.toString, html) |
187 |
case None => html_class(name, html) |
|
66044 | 188 |
} |
66040 | 189 |
case XML.Text(text) => |
190 |
XML.Text(Symbol.decode(text)) |
|
191 |
} |
|
192 |
||
67253 | 193 |
def pide_document(snapshot: Document.Snapshot): XML.Body = |
67336 | 194 |
make_html(snapshot.markup_to_XML(Text.Range.full, document_elements)) |
67246
4cedf44f2af1
isabelle.preview presents auxiliary text files as well;
wenzelm
parents:
67204
diff
changeset
|
195 |
|
4cedf44f2af1
isabelle.preview presents auxiliary text files as well;
wenzelm
parents:
67204
diff
changeset
|
196 |
|
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
197 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
198 |
/** build document **/ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
199 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
200 |
val default_document_name = "document" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
201 |
val default_document_format = "pdf" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
202 |
val document_formats = List("pdf", "dvi") |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
203 |
def default_document_dir(name: String): Path = Path.explode("output") + Path.basic(name) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
204 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
205 |
def document_tags(tags: List[String]): String = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
206 |
{ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
207 |
cat_lines( |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
208 |
tags.map(tag => |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
209 |
tag.toList match { |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
210 |
case '/' :: cs => "\\isafoldtag{" + cs.mkString + "}" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
211 |
case '-' :: cs => "\\isadroptag{" + cs.mkString + "}" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
212 |
case '+' :: cs => "\\isakeeptag{" + cs.mkString + "}" |
67201 | 213 |
case cs => "\\isakeeptag{" + cs.mkString + "}" |
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
214 |
})) + "\n" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
215 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
216 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
217 |
def build_document( |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
218 |
document_name: String = default_document_name, |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
219 |
document_format: String = default_document_format, |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
220 |
document_dir: Option[Path] = None, |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
221 |
tags: List[String] = Nil) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
222 |
{ |
67177 | 223 |
val document_target = Path.parent + Path.explode(document_name).ext(document_format) |
224 |
||
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
225 |
if (!document_formats.contains(document_format)) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
226 |
error("Bad document output format: " + quote(document_format)) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
227 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
228 |
val dir = document_dir getOrElse default_document_dir(document_name) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
229 |
if (!dir.is_dir) error("Bad document output directory " + dir) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
230 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
231 |
val root_name = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
232 |
{ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
233 |
val root1 = "root_" + document_name |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
234 |
if ((dir + Path.explode(root1).ext("tex")).is_file) root1 else "root" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
235 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
236 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
237 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
238 |
/* bash scripts */ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
239 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
240 |
def root_bash(ext: String): String = Bash.string(root_name + "." + ext) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
241 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
242 |
def latex_bash(fmt: String, ext: String = "tex"): String = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
243 |
"isabelle latex -o " + Bash.string(fmt) + " " + Bash.string(root_name + "." + ext) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
244 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
245 |
def bash(script: String): Process_Result = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
246 |
Isabelle_System.bash(script, cwd = dir.file) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
247 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
248 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
249 |
/* prepare document */ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
250 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
251 |
File.write(dir + Path.explode("isabelletags.sty"), document_tags(tags)) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
252 |
|
67204 | 253 |
List("log", "blg").foreach(ext => (dir + Path.explode(root_name).ext(ext)).file.delete) |
254 |
||
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
255 |
val result = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
256 |
if ((dir + Path.explode("build")).is_file) { |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
257 |
bash("./build " + Bash.string(document_format) + " " + Bash.string(document_name)) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
258 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
259 |
else { |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
260 |
bash( |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
261 |
List( |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
262 |
latex_bash("sty"), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
263 |
latex_bash(document_format), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
264 |
"{ [ ! -f " + root_bash("bib") + " ] || " + latex_bash("bbl") + "; }", |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
265 |
"{ [ ! -f " + root_bash("idx") + " ] || " + latex_bash("idx") + "; }", |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
266 |
latex_bash(document_format), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
267 |
latex_bash(document_format)).mkString(" && ")) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
268 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
269 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
270 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
271 |
/* result */ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
272 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
273 |
if (!result.ok) { |
67203 | 274 |
cat_error( |
68132
2a5ae592eafb
more informative error, notably for missing executable;
wenzelm
parents:
67337
diff
changeset
|
275 |
Library.trim_line(result.err), |
67203 | 276 |
cat_lines(Latex.latex_errors(dir, root_name) ::: Bibtex.bibtex_errors(dir, root_name)), |
67187 | 277 |
"Failed to build document in " + File.path(dir.absolute_file)) |
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
278 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
279 |
|
68704 | 280 |
bash("if [ -f " + root_bash(document_format) + " ]; then cp -f " + |
281 |
root_bash(document_format) + " " + File.bash_path(document_target) + "; fi").check |
|
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
282 |
} |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
283 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
284 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
285 |
/* Isabelle tool wrapper */ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
286 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
287 |
val isabelle_tool = |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
288 |
Isabelle_Tool("document", "prepare theory session document", args => |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
289 |
{ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
290 |
var document_dir: Option[Path] = None |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
291 |
var document_name = default_document_name |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
292 |
var document_format = default_document_format |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
293 |
var tags: List[String] = Nil |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
294 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
295 |
val getopts = Getopts(""" |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
296 |
Usage: isabelle document [OPTIONS] |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
297 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
298 |
Options are: |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
299 |
-d DIR document output directory (default """ + |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
300 |
default_document_dir(default_document_name) + """) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
301 |
-n NAME document name (default """ + quote(default_document_name) + """) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
302 |
-o FORMAT document format: """ + |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
303 |
commas(document_formats.map(fmt => |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
304 |
fmt + (if (fmt == default_document_format) " (default)" else ""))) + """ |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
305 |
-t TAGS markup for tagged regions |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
306 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
307 |
Prepare the theory session document in document directory, producing the |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
308 |
specified output format. |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
309 |
""", |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
310 |
"d:" -> (arg => document_dir = Some(Path.explode(arg))), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
311 |
"n:" -> (arg => document_name = arg), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
312 |
"o:" -> (arg => document_format = arg), |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
313 |
"t:" -> (arg => tags = space_explode(',', arg))) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
314 |
|
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
315 |
val more_args = getopts(args) |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
316 |
if (more_args.nonEmpty) getopts.usage() |
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
317 |
|
67180 | 318 |
try { |
319 |
build_document(document_dir = document_dir, document_name = document_name, |
|
320 |
document_format = document_format, tags = tags) |
|
321 |
} |
|
69033 | 322 |
catch { case ERROR(msg) => Output.writeln(msg); sys.exit(2) } |
67176
13b5c3ff1954
re-implemented "isabelle document" in Isabelle/Scala, include latex_errors here;
wenzelm
parents:
66075
diff
changeset
|
323 |
}) |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
324 |
} |