author | wenzelm |
Sat, 25 Nov 2023 20:41:18 +0100 | |
changeset 79064 | a54be9630ef8 |
parent 76558 | d6a2a8bc40e1 |
permissions | -rw-r--r-- |
67041 | 1 |
/* Title: Pure/Tools/mkroot.scala |
2 |
Author: Makarius |
|
3 |
||
76556 | 4 |
Create session root directory. |
67041 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75393 | 10 |
object Mkroot { |
67041 | 11 |
/** mkroot **/ |
12 |
||
13 |
def root_name(name: String): String = |
|
14 |
Token.quote_name(Sessions.root_syntax.keywords, name) |
|
15 |
||
16 |
def latex_name(name: String): String = |
|
17 |
(for (c <- name.iterator if c != '\\') |
|
18 |
yield if (c == '_') '-' else c).mkString |
|
19 |
||
20 |
def mkroot( |
|
21 |
session_name: String = "", |
|
22 |
session_dir: Path = Path.current, |
|
23 |
session_parent: String = "", |
|
67069
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
24 |
init_repos: Boolean = false, |
67041 | 25 |
title: String = "", |
26 |
author: String = "", |
|
76556 | 27 |
quiet: Boolean = false, |
75393 | 28 |
progress: Progress = new Progress |
29 |
): Unit = { |
|
72375 | 30 |
Isabelle_System.make_directory(session_dir) |
67041 | 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 |
||
72832 | 35 |
val root_path = session_dir + Sessions.ROOT |
67041 | 36 |
if (root_path.file.exists) error("Cannot overwrite existing " + root_path) |
37 |
||
38 |
val document_path = session_dir + Path.explode("document") |
|
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
39 |
if (document_path.file.exists) error("Cannot overwrite existing " + document_path) |
67041 | 40 |
|
67069
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
41 |
val root_tex = session_dir + Path.explode("document/root.tex") |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
42 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
43 |
|
76557 | 44 |
progress.echo( |
45 |
(if (quiet) "" else "\n") + |
|
76558 | 46 |
"Initializing session " + quote(name) + " in " + session_dir.absolute) |
67041 | 47 |
|
48 |
||
49 |
/* ROOT */ |
|
50 |
||
76556 | 51 |
progress.echo_if(!quiet, " creating " + root_path) |
67041 | 52 |
|
53 |
File.write(root_path, |
|
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
54 |
"session " + root_name(name) + " = " + root_name(parent) + """ + |
67041 | 55 |
options [document = pdf, document_output = "output"] |
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
56 |
(*theories [document = false] |
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
57 |
A |
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
58 |
B |
67041 | 59 |
theories |
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
60 |
C |
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
61 |
D*) |
67041 | 62 |
document_files |
63 |
"root.tex" |
|
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
64 |
""") |
67041 | 65 |
|
66 |
||
67 |
/* document directory */ |
|
68 |
||
67042
677cab7c2b85
adapted to changed ROOT syntax (see 13857f49d215);
wenzelm
parents:
67041
diff
changeset
|
69 |
{ |
76556 | 70 |
progress.echo_if(!quiet, " creating " + root_tex) |
67041 | 71 |
|
72375 | 72 |
Isabelle_System.make_directory(root_tex.dir) |
67041 | 73 |
|
74 |
File.write(root_tex, |
|
75 |
"""\documentclass[11pt,a4paper]{article} |
|
73404 | 76 |
\""" + """usepackage[T1]{fontenc} |
67041 | 77 |
\""" + """usepackage{isabelle,isabellesym} |
78 |
||
79 |
% further packages required for unusual symbols (see also |
|
80 |
% isabellesym.sty), use only when needed |
|
81 |
||
82 |
%\""" + """usepackage{amssymb} |
|
83 |
%for \<leadsto>, \<box>, \<diamond>, \<sqsupset>, \<mho>, \<Join>, |
|
84 |
%\<lhd>, \<lesssim>, \<greatersim>, \<lessapprox>, \<greaterapprox>, |
|
85 |
%\<triangleq>, \<yen>, \<lozenge> |
|
86 |
||
87 |
%\""" + """usepackage{eurosym} |
|
88 |
%for \<euro> |
|
89 |
||
74434 | 90 |
%\""" + """usepackage[only,bigsqcap,bigparallel,fatsemi,interleave,sslash]{stmaryrd} |
91 |
%for \<Sqinter>, \<Parallel>, \<Zsemi>, \<Parallel>, \<sslash> |
|
67041 | 92 |
|
93 |
%\""" + """usepackage{eufrak} |
|
94 |
%for \<AA> ... \<ZZ>, \<aa> ... \<zz> (also included in amssymb) |
|
95 |
||
96 |
%\""" + """usepackage{textcomp} |
|
97 |
%for \<onequarter>, \<onehalf>, \<threequarters>, \<degree>, \<cent>, |
|
98 |
%\<currency> |
|
99 |
||
100 |
% this should be the last package used |
|
101 |
\""" + """usepackage{pdfsetup} |
|
102 |
||
103 |
% urls in roman style, theory text in math-similar italics |
|
104 |
\""" + """urlstyle{rm} |
|
105 |
\isabellestyle{it} |
|
106 |
||
107 |
% for uniform font size |
|
108 |
%\renewcommand{\isastyle}{\isastyleminor} |
|
109 |
||
110 |
||
111 |
\begin{document} |
|
112 |
||
113 |
\title{""" + (proper_string(title) getOrElse latex_name(name)) + """} |
|
67043 | 114 |
\author{""" + (proper_string(author) getOrElse latex_name(System.getProperty("user.name"))) + """} |
67041 | 115 |
\maketitle |
116 |
||
117 |
\tableofcontents |
|
118 |
||
119 |
% sane default for proof documents |
|
120 |
\parindent 0pt\parskip 0.5ex |
|
121 |
||
122 |
% generated text of all theories |
|
123 |
\input{session} |
|
124 |
||
125 |
% optional bibliography |
|
126 |
%\bibliographystyle{abbrv} |
|
127 |
%\bibliography{root} |
|
128 |
||
129 |
\end{document} |
|
130 |
||
131 |
%%% Local Variables: |
|
132 |
%%% mode: latex |
|
133 |
%%% TeX-master: t |
|
134 |
%%% End: |
|
135 |
""") |
|
136 |
} |
|
137 |
||
138 |
||
67069
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
139 |
/* Mercurial repository */ |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
140 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
141 |
if (init_repos) { |
76558 | 142 |
progress.echo( |
143 |
(if (quiet) "" else "\n") + |
|
144 |
"Initializing Mercurial repository " + session_dir.absolute) |
|
67069
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
145 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
146 |
val hg = Mercurial.init_repository(session_dir) |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
147 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
148 |
val hg_ignore = session_dir + Path.explode(".hgignore") |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
149 |
File.write(hg_ignore, |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
150 |
"""syntax: glob |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
151 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
152 |
*~ |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
153 |
*.marks |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
154 |
*.orig |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
155 |
*.rej |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
156 |
.DS_Store |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
157 |
.swp |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
158 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
159 |
syntax: regexp |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
160 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
161 |
^output/ |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
162 |
""") |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
163 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
164 |
hg.add(List(root_path, root_tex, hg_ignore)) |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
165 |
} |
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
166 |
|
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
167 |
|
67041 | 168 |
/* notes */ |
169 |
||
170 |
{ |
|
171 |
val print_dir = session_dir.implode |
|
76556 | 172 |
progress.echo_if(!quiet, """ |
67041 | 173 |
Now use the following command line to build the session: |
174 |
||
175 |
isabelle build -D """ + |
|
176 |
(if (Bash.string(print_dir) == print_dir) print_dir else quote(print_dir)) + "\n") |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
||
181 |
||
182 |
/** Isabelle tool wrapper **/ |
|
183 |
||
76556 | 184 |
val isabelle_tool = Isabelle_Tool("mkroot", "create session root directory", |
75393 | 185 |
Scala_Project.here, |
75394 | 186 |
{ args => |
187 |
var author = "" |
|
188 |
var init_repos = false |
|
189 |
var title = "" |
|
190 |
var session_name = "" |
|
76556 | 191 |
var quiet = false |
67041 | 192 |
|
75394 | 193 |
val getopts = Getopts(""" |
67043 | 194 |
Usage: isabelle mkroot [OPTIONS] [DIRECTORY] |
67041 | 195 |
|
196 |
Options are: |
|
67043 | 197 |
-A LATEX provide author in LaTeX notation (default: user name) |
67069
f11486d31586
init Mercurial repository for the generated session files;
wenzelm
parents:
67043
diff
changeset
|
198 |
-I init Mercurial repository and add generated files |
67043 | 199 |
-T LATEX provide title in LaTeX notation (default: session name) |
200 |
-n NAME alternative session name (default: directory base name) |
|
76556 | 201 |
-q quiet mode: less verbosity |
67041 | 202 |
|
76556 | 203 |
Create session root directory (default: current directory). |
67041 | 204 |
""", |
75394 | 205 |
"A:" -> (arg => author = arg), |
76556 | 206 |
"I" -> (_ => init_repos = true), |
75394 | 207 |
"T:" -> (arg => title = arg), |
76556 | 208 |
"n:" -> (arg => session_name = arg), |
209 |
"q" -> (_ => quiet = true)) |
|
67041 | 210 |
|
75394 | 211 |
val more_args = getopts(args) |
67041 | 212 |
|
75394 | 213 |
val session_dir = |
214 |
more_args match { |
|
215 |
case Nil => Path.current |
|
216 |
case List(dir) => Path.explode(dir) |
|
217 |
case _ => getopts.usage() |
|
218 |
} |
|
67041 | 219 |
|
76556 | 220 |
val progress = new Console_Progress |
221 |
||
75394 | 222 |
mkroot(session_name = session_name, session_dir = session_dir, init_repos = init_repos, |
76556 | 223 |
author = author, title = title, quiet = quiet, progress = progress) |
75394 | 224 |
}) |
67041 | 225 |
} |