67041
|
1 |
/* Title: Pure/Tools/mkroot.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Prepare session root directory.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Mkroot
|
|
11 |
{
|
|
12 |
/** mkroot **/
|
|
13 |
|
|
14 |
def root_name(name: String): String =
|
|
15 |
Token.quote_name(Sessions.root_syntax.keywords, name)
|
|
16 |
|
|
17 |
def latex_name(name: String): String =
|
|
18 |
(for (c <- name.iterator if c != '\\')
|
|
19 |
yield if (c == '_') '-' else c).mkString
|
|
20 |
|
|
21 |
def mkroot(
|
|
22 |
session_name: String = "",
|
|
23 |
session_dir: Path = Path.current,
|
|
24 |
session_parent: String = "",
|
|
25 |
document: Boolean = false,
|
|
26 |
title: String = "",
|
|
27 |
author: String = "",
|
|
28 |
progress: Progress = No_Progress)
|
|
29 |
{
|
|
30 |
Isabelle_System.mkdirs(session_dir)
|
|
31 |
|
|
32 |
val name = proper_string(session_name) getOrElse session_dir.absolute_file.getName
|
|
33 |
val parent = proper_string(session_parent) getOrElse Isabelle_System.getenv("ISABELLE_LOGIC")
|
|
34 |
|
|
35 |
val root_path = session_dir + Path.explode("ROOT")
|
|
36 |
if (root_path.file.exists) error("Cannot overwrite existing " + root_path)
|
|
37 |
|
|
38 |
val document_path = session_dir + Path.explode("document")
|
|
39 |
if (document && document_path.file.exists) error("Cannot overwrite existing " + document_path)
|
|
40 |
|
|
41 |
progress.echo("\nPreparing session " + quote(name) + " in " + session_dir)
|
|
42 |
|
|
43 |
|
|
44 |
/* ROOT */
|
|
45 |
|
|
46 |
progress.echo(" creating " + root_path)
|
|
47 |
|
|
48 |
File.write(root_path,
|
|
49 |
"session " + root_name(name) + " = " + root_name(parent) + " +" +
|
|
50 |
(if (document) """
|
|
51 |
options [document = pdf, document_output = "output"]
|
|
52 |
theories [document = false]
|
|
53 |
(* Foo *)
|
|
54 |
(* Bar *)
|
|
55 |
theories
|
|
56 |
(* Baz *)
|
|
57 |
document_files
|
|
58 |
"root.tex"
|
|
59 |
"""
|
|
60 |
else """
|
|
61 |
options [document = false]
|
|
62 |
theories
|
|
63 |
(* Foo *)
|
|
64 |
(* Bar *)
|
|
65 |
(* Baz *)
|
|
66 |
"""))
|
|
67 |
|
|
68 |
|
|
69 |
/* document directory */
|
|
70 |
|
|
71 |
if (document) {
|
|
72 |
val root_tex = session_dir + Path.explode("document/root.tex")
|
|
73 |
progress.echo(" creating " + root_tex)
|
|
74 |
|
|
75 |
Isabelle_System.mkdirs(root_tex.dir)
|
|
76 |
|
|
77 |
File.write(root_tex,
|
|
78 |
"""\documentclass[11pt,a4paper]{article}
|
|
79 |
\""" + """usepackage{isabelle,isabellesym}
|
|
80 |
|
|
81 |
% further packages required for unusual symbols (see also
|
|
82 |
% isabellesym.sty), use only when needed
|
|
83 |
|
|
84 |
%\""" + """usepackage{amssymb}
|
|
85 |
%for \<leadsto>, \<box>, \<diamond>, \<sqsupset>, \<mho>, \<Join>,
|
|
86 |
%\<lhd>, \<lesssim>, \<greatersim>, \<lessapprox>, \<greaterapprox>,
|
|
87 |
%\<triangleq>, \<yen>, \<lozenge>
|
|
88 |
|
|
89 |
%\""" + """usepackage{eurosym}
|
|
90 |
%for \<euro>
|
|
91 |
|
|
92 |
%\""" + """usepackage[only,bigsqcap]{stmaryrd}
|
|
93 |
%for \<Sqinter>
|
|
94 |
|
|
95 |
%\""" + """usepackage{eufrak}
|
|
96 |
%for \<AA> ... \<ZZ>, \<aa> ... \<zz> (also included in amssymb)
|
|
97 |
|
|
98 |
%\""" + """usepackage{textcomp}
|
|
99 |
%for \<onequarter>, \<onehalf>, \<threequarters>, \<degree>, \<cent>,
|
|
100 |
%\<currency>
|
|
101 |
|
|
102 |
% this should be the last package used
|
|
103 |
\""" + """usepackage{pdfsetup}
|
|
104 |
|
|
105 |
% urls in roman style, theory text in math-similar italics
|
|
106 |
\""" + """urlstyle{rm}
|
|
107 |
\isabellestyle{it}
|
|
108 |
|
|
109 |
% for uniform font size
|
|
110 |
%\renewcommand{\isastyle}{\isastyleminor}
|
|
111 |
|
|
112 |
|
|
113 |
\begin{document}
|
|
114 |
|
|
115 |
\title{""" + (proper_string(title) getOrElse latex_name(name)) + """}
|
|
116 |
\author{""" +
|
|
117 |
(proper_string(author) getOrElse ("By " + latex_name(Isabelle_System.getenv("USER")))) + """}
|
|
118 |
\maketitle
|
|
119 |
|
|
120 |
\tableofcontents
|
|
121 |
|
|
122 |
% sane default for proof documents
|
|
123 |
\parindent 0pt\parskip 0.5ex
|
|
124 |
|
|
125 |
% generated text of all theories
|
|
126 |
\input{session}
|
|
127 |
|
|
128 |
% optional bibliography
|
|
129 |
%\bibliographystyle{abbrv}
|
|
130 |
%\bibliography{root}
|
|
131 |
|
|
132 |
\end{document}
|
|
133 |
|
|
134 |
%%% Local Variables:
|
|
135 |
%%% mode: latex
|
|
136 |
%%% TeX-master: t
|
|
137 |
%%% End:
|
|
138 |
""")
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
/* notes */
|
|
143 |
|
|
144 |
{
|
|
145 |
val print_dir = session_dir.implode
|
|
146 |
progress.echo("""
|
|
147 |
Now use the following command line to build the session:
|
|
148 |
|
|
149 |
isabelle build -D """ +
|
|
150 |
(if (Bash.string(print_dir) == print_dir) print_dir else quote(print_dir)) + "\n")
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
/** Isabelle tool wrapper **/
|
|
157 |
|
|
158 |
val isabelle_tool = Isabelle_Tool("mkroot", "prepare session root directory", args =>
|
|
159 |
{
|
|
160 |
var document = false
|
|
161 |
var session_name = ""
|
|
162 |
|
|
163 |
val getopts = Getopts("""
|
|
164 |
Usage: isabelle mkroot [OPTIONS] [DIR]
|
|
165 |
|
|
166 |
Options are:
|
|
167 |
-d enable document preparation
|
|
168 |
-n NAME alternative session name (default: DIR base name)
|
|
169 |
|
|
170 |
Prepare session root DIR (default: current directory).
|
|
171 |
""",
|
|
172 |
"d" -> (_ => document = true),
|
|
173 |
"n:" -> (arg => session_name = arg))
|
|
174 |
|
|
175 |
val more_args = getopts(args)
|
|
176 |
|
|
177 |
val session_dir =
|
|
178 |
more_args match {
|
|
179 |
case Nil => Path.current
|
|
180 |
case List(dir) => Path.explode(dir)
|
|
181 |
case _ => getopts.usage()
|
|
182 |
}
|
|
183 |
|
|
184 |
mkroot(session_name = session_name, session_dir = session_dir, document = document,
|
|
185 |
progress = new Console_Progress)
|
|
186 |
})
|
|
187 |
}
|