| author | nipkow | 
| Fri, 23 Aug 2024 18:40:12 +0200 | |
| changeset 80738 | 6adf6cc82013 | 
| parent 77566 | 2a99fcb283ee | 
| child 81659 | a904fcbbbdbc | 
| permissions | -rw-r--r-- | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 1 | /* Title: Pure/Admin/component_llncs.scala | 
| 76443 | 2 | Author: Makarius | 
| 3 | ||
| 4 | Build Isabelle component for Springer LaTeX LNCS style. | |
| 5 | ||
| 6 | See also: | |
| 7 | ||
| 8 | - https://ctan.org/pkg/llncs?lang=en | |
| 9 | - https://www.springer.com/gp/computer-science/lncs/conference-proceedings-guidelines | |
| 10 | */ | |
| 11 | ||
| 12 | package isabelle | |
| 13 | ||
| 14 | ||
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 15 | object Component_LLNCS {
 | 
| 76443 | 16 | /* build llncs component */ | 
| 17 | ||
| 18 | val default_url = "https://mirrors.ctan.org/macros/latex/contrib/llncs.zip" | |
| 19 | ||
| 20 | def build_llncs( | |
| 21 | download_url: String = default_url, | |
| 22 | target_dir: Path = Path.current, | |
| 23 | progress: Progress = new Progress | |
| 24 |   ): Unit = {
 | |
| 25 |     Isabelle_System.with_tmp_file("download", ext = "zip") { download_file =>
 | |
| 26 |       Isabelle_System.with_tmp_dir("download") { download_dir =>
 | |
| 27 | ||
| 28 | /* download */ | |
| 29 | ||
| 30 | Isabelle_System.download_file(download_url, download_file, progress = progress) | |
| 76530 | 31 | Isabelle_System.extract(download_file, download_dir) | 
| 76443 | 32 | |
| 76529 | 33 | val llncs_dir = File.get_dir(download_dir, title = download_url) | 
| 76443 | 34 | |
| 35 | ||
| 36 | /* component */ | |
| 37 | ||
| 76546 | 38 |         val README_md = Path.explode("README.md")
 | 
| 76443 | 39 |         val version = {
 | 
| 40 | val Version = """^_.* v(.*)_$""".r | |
| 76546 | 41 | split_lines(File.read(llncs_dir + README_md)) | 
| 76443 | 42 |             .collectFirst({ case Version(v) => v })
 | 
| 76546 | 43 |             .getOrElse(error("Failed to detect version in " + README_md))
 | 
| 76443 | 44 | } | 
| 45 | ||
| 46 | val component = "llncs-" + version | |
| 76518 | 47 | val component_dir = | 
| 76547 | 48 | Components.Directory(target_dir + Path.basic(component)).create(progress = progress) | 
| 76443 | 49 | |
| 76546 | 50 | Isabelle_System.extract(download_file, component_dir.path, strip = true) | 
| 76443 | 51 | |
| 52 | ||
| 53 | /* settings */ | |
| 54 | ||
| 76548 | 55 |         component_dir.write_settings("""
 | 
| 76443 | 56 | ISABELLE_LLNCS_HOME="$COMPONENT" | 
| 57 | """) | |
| 58 | ||
| 59 | ||
| 60 | /* README */ | |
| 61 | ||
| 76546 | 62 |         File.change(component_dir.path + README_md)(_.replace(" ", "\u00a0"))
 | 
| 63 | ||
| 76518 | 64 | File.write(component_dir.README, | 
| 76443 | 65 | """This is the Springer LaTeX LNCS style for authors from | 
| 66 | """ + download_url + """ | |
| 67 | ||
| 68 | ||
| 69 | Makarius | |
| 70 | """ + Date.Format.date(Date.now()) + "\n") | |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | ||
| 76 | /* Isabelle tool wrapper */ | |
| 77 | ||
| 78 | val isabelle_tool = | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 79 |     Isabelle_Tool("component_llncs", "build component for Springer LaTeX LNCS style",
 | 
| 76443 | 80 | Scala_Project.here, | 
| 81 |       { args =>
 | |
| 82 | var target_dir = Path.current | |
| 83 | var download_url = default_url | |
| 84 | ||
| 85 |         val getopts = Getopts("""
 | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 86 | Usage: isabelle component_llncs [OPTIONS] | 
| 76443 | 87 | |
| 88 | Options are: | |
| 89 | -D DIR target directory (default ".") | |
| 90 | -U URL download URL (default: """" + default_url + """") | |
| 91 | ||
| 92 | Build component for Springer LaTeX LNCS style. | |
| 93 | """, | |
| 94 | "D:" -> (arg => target_dir = Path.explode(arg)), | |
| 95 | "U:" -> (arg => download_url = arg)) | |
| 96 | ||
| 97 | val more_args = getopts(args) | |
| 98 | if (more_args.nonEmpty) getopts.usage() | |
| 99 | ||
| 100 | val progress = new Console_Progress() | |
| 101 | ||
| 102 | build_llncs(download_url = download_url, target_dir = target_dir, progress = progress) | |
| 103 | }) | |
| 104 | } |