194 |
194 |
195 |
195 |
196 |
196 |
197 /** build document **/ |
197 /** build document **/ |
198 |
198 |
|
199 val document_format = "pdf" |
|
200 |
199 val default_document_name = "document" |
201 val default_document_name = "document" |
200 val default_document_format = "pdf" |
|
201 val document_formats = List("pdf", "dvi") |
|
202 def default_document_dir(name: String): Path = Path.explode("output") + Path.basic(name) |
202 def default_document_dir(name: String): Path = Path.explode("output") + Path.basic(name) |
203 |
203 |
204 def document_tags(tags: List[String]): String = |
204 def document_tags(tags: List[String]): String = |
205 { |
205 { |
206 cat_lines( |
206 cat_lines( |
213 })) + "\n" |
213 })) + "\n" |
214 } |
214 } |
215 |
215 |
216 def build_document( |
216 def build_document( |
217 document_name: String = default_document_name, |
217 document_name: String = default_document_name, |
218 document_format: String = default_document_format, |
|
219 document_dir: Option[Path] = None, |
218 document_dir: Option[Path] = None, |
220 tags: List[String] = Nil) |
219 tags: List[String] = Nil) |
221 { |
220 { |
222 val document_target = Path.parent + Path.explode(document_name).ext(document_format) |
221 val document_target = Path.parent + Path.explode(document_name).ext(document_format) |
223 |
|
224 if (!document_formats.contains(document_format)) |
|
225 error("Bad document output format: " + quote(document_format)) |
|
226 |
222 |
227 val dir = document_dir getOrElse default_document_dir(document_name) |
223 val dir = document_dir getOrElse default_document_dir(document_name) |
228 if (!dir.is_dir) error("Bad document output directory " + dir) |
224 if (!dir.is_dir) error("Bad document output directory " + dir) |
229 |
225 |
230 val root_name = |
226 val root_name = |
286 val isabelle_tool = |
282 val isabelle_tool = |
287 Isabelle_Tool("document", "prepare theory session document", args => |
283 Isabelle_Tool("document", "prepare theory session document", args => |
288 { |
284 { |
289 var document_dir: Option[Path] = None |
285 var document_dir: Option[Path] = None |
290 var document_name = default_document_name |
286 var document_name = default_document_name |
291 var document_format = default_document_format |
|
292 var tags: List[String] = Nil |
287 var tags: List[String] = Nil |
293 |
288 |
294 val getopts = Getopts(""" |
289 val getopts = Getopts(""" |
295 Usage: isabelle document [OPTIONS] |
290 Usage: isabelle document [OPTIONS] |
296 |
291 |
297 Options are: |
292 Options are: |
298 -d DIR document output directory (default """ + |
293 -d DIR document output directory (default """ + |
299 default_document_dir(default_document_name) + """) |
294 default_document_dir(default_document_name) + """) |
300 -n NAME document name (default """ + quote(default_document_name) + """) |
295 -n NAME document name (default """ + quote(default_document_name) + """) |
301 -o FORMAT document format: """ + |
|
302 commas(document_formats.map(fmt => |
|
303 fmt + (if (fmt == default_document_format) " (default)" else ""))) + """ |
|
304 -t TAGS markup for tagged regions |
296 -t TAGS markup for tagged regions |
305 |
297 |
306 Prepare the theory session document in document directory, producing the |
298 Prepare the theory session document in document directory, producing the |
307 specified output format. |
299 specified output format. |
308 """, |
300 """, |
309 "d:" -> (arg => document_dir = Some(Path.explode(arg))), |
301 "d:" -> (arg => document_dir = Some(Path.explode(arg))), |
310 "n:" -> (arg => document_name = arg), |
302 "n:" -> (arg => document_name = arg), |
311 "o:" -> (arg => document_format = arg), |
|
312 "t:" -> (arg => tags = space_explode(',', arg))) |
303 "t:" -> (arg => tags = space_explode(',', arg))) |
313 |
304 |
314 val more_args = getopts(args) |
305 val more_args = getopts(args) |
315 if (more_args.nonEmpty) getopts.usage() |
306 if (more_args.nonEmpty) getopts.usage() |
316 |
307 |
317 try { |
308 try { |
318 build_document(document_dir = document_dir, document_name = document_name, |
309 build_document(document_dir = document_dir, document_name = document_name, tags = tags) |
319 document_format = document_format, tags = tags) |
|
320 } |
310 } |
321 catch { case ERROR(msg) => Output.writeln(msg); sys.exit(2) } |
311 catch { case ERROR(msg) => Output.writeln(msg); sys.exit(2) } |
322 }) |
312 }) |
323 } |
313 } |