76399
|
1 |
/* Title: Pure/Admin/build_foiltex.scala
|
|
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 |
|
|
12 |
object Build_Foiltex {
|
|
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 |
|
76518
|
55 |
File.write(component_dir.settings,
|
76399
|
56 |
"""# -*- shell-script -*- :mode=shellscript:
|
|
57 |
|
|
58 |
ISABELLE_FOILTEX_HOME="$COMPONENT"
|
|
59 |
""")
|
|
60 |
|
|
61 |
|
|
62 |
/* README */
|
|
63 |
|
76546
|
64 |
Isabelle_System.move_file(component_dir.README,
|
|
65 |
component_dir.path + Path.basic("README.flt"))
|
|
66 |
|
76518
|
67 |
File.write(component_dir.README,
|
76399
|
68 |
"""This is FoilTeX from
|
|
69 |
""" + download_url + """
|
|
70 |
|
|
71 |
|
|
72 |
Makarius
|
|
73 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
/* Isabelle tool wrapper */
|
|
80 |
|
|
81 |
val isabelle_tool =
|
|
82 |
Isabelle_Tool("build_foiltex", "build component for FoilTeX",
|
|
83 |
Scala_Project.here,
|
|
84 |
{ args =>
|
|
85 |
var target_dir = Path.current
|
|
86 |
var download_url = default_url
|
|
87 |
|
|
88 |
val getopts = Getopts("""
|
|
89 |
Usage: isabelle build_foiltex [OPTIONS]
|
|
90 |
|
|
91 |
Options are:
|
|
92 |
-D DIR target directory (default ".")
|
|
93 |
-U URL download URL (default: """" + default_url + """")
|
|
94 |
|
|
95 |
Build component for FoilTeX: slides in LaTeX.
|
|
96 |
""",
|
|
97 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
|
98 |
"U:" -> (arg => download_url = arg))
|
|
99 |
|
|
100 |
val more_args = getopts(args)
|
|
101 |
if (more_args.nonEmpty) getopts.usage()
|
|
102 |
|
|
103 |
val progress = new Console_Progress()
|
|
104 |
|
|
105 |
build_foiltex(download_url = download_url, target_dir = target_dir, progress = progress)
|
|
106 |
})
|
|
107 |
}
|