author | wenzelm |
Tue, 09 Jan 2024 23:41:50 +0100 | |
changeset 79458 | ca2fe94e8048 |
parent 77566 | 2a99fcb283ee |
child 80224 | db92e0b6a11a |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
1 |
/* Title: Pure/Admin/component_foiltex.scala |
76399 | 2 |
Author: Makarius |
3 |
||
4 |
Build Isabelle component for FoilTeX. |
|
5 |
||
6 |
See also https://ctan.org/pkg/foiltex |
|
7 |
*/ |
|
8 |
||
9 |
package isabelle |
|
10 |
||
11 |
||
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
12 |
object Component_Foiltex { |
76399 | 13 |
/* build FoilTeX component */ |
14 |
||
15 |
val default_url = "https://mirrors.ctan.org/macros/latex/contrib/foiltex.zip" |
|
16 |
||
17 |
def build_foiltex( |
|
18 |
download_url: String = default_url, |
|
19 |
target_dir: Path = Path.current, |
|
20 |
progress: Progress = new Progress |
|
21 |
): Unit = { |
|
22 |
Isabelle_System.with_tmp_file("download", ext = "zip") { download_file => |
|
23 |
Isabelle_System.with_tmp_dir("download") { download_dir => |
|
24 |
||
25 |
/* download */ |
|
26 |
||
27 |
Isabelle_System.download_file(download_url, download_file, progress = progress) |
|
76530 | 28 |
Isabelle_System.extract(download_file, download_dir) |
76399 | 29 |
|
76529 | 30 |
val foiltex_dir = File.get_dir(download_dir, title = download_url) |
76399 | 31 |
|
32 |
||
33 |
/* component */ |
|
34 |
||
76546 | 35 |
val README = Path.explode("README") |
76399 | 36 |
val version = { |
37 |
val Version = """^.*Instructions for FoilTeX Version\s*(.*)$""".r |
|
76546 | 38 |
split_lines(File.read(foiltex_dir + README)) |
76399 | 39 |
.collectFirst({ case Version(v) => v }) |
76546 | 40 |
.getOrElse(error("Failed to detect version in " + README)) |
76399 | 41 |
} |
42 |
||
43 |
val component = "foiltex-" + version |
|
76518 | 44 |
val component_dir = |
76547 | 45 |
Components.Directory(target_dir + Path.basic(component)).create(progress = progress) |
76399 | 46 |
|
76546 | 47 |
Isabelle_System.extract(download_file, component_dir.path, strip = true) |
48 |
||
49 |
Isabelle_System.bash("pdflatex foiltex.ins", cwd = component_dir.path.file).check |
|
50 |
(component_dir.path + Path.basic("foiltex.log")).file.delete() |
|
76399 | 51 |
|
52 |
||
53 |
/* settings */ |
|
54 |
||
76548 | 55 |
component_dir.write_settings(""" |
76399 | 56 |
ISABELLE_FOILTEX_HOME="$COMPONENT" |
57 |
""") |
|
58 |
||
59 |
||
60 |
/* README */ |
|
61 |
||
76546 | 62 |
Isabelle_System.move_file(component_dir.README, |
63 |
component_dir.path + Path.basic("README.flt")) |
|
64 |
||
76518 | 65 |
File.write(component_dir.README, |
76399 | 66 |
"""This is FoilTeX from |
67 |
""" + download_url + """ |
|
68 |
||
69 |
||
70 |
Makarius |
|
71 |
""" + Date.Format.date(Date.now()) + "\n") |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
||
77 |
/* Isabelle tool wrapper */ |
|
78 |
||
79 |
val isabelle_tool = |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
80 |
Isabelle_Tool("component_foiltex", "build component for FoilTeX", |
76399 | 81 |
Scala_Project.here, |
82 |
{ args => |
|
83 |
var target_dir = Path.current |
|
84 |
var download_url = default_url |
|
85 |
||
86 |
val getopts = Getopts(""" |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
87 |
Usage: isabelle component_foiltex [OPTIONS] |
76399 | 88 |
|
89 |
Options are: |
|
90 |
-D DIR target directory (default ".") |
|
91 |
-U URL download URL (default: """" + default_url + """") |
|
92 |
||
93 |
Build component for FoilTeX: slides in LaTeX. |
|
94 |
""", |
|
95 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
96 |
"U:" -> (arg => download_url = arg)) |
|
97 |
||
98 |
val more_args = getopts(args) |
|
99 |
if (more_args.nonEmpty) getopts.usage() |
|
100 |
||
101 |
val progress = new Console_Progress() |
|
102 |
||
103 |
build_foiltex(download_url = download_url, target_dir = target_dir, progress = progress) |
|
104 |
}) |
|
105 |
} |